From 1bb1eb7b8790d52fea2296b06c1d46730946fc53 Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Tue, 11 Sep 2012 23:11:34 +0200 Subject: half of task compile. --- src/object/task/taskbuild.cpp | 210 +++++++++++++++++++++--------------------- 1 file changed, 103 insertions(+), 107 deletions(-) (limited to 'src/object/task/taskbuild.cpp') diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index ecbf898..6aa0ed2 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -16,15 +16,14 @@ // taskbuild.cpp - -#include - #include "object/task/taskbuild.h" #include "common/iman.h" -#include "old/light.h" -#include "old/terrain.h" -#include "old/water.h" +#include "graphics/core/color.h" +#include "graphics/core/light.h" +#include "graphics/engine/lightman.h" +#include "graphics/engine/terrain.h" +#include "graphics/engine/water.h" #include "math/geometry.h" #include "object/auto/auto.h" #include "object/motion/motionhuman.h" @@ -32,9 +31,6 @@ #include "physics/physics.h" #include "ui/displaytext.h" - - - // Object's constructor. CTaskBuild::CTaskBuild(CInstanceManager* iMan, CObject* object) @@ -68,7 +64,7 @@ CTaskBuild::~CTaskBuild() for ( i=0 ; iDeleteLight(m_lightRank[i]); + m_lightMan->DeleteLight(m_lightRank[i]); } } @@ -102,7 +98,7 @@ bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) if ( m_type == OBJECT_INFO ) m_buildingHeight = 19.0f; m_buildingHeight *= 0.25f; - m_buildingPos = m_building->RetPosition(0); + m_buildingPos = m_building->GetPosition(0); m_buildingPos.y -= m_buildingHeight; m_building->SetPosition(0, m_buildingPos); return true; @@ -112,21 +108,21 @@ bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) void CTaskBuild::CreateLight() { - D3DLIGHT7 light; - D3DCOLORVALUE color; - Math::Vector center, pos, dir; - Math::Point c, p; - float angle; - int i; + Gfx::Light light; + Gfx::Color color; + Math::Vector center, pos, dir; + Math::Point c, p; + float angle; + int i; - if ( !m_engine->RetLightMode() ) return; + if ( !m_engine->GetLightMode() ) return; - center = m_metal->RetPosition(0); + center = m_metal->GetPosition(0); angle = 0; for ( i=0 ; iCreateLight(); + m_lightRank[i] = m_lightMan->CreateLight(); if ( m_lightRank[i] == -1 ) continue; c.x = center.x; @@ -139,32 +135,32 @@ void CTaskBuild::CreateLight() pos.y = center.y+40.0f; dir = center-pos; - ZeroMemory( &light, sizeof(light) ); - light.dltType = D3DLIGHT_SPOT; - light.dcvDiffuse.r = 0.0f; - light.dcvDiffuse.g = 0.0f; - light.dcvDiffuse.b = 0.0f; // white (invisible) - light.dvPosition.x = pos.x; - light.dvPosition.y = pos.y; - light.dvPosition.z = pos.z; - light.dvDirection.x = dir.x; - light.dvDirection.y = dir.y; - light.dvDirection.z = dir.z; - light.dvRange = D3DLIGHT_RANGE_MAX; - light.dvFalloff = 1.0f; - light.dvAttenuation0 = 1.0f; - light.dvAttenuation1 = 0.0f; - light.dvAttenuation2 = 0.0f; - light.dvTheta = 0.0f; - light.dvPhi = Math::PI/4.0f; - m_light->SetLight(m_lightRank[i], light); + memset(&light, 0, sizeof(light)); + light.type = Gfx::LIGHT_SPOT; + light.diffuse.r = 0.0f; + light.diffuse.g = 0.0f; + light.diffuse.b = 0.0f; // white (invisible) + light.position.x = pos.x; + light.position.y = pos.y; + light.position.z = pos.z; + light.direction.x = dir.x; + light.direction.y = dir.y; + light.direction.z = dir.z; + //TODO Is this value correct + light.spotIntensity = 128; + light.attenuation0 = 1.0f; + light.attenuation1 = 0.0f; + light.attenuation2 = 0.0f; + //TODO Is this value correct + light.spotAngle = 90; + m_lightMan->SetLight(m_lightRank[i], light); color.r = -1.0f; color.g = -1.0f; color.b = -0.5f; // violet color.a = 0.0f; - m_light->SetLightColor(m_lightRank[i], color); - m_light->SetLightColorSpeed(m_lightRank[i], 1.0f/((1.0f/m_speed)*0.25f)); + m_lightMan->SetLightColor(m_lightRank[i], color); + m_lightMan->SetLightColorSpeed(m_lightRank[i], 1.0f/((1.0f/m_speed)*0.25f)); angle += (Math::PI*2.0f)/TBMAXLIGHT; } @@ -176,8 +172,8 @@ void CTaskBuild::CreateLight() void CTaskBuild::BlackLight() { - D3DCOLORVALUE color; - int i; + Gfx::Color color; + int i; for ( i=0 ; iSetLightColor(m_lightRank[i], color); - m_light->SetLightColorSpeed(m_lightRank[i], 1.0f/((1.0f/m_speed)*0.75f)); + m_lightMan->SetLightColor(m_lightRank[i], color); + m_lightMan->SetLightColorSpeed(m_lightRank[i], 1.0f/((1.0f/m_speed)*0.75f)); } m_bBlack = true; @@ -203,8 +199,8 @@ bool CTaskBuild::EventProcess(const Event &event) Math::Point dim; float a, g, cirSpeed, dist, linSpeed; - if ( m_engine->RetPause() ) return true; - if ( event.event != EVENT_FRAME ) return true; + if ( m_engine->GetPause() ) return true; + if ( event.type != EVENT_FRAME ) return true; if ( m_bError ) return false; m_time += event.rTime; @@ -213,7 +209,7 @@ bool CTaskBuild::EventProcess(const Event &event) if ( m_phase == TBP_TURN ) // preliminary rotation? { - a = m_object->RetAngleY(0); + a = m_object->GetAngleY(0); g = m_angleY; cirSpeed = Math::Direction(a, g)*1.0f; if ( cirSpeed > 1.0f ) cirSpeed = 1.0f; @@ -225,7 +221,7 @@ bool CTaskBuild::EventProcess(const Event &event) if ( m_phase == TBP_MOVE ) // preliminary forward/backward? { - dist = Math::Distance(m_object->RetPosition(0), m_metal->RetPosition(0)); + dist = Math::Distance(m_object->GetPosition(0), m_metal->GetPosition(0)); linSpeed = 0.0f; if ( dist > 30.0f ) linSpeed = 1.0f; if ( dist < 30.0f ) linSpeed = -1.0f; @@ -258,8 +254,8 @@ bool CTaskBuild::EventProcess(const Event &event) { m_bBuild = true; - pos = m_metal->RetPosition(0); - a = m_object->RetAngleY(0); + pos = m_metal->GetPosition(0); + a = m_object->GetAngleY(0); if ( !CreateBuilding(pos, a+Math::PI) ) { m_metal->SetLock(false); // usable again @@ -270,7 +266,7 @@ bool CTaskBuild::EventProcess(const Event &event) m_camera->FlushEffect(); Abort(); m_bError = true; - m_displayText->DisplayError(ERR_TOOMANY, m_object->RetPosition(0)); + m_displayText->DisplayError(ERR_TOOMANY, m_object->GetPosition(0)); return false; } CreateLight(); @@ -295,32 +291,32 @@ bool CTaskBuild::EventProcess(const Event &event) BlackLight(); } - if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time ) + if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { - m_lastParticule = m_time; + m_lastParticle = m_time; - pos = m_metal->RetPosition(0); + pos = m_metal->GetPosition(0); speed.x = (Math::Rand()-0.5f)*20.0f; speed.z = (Math::Rand()-0.5f)*20.0f; speed.y = Math::Rand()*10.0f; dim.x = Math::Rand()*6.0f+4.0f; dim.y = dim.x; - m_particule->CreateParticule(pos, speed, dim, PARTIFIRE); + m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIRE); pos = Math::Vector(0.0f, 0.5f, 0.0f); - mat = m_object->RetWorldMatrix(14); + mat = m_object->GetWorldMatrix(14); pos = Transform(*mat, pos); - speed = m_metal->RetPosition(0); + speed = m_metal->GetPosition(0); speed.x += (Math::Rand()-0.5f)*5.0f; speed.z += (Math::Rand()-0.5f)*5.0f; speed -= pos; dim.x = 2.0f; dim.y = dim.x; - m_particule->CreateParticule(pos, speed, dim, PARTIFIREZ); + m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIREZ); if ( Math::Rand() < 0.3f ) { - m_sound->Play(SOUND_BUILD, m_object->RetPosition(0), 0.5f, 1.0f*Math::Rand()*1.5f); + m_sound->Play(SOUND_BUILD, m_object->GetPosition(0), 0.5f, 1.0f*Math::Rand()*1.5f); } } @@ -337,25 +333,25 @@ Error CTaskBuild::Start(ObjectType type) float iAngle, oAngle; m_type = type; - m_lastParticule = 0.0f; + m_lastParticle = 0.0f; m_progress = 0.0f; - iAngle = m_object->RetAngleY(0); + iAngle = m_object->GetAngleY(0); iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI oAngle = iAngle; m_bError = true; // operation impossible - pos = m_object->RetPosition(0); - if ( pos.y < m_water->RetLevel() ) return ERR_BUILD_WATER; + pos = m_object->GetPosition(0); + if ( pos.y < m_water->GetLevel() ) return ERR_BUILD_WATER; - if ( !m_physics->RetLand() ) return ERR_BUILD_FLY; + if ( !m_physics->GetLand() ) return ERR_BUILD_FLY; - speed = m_physics->RetMotorSpeed(); + speed = m_physics->GetMotorSpeed(); if ( speed.x != 0.0f || speed.z != 0.0f ) return ERR_BUILD_MOTOR; - if ( m_object->RetFret() != 0 ) return ERR_MANIP_BUSY; + if ( m_object->GetFret() != 0 ) return ERR_MANIP_BUSY; m_metal = SearchMetalObject(oAngle, 2.0f, 100.0f, Math::PI*0.25f, err); if ( err == ERR_BUILD_METALNEAR && m_metal != 0 ) @@ -375,9 +371,9 @@ Error CTaskBuild::Start(ObjectType type) m_phase = TBP_TURN; // rotation necessary preliminary m_angleY = oAngle; // angle was reached - pv = m_object->RetPosition(0); + pv = m_object->GetPosition(0); pv.y += 8.3f; - pm = m_metal->RetPosition(0); + pm = m_metal->GetPosition(0); m_angleZ = Math::RotateAngle(Math::DistanceProjected(pv, pm), fabs(pv.y-pm.y)); m_physics->SetFreeze(true); // it does not move @@ -394,27 +390,27 @@ Error CTaskBuild::IsEnded() CAuto* automat; float angle, dist, time; - if ( m_engine->RetPause() ) return ERR_CONTINUE; + if ( m_engine->GetPause() ) return ERR_CONTINUE; if ( m_bError ) return ERR_STOP; if ( m_phase == TBP_TURN ) // preliminary rotation? { - angle = m_object->RetAngleY(0); + angle = m_object->GetAngleY(0); angle = Math::NormAngle(angle); // 0..2*Math::PI if ( Math::TestAngle(angle, m_angleY-Math::PI*0.01f, m_angleY+Math::PI*0.01f) ) { m_physics->SetMotorSpeedZ(0.0f); - dist = Math::Distance(m_object->RetPosition(0), m_metal->RetPosition(0)); + dist = Math::Distance(m_object->GetPosition(0), m_metal->GetPosition(0)); if ( dist > 30.0f ) { - time = m_physics->RetLinTimeLength(dist-30.0f, 1.0f); + time = m_physics->GetLinTimeLength(dist-30.0f, 1.0f); m_speed = 1.0f/time; } else { - time = m_physics->RetLinTimeLength(30.0f-dist, -1.0f); + time = m_physics->GetLinTimeLength(30.0f-dist, -1.0f); m_speed = 1.0f/time; } m_phase = TBP_MOVE; @@ -425,7 +421,7 @@ Error CTaskBuild::IsEnded() if ( m_phase == TBP_MOVE ) // preliminary forward/backward? { - dist = Math::Distance(m_object->RetPosition(0), m_metal->RetPosition(0)); + dist = Math::Distance(m_object->GetPosition(0), m_metal->GetPosition(0)); if ( dist >= 25.0f && dist <= 35.0f ) { @@ -466,12 +462,12 @@ Error CTaskBuild::IsEnded() { if ( m_progress < 1.0f ) return ERR_CONTINUE; - m_soundChannel = m_sound->Play(SOUND_TREMBLE, m_object->RetPosition(0), 0.0f, 1.0f, true); + m_soundChannel = m_sound->Play(SOUND_TREMBLE, m_object->GetPosition(0), 0.0f, 1.0f, true); m_sound->AddEnvelope(m_soundChannel, 0.7f, 1.0f, 1.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 0.7f, 1.5f, 7.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.5f, 2.0f, SOPER_STOP); - m_camera->StartEffect(CE_VIBRATION, m_metal->RetPosition(0), 1.0f); + m_camera->StartEffect(Gfx::CAM_EFFECT_VIBRATION, m_metal->GetPosition(0), 1.0f); m_phase = TBP_BUILD; m_speed = 1.0f/10.f; // duration of 10s @@ -482,7 +478,7 @@ Error CTaskBuild::IsEnded() { if ( m_progress < 1.0f ) return ERR_CONTINUE; - DeleteMark(m_metal->RetPosition(0), 20.0f); + DeleteMark(m_metal->GetPosition(0), 20.0f); m_metal->DeleteObject(); // removes the metal delete m_metal; @@ -494,7 +490,7 @@ Error CTaskBuild::IsEnded() m_main->CreateShortcuts(); m_displayText->DisplayError(INFO_BUILD, m_buildingPos, 10.0f, 50.0f); - automat = m_building->RetAuto(); + automat = m_building->GetAuto(); if ( automat != 0 ) { automat->Init(); @@ -583,16 +579,16 @@ Error CTaskBuild::FlatFloor() if ( m_type == OBJECT_INFO ) radius = 5.0f; if ( radius == 0.0f ) return ERR_GENERIC; - center = m_metal->RetPosition(0); - angle = m_terrain->RetFineSlope(center); - bLittleFlat = ( angle < FLATLIMIT ); + center = m_metal->GetPosition(0); + angle = m_terrain->GetFineSlope(center); + bLittleFlat = ( angle < Gfx::TERRAIN_FLATLIMIT); - max = m_terrain->RetFlatZoneRadius(center, radius); + max = m_terrain->GetFlatZoneRadius(center, radius); if ( max < radius ) // area too small? { if ( bLittleFlat ) { - m_main->SetShowLimit(1, PARTILIMIT3, m_metal, center, max, 10.0f); + m_main->SetShowLimit(1, Gfx::PARTILIMIT3, m_metal, center, max, 10.0f); } return bLittleFlat?ERR_BUILD_FLATLIT:ERR_BUILD_FLAT; } @@ -601,18 +597,18 @@ Error CTaskBuild::FlatFloor() bBase = false; for ( i=0 ; i<1000000 ; i++ ) { - pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i); + pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; - if ( !pObj->RetActif() ) continue; // inactive? - if ( pObj->RetTruck() != 0 ) continue; // object transported? + if ( !pObj->GetActif() ) continue; // inactive? + if ( pObj->GetTruck() != 0 ) continue; // object transported? if ( pObj == m_metal ) continue; if ( pObj == m_object ) continue; - type = pObj->RetType(); + type = pObj->GetType(); if ( type == OBJECT_BASE ) { - oPos = pObj->RetPosition(0); + oPos = pObj->GetPosition(0); dist = Math::Distance(center, oPos)-80.0f; if ( dist < max ) { @@ -640,24 +636,24 @@ Error CTaskBuild::FlatFloor() } if ( max < radius ) { - m_main->SetShowLimit(1, PARTILIMIT2, m_metal, center, max, 10.0f); + m_main->SetShowLimit(1, Gfx::PARTILIMIT2, m_metal, center, max, 10.0f); if ( bRadius < 2.0f ) bRadius = 2.0f; - m_main->SetShowLimit(2, PARTILIMIT3, m_metal, bPos, bRadius, 10.0f); + m_main->SetShowLimit(2, Gfx::PARTILIMIT3, m_metal, bPos, bRadius, 10.0f); return bBase?ERR_BUILD_BASE:ERR_BUILD_BUSY; } max = 100000.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i); + pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; - if ( !pObj->RetActif() ) continue; // inactive? - if ( pObj->RetTruck() != 0 ) continue; // object transported? + if ( !pObj->GetActif() ) continue; // inactive? + if ( pObj->GetTruck() != 0 ) continue; // object transported? if ( pObj == m_metal ) continue; if ( pObj == m_object ) continue; - type = pObj->RetType(); + type = pObj->GetType(); if ( type == OBJECT_DERRICK || type == OBJECT_FACTORY || type == OBJECT_STATION || @@ -691,8 +687,8 @@ Error CTaskBuild::FlatFloor() } if ( max-BUILDMARGIN < radius ) { - m_main->SetShowLimit(1, PARTILIMIT2, m_metal, center, max-BUILDMARGIN, 10.0f); - m_main->SetShowLimit(2, PARTILIMIT3, m_metal, bPos, bRadius+BUILDMARGIN, 10.0f); + m_main->SetShowLimit(1, Gfx::PARTILIMIT2, m_metal, center, max-BUILDMARGIN, 10.0f); + m_main->SetShowLimit(2, Gfx::PARTILIMIT3, m_metal, bPos, bRadius+BUILDMARGIN, 10.0f); return bBase?ERR_BUILD_BASE:ERR_BUILD_NARROW; } @@ -711,8 +707,8 @@ CObject* CTaskBuild::SearchMetalObject(float &angle, float dMin, float dMax, int i; bool bMetal; - iPos = m_object->RetPosition(0); - iAngle = m_object->RetAngleY(0); + iPos = m_object->GetPosition(0); + iAngle = m_object->GetAngleY(0); iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI min = 1000000.0f; @@ -720,18 +716,18 @@ CObject* CTaskBuild::SearchMetalObject(float &angle, float dMin, float dMax, bMetal = false; for ( i=0 ; i<1000000 ; i++ ) { - pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i); + pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; - if ( !pObj->RetActif() ) continue; // objet inactive? - if ( pObj->RetTruck() != 0 ) continue; // object transported? + if ( !pObj->GetActif() ) continue; // objet inactive? + if ( pObj->GetTruck() != 0 ) continue; // object transported? - type = pObj->RetType(); + type = pObj->GetType(); if ( type != OBJECT_METAL ) continue; bMetal = true; // metal exists - oPos = pObj->RetPosition(0); + oPos = pObj->GetPosition(0); distance = Math::Distance(oPos, iPos); a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW! @@ -781,10 +777,10 @@ void CTaskBuild::DeleteMark(Math::Vector pos, float radius) for ( i=0 ; i<1000000 ; i++ ) { - pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i); + pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; - type = pObj->RetType(); + type = pObj->GetType(); if ( type != OBJECT_MARKSTONE && type != OBJECT_MARKURANIUM && type != OBJECT_MARKKEYa && @@ -793,7 +789,7 @@ void CTaskBuild::DeleteMark(Math::Vector pos, float radius) type != OBJECT_MARKKEYd && type != OBJECT_MARKPOWER ) continue; - oPos = pObj->RetPosition(0); + oPos = pObj->GetPosition(0); distance = Math::Distance(oPos, pos); if ( distance <= radius ) { -- cgit v1.2.3-1-g7c22