From fce69aaa7f9ddd7ba809a3111ae0d587b3bfe8f3 Mon Sep 17 00:00:00 2001 From: Matei Date: Tue, 8 Aug 2006 03:45:13 +0000 Subject: [PATCH] # - Housekeeping # - Territory restriction rules for buildings. This was SVN commit r4206. --- source/ps/Interact.cpp | 23 ++++++++-- source/simulation/Collision.cpp | 7 +-- source/simulation/Entity.cpp | 30 +++++------- source/simulation/Entity.h | 48 ------------------- source/simulation/EntityStateProcessing.cpp | 1 + source/simulation/EntityTemplate.cpp | 51 +++++++++++---------- source/simulation/EntityTemplate.h | 5 +- source/simulation/LOSManager.cpp | 2 +- source/simulation/TerritoryManager.cpp | 2 +- 9 files changed, 67 insertions(+), 102 deletions(-) diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index 3cf730b3d4..e614886148 100644 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -32,6 +32,7 @@ #include "simulation/EntityFormation.h" #include "simulation/EntityManager.h" #include "simulation/FormationManager.h" +#include "simulation/TerritoryManager.h" #include "simulation/Simulation.h" #include "ps/CLogger.h" @@ -1350,7 +1351,7 @@ bool CBuildingPlacer::activate(CStrW& templateName) std::set selections; m_actor = g_UnitMan.CreateUnit( actorName, 0, selections ); - m_actor->SetPlayerID(g_Game->GetLocalPlayer()->GetPlayerID()); + m_actor->SetPlayerID( g_Game->GetLocalPlayer()->GetPlayerID() ); // m_bounds if( m_template->m_bound_type == CBoundingObject::BOUND_CIRCLE ) @@ -1480,9 +1481,25 @@ void CBuildingPlacer::update( float timeStep ) // socketted object, we check that we are in fact on a socket, using onSocket. CTerrain *pTerrain=g_Game->GetWorld()->GetTerrain(); - m_valid = pTerrain->isOnMap( pos.X, pos.Z ) - && ( m_template->m_socket == L"" || onSocket ) + + if( pTerrain->isOnMap( pos.X, pos.Z ) ) + { + m_valid = ( m_template->m_socket == L"" || onSocket ) && ( getCollisionObject( m_bounds, 0, &m_template->m_socket ) == 0 ); + + // Check that we are being placed in a valid territory; currently, m_territoryRestriction + // can be either "Allied" for placing in allied territories, or nothing. Since there's no + // diplomacy yet, "allied" just means "owned by us" for now. + CTerritory* territory = g_Game->GetWorld()->GetTerritoryManager()->GetTerritory( pos.X, pos.Z ); + if( m_template->m_territoryRestriction == L"Allied" && territory->owner != g_Game->GetLocalPlayer() ) + { + m_valid = false; + } + } + else + { + m_valid = false; + } // Flash our actor red if the position is invalid. diff --git a/source/simulation/Collision.cpp b/source/simulation/Collision.cpp index 4827d92fca..f7e53788af 100644 --- a/source/simulation/Collision.cpp +++ b/source/simulation/Collision.cpp @@ -49,7 +49,6 @@ CEntity* GetCollisionObject( float x, float y ) CBoundingObject* getCollisionObject( CBoundingObject* bounds, CPlayer* player, const CStrW* ignoreClass ) { std::vector entities; - entities.reserve(8); g_EntityManager.GetInRange( bounds->m_pos.x, bounds->m_pos.y, COLLISION_RANGE, entities ); std::vector::iterator it; @@ -60,7 +59,7 @@ CBoundingObject* getCollisionObject( CBoundingObject* bounds, CPlayer* player, c /* If the unit is marked to ignore ally collisions, and the player parameter is passed in and the same player as the unit, then ignore the (potential) collision */ - if( player && (*it)->m_passThroughAllies && (*it)->m_player == player ) continue; + if( player && (*it)->m_base->m_passThroughAllies && (*it)->m_player == player ) continue; if( ignoreClass && (*it)->m_classes.IsMember( *ignoreClass ) ) continue; @@ -77,7 +76,6 @@ CBoundingObject* getCollisionObject( CBoundingObject* bounds, CPlayer* player, c CEntity* getCollisionEntity( CBoundingObject* bounds, CPlayer* player, const CStrW* ignoreClass ) { std::vector entities; - entities.reserve(8); g_EntityManager.GetInRange( bounds->m_pos.x, bounds->m_pos.y, COLLISION_RANGE, entities ); std::vector::iterator it; @@ -88,7 +86,7 @@ CEntity* getCollisionEntity( CBoundingObject* bounds, CPlayer* player, const CSt /* If the unit is marked to ignore ally collisions, and the player parameter is passed in and the same player as the unit, then ignore the (potential) collision */ - if( player && (*it)->m_passThroughAllies && (*it)->m_player == player ) continue; + if( player && (*it)->m_base->m_passThroughAllies && (*it)->m_player == player ) continue; if( ignoreClass && (*it)->m_classes.IsMember( *ignoreClass ) ) continue; @@ -110,7 +108,6 @@ HEntity getCollisionObject( CEntity* entity ) #endif std::vector entities; - entities.reserve(8); g_EntityManager.GetInRange( entity->m_position.X, entity->m_position.Z, COLLISION_RANGE, entities ); std::vector::iterator it; diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 24660599b8..c18886af97 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -1345,7 +1345,7 @@ void CEntity::renderRallyPoint() if( !m_visible ) return; - if ( !entf_get(ENTF_HAS_RALLY_POINT) || g_Selection.m_unitUITextures.find(m_rallyTexture) == + if ( !entf_get(ENTF_HAS_RALLY_POINT) || g_Selection.m_unitUITextures.find(m_base->m_rallyName) == g_Selection.m_unitUITextures.end() ) { return; @@ -1362,10 +1362,10 @@ void CEntity::renderRallyPoint() CSprite sprite; CTexture tex; - tex.SetHandle( g_Selection.m_unitUITextures[m_rallyTexture] ); + tex.SetHandle( g_Selection.m_unitUITextures[m_base->m_rallyName] ); sprite.SetTexture(&tex); CVector3D rally = m_rallyPoint; - rally.Y += m_rallyHeight/2.f + .1f; + rally.Y += m_base->m_rallyHeight/2.f + .1f; sprite.SetTranslation(rally); sprite.Render(); } @@ -1457,13 +1457,12 @@ void CEntity::ScriptingInit() /* Any inherited property MUST be added to EntityTemplate.cpp as well */ - AddClassProperty( L"actions.move.speed_curr", &CEntity::m_speed ); + AddClassProperty( L"actions.move.speedCurr", &CEntity::m_speed ); AddClassProperty( L"actions.move.run.speed", &CEntity::m_runSpeed ); AddClassProperty( L"actions.move.run.rangemin", &CEntity::m_runMinRange ); AddClassProperty( L"actions.move.run.range", &CEntity::m_runMaxRange ); - AddClassProperty( L"actions.move.run.regen_rate", &CEntity::m_runRegenRate ); - AddClassProperty( L"actions.move.run.decay_rate", &CEntity::m_runDecayRate ); - AddClassProperty( L"actions.move.pass_through_allies", &CEntity::m_passThroughAllies ); + AddClassProperty( L"actions.move.run.regenRate", &CEntity::m_runRegenRate ); + AddClassProperty( L"actions.move.run.decayRate", &CEntity::m_runDecayRate ); AddClassProperty( L"selected", &CEntity::m_selected, false, (NotifyFn)&CEntity::checkSelection ); AddClassProperty( L"group", &CEntity::m_grouped, false, (NotifyFn)&CEntity::checkGroup ); AddClassProperty( L"traits.extant", &CEntity::m_extant ); @@ -1473,23 +1472,18 @@ void CEntity::ScriptingInit() AddClassProperty( L"player", (GetFn)&CEntity::JSI_GetPlayer, (SetFn)&CEntity::JSI_SetPlayer ); AddClassProperty( L"traits.health.curr", &CEntity::m_healthCurr ); AddClassProperty( L"traits.health.max", &CEntity::m_healthMax ); - AddClassProperty( L"traits.health.regen_rate", &CEntity::m_healthRegenRate ); - AddClassProperty( L"traits.health.regen_start", &CEntity::m_healthRegenStart ); - AddClassProperty( L"traits.health.decay_rate", &CEntity::m_healthDecayRate ); + AddClassProperty( L"traits.health.regenRate", &CEntity::m_healthRegenRate ); + AddClassProperty( L"traits.health.regenStart", &CEntity::m_healthRegenStart ); + AddClassProperty( L"traits.health.decayRate", &CEntity::m_healthDecayRate ); AddClassProperty( L"traits.stamina.curr", &CEntity::m_staminaCurr ); AddClassProperty( L"traits.stamina.max", &CEntity::m_staminaMax ); - AddClassProperty( L"traits.rally.name", &CEntity::m_rallyTexture ); - AddClassProperty( L"traits.rally.width", &CEntity::m_rallyWidth ); - AddClassProperty( L"traits.rally.height", &CEntity::m_rallyHeight ); AddClassProperty( L"traits.rank.name", &CEntity::m_rankName ); AddClassProperty( L"traits.vision.los", &CEntity::m_los ); - AddClassProperty( L"traits.vision.permanent", &CEntity::m_permanent ); - AddClassProperty( L"traits.is_territory_centre", &CEntity::m_isTerritoryCentre ); - AddClassProperty( L"last_combat_time", &CEntity::m_lastCombatTime ); - AddClassProperty( L"last_run_time", &CEntity::m_lastRunTime ); + AddClassProperty( L"lastCombatTime", &CEntity::m_lastCombatTime ); + AddClassProperty( L"lastRunTime", &CEntity::m_lastRunTime ); AddClassProperty( L"building", &CEntity::m_building ); AddClassProperty( L"visible", &CEntity::m_visible ); - AddClassProperty( L"production_queue", &CEntity::m_productionQueue ); + AddClassProperty( L"productionQueue", &CEntity::m_productionQueue ); CJSComplex::ScriptingInit( "Entity", Construct, 2 ); } diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index e69cc22420..77b0f08482 100644 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -109,7 +109,6 @@ public: float m_runSpeed; float m_runRegenRate; float m_runDecayRate; - bool m_passThroughAllies; float m_maxActorPitch; float m_minActorPitch; @@ -163,17 +162,9 @@ public: //Rank properties CStr m_rankName; - //Rally texture - CStr m_rallyTexture; - float m_rallyWidth; - float m_rallyHeight; // LOS int m_los; - bool m_permanent; - - // Is this object a territory centre? (e.g. Settlements in 0AD) - bool m_isTerritoryCentre; // If the object is a territory centre, this points to its territory CTerritory* m_associatedTerritory; @@ -235,45 +226,6 @@ public: std::vector m_sectorValues; - /* JW: these have all been 'moved' (1) into EntityTemplate: - 1: were already present there, just removed from here - int m_sectorDivs; - - int m_pitchDivs; - - float m_staminaBarHeight; - int m_staminaBarSize; - float m_staminaBarWidth; - - float m_healthBarHeight; - int m_healthBarSize; - float m_healthBarWidth; - - int m_staminaBorderWidth; - int m_staminaBorderHeight; - CStr m_staminaBorderName; - - float m_rankHeight; - float m_rankWidth; - - // Minimap properties - CStrW m_minimapType; - int m_minimapR; - int m_minimapG; - int m_minimapB; - - // Y anchor - CStrW m_anchorType; - float m_anchorConformX; - float m_anchorConformZ; - - int m_healthBorderWidth; - int m_healthBorderHeight; - CStr m_healthBorderName; - */ - - - private: CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building = 0 ); diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 8b80c8fd30..4413ff91c9 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -470,6 +470,7 @@ bool CEntity::processContactActionNoPathing( CEntityOrder* current, size_t times case ALREADY_AT_DESTINATION: case REACHED_DESTINATION: case COLLISION_WITH_DESTINATION: + case WOULD_LEAVE_MAP: // Not too far any more... break; case NORMAL: diff --git a/source/simulation/EntityTemplate.cpp b/source/simulation/EntityTemplate.cpp index e859625cab..5051e0ba3b 100644 --- a/source/simulation/EntityTemplate.cpp +++ b/source/simulation/EntityTemplate.cpp @@ -391,36 +391,36 @@ void CEntityTemplate::ScriptingInit() AddClassProperty( L"traits.id.classes", (GetFn)&CEntityTemplate::getClassSet, (SetFn)&CEntityTemplate::setClassSet ); - AddClassProperty( L"actions.move.speed_curr", &CEntityTemplate::m_speed ); + AddClassProperty( L"actions.move.speedCurr", &CEntityTemplate::m_speed ); AddClassProperty( L"actions.move.turningRadius", &CEntityTemplate::m_turningRadius ); AddClassProperty( L"actions.move.run.speed", &CEntityTemplate::m_runSpeed ); AddClassProperty( L"actions.move.run.rangeMin", &CEntityTemplate::m_runMinRange ); AddClassProperty( L"actions.move.run.range", &CEntityTemplate::m_runMaxRange ); - AddClassProperty( L"actions.move.run.regen_rate", &CEntityTemplate::m_runRegenRate ); - AddClassProperty( L"actions.move.run.decay_rate", &CEntityTemplate::m_runDecayRate ); - AddClassProperty( L"actions.move.pass_through_allies", &CEntityTemplate::m_passThroughAllies ); + AddClassProperty( L"actions.move.run.regenRate", &CEntityTemplate::m_runRegenRate ); + AddClassProperty( L"actions.move.run.decayRate", &CEntityTemplate::m_runDecayRate ); + AddClassProperty( L"actions.move.passThroughAllies", &CEntityTemplate::m_passThroughAllies ); AddClassProperty( L"actor", &CEntityTemplate::m_actorName ); AddClassProperty( L"traits.health.max", &CEntityTemplate::m_healthMax ); - AddClassProperty( L"traits.health.bar_height", &CEntityTemplate::m_healthBarHeight ); - AddClassProperty( L"traits.health.bar_size", &CEntityTemplate::m_healthBarSize ); - AddClassProperty( L"traits.health.bar_width", &CEntityTemplate::m_healthBarWidth ); - AddClassProperty( L"traits.health.border_height", &CEntityTemplate::m_healthBorderHeight); - AddClassProperty( L"traits.health.border_width", &CEntityTemplate::m_healthBorderWidth ); - AddClassProperty( L"traits.health.border_name", &CEntityTemplate::m_healthBorderName ); - AddClassProperty( L"traits.health.regen_rate", &CEntityTemplate::m_healthRegenRate ); - AddClassProperty( L"traits.health.regen_start", &CEntityTemplate::m_healthRegenStart ); - AddClassProperty( L"traits.health.decay_rate", &CEntityTemplate::m_healthDecayRate ); + AddClassProperty( L"traits.health.barHeight", &CEntityTemplate::m_healthBarHeight ); + AddClassProperty( L"traits.health.barSize", &CEntityTemplate::m_healthBarSize ); + AddClassProperty( L"traits.health.barWidth", &CEntityTemplate::m_healthBarWidth ); + AddClassProperty( L"traits.health.borderHeight", &CEntityTemplate::m_healthBorderHeight); + AddClassProperty( L"traits.health.borderWidth", &CEntityTemplate::m_healthBorderWidth ); + AddClassProperty( L"traits.health.borderName", &CEntityTemplate::m_healthBorderName ); + AddClassProperty( L"traits.health.regenRate", &CEntityTemplate::m_healthRegenRate ); + AddClassProperty( L"traits.health.regenStart", &CEntityTemplate::m_healthRegenStart ); + AddClassProperty( L"traits.health.decayRate", &CEntityTemplate::m_healthDecayRate ); AddClassProperty( L"traits.stamina.max", &CEntityTemplate::m_staminaMax ); - AddClassProperty( L"traits.stamina.bar_height", &CEntityTemplate::m_staminaBarHeight ); - AddClassProperty( L"traits.stamina.bar_size", &CEntityTemplate::m_staminaBarSize ); - AddClassProperty( L"traits.stamina.bar_width", &CEntityTemplate::m_staminaBarWidth ); - AddClassProperty( L"traits.stamina.border_height", &CEntityTemplate::m_staminaBorderHeight); - AddClassProperty( L"traits.stamina.border_width", &CEntityTemplate::m_staminaBorderWidth ); - AddClassProperty( L"traits.stamina.border_name", &CEntityTemplate::m_staminaBorderName ); + AddClassProperty( L"traits.stamina.barHeight", &CEntityTemplate::m_staminaBarHeight ); + AddClassProperty( L"traits.stamina.barSize", &CEntityTemplate::m_staminaBarSize ); + AddClassProperty( L"traits.stamina.barWidth", &CEntityTemplate::m_staminaBarWidth ); + AddClassProperty( L"traits.stamina.borderHeight", &CEntityTemplate::m_staminaBorderHeight); + AddClassProperty( L"traits.stamina.borderWidth", &CEntityTemplate::m_staminaBorderWidth ); + AddClassProperty( L"traits.stamina.borderName", &CEntityTemplate::m_staminaBorderName ); AddClassProperty( L"traits.rally.name", &CEntityTemplate::m_rallyName ); AddClassProperty( L"traits.rally.width", &CEntityTemplate::m_rallyWidth ); AddClassProperty( L"traits.rally.height", &CEntityTemplate::m_rallyHeight ); - AddClassProperty( L"traits.flank_penalty.sectors", &CEntityTemplate::m_sectorDivs ); + AddClassProperty( L"traits.flankPenalty.sectors", &CEntityTemplate::m_sectorDivs ); AddClassProperty( L"traits.pitch.sectors", &CEntityTemplate::m_pitchDivs ); AddClassProperty( L"traits.rank.width", &CEntityTemplate::m_rankWidth ); AddClassProperty( L"traits.rank.height", &CEntityTemplate::m_rankHeight ); @@ -433,16 +433,17 @@ void CEntityTemplate::ScriptingInit() AddClassProperty( L"traits.anchor.conformX", &CEntityTemplate::m_anchorConformX ); AddClassProperty( L"traits.anchor.conformZ", &CEntityTemplate::m_anchorConformZ ); AddClassProperty( L"traits.vision.los", &CEntityTemplate::m_los ); - AddClassProperty( L"traits.vision.permanent", &CEntityTemplate::m_permanent ); + AddClassProperty( L"traits.vision.permanent", &CEntityTemplate::m_visionPermanent ); AddClassProperty( L"traits.display.bars.enabled", &CEntityTemplate::m_barsEnabled ); AddClassProperty( L"traits.display.bars.offset", &CEntityTemplate::m_barOffset ); AddClassProperty( L"traits.display.bars.height", &CEntityTemplate::m_barHeight ); AddClassProperty( L"traits.display.bars.width", &CEntityTemplate::m_barWidth ); AddClassProperty( L"traits.display.bars.border", &CEntityTemplate::m_barBorder ); - AddClassProperty( L"traits.display.bars.border_size", &CEntityTemplate::m_barBorderSize ); - AddClassProperty( L"traits.is_territory_centre", &CEntityTemplate::m_isTerritoryCentre ); - AddClassProperty( L"traits.foundation", &CEntityTemplate::m_foundation ); - AddClassProperty( L"traits.socket", &CEntityTemplate::m_socket ); + AddClassProperty( L"traits.display.bars.borderSize", &CEntityTemplate::m_barBorderSize ); + AddClassProperty( L"traits.isTerritoryCentre", &CEntityTemplate::m_isTerritoryCentre ); + AddClassProperty( L"traits.creation.foundation", &CEntityTemplate::m_foundation ); + AddClassProperty( L"traits.creation.socket", &CEntityTemplate::m_socket ); + AddClassProperty( L"traits.creation.territoryRestriction", &CEntityTemplate::m_territoryRestriction ); CJSComplex::ScriptingInit( "EntityTemplate" ); } diff --git a/source/simulation/EntityTemplate.h b/source/simulation/EntityTemplate.h index 49afc74d2f..b8250eda05 100644 --- a/source/simulation/EntityTemplate.h +++ b/source/simulation/EntityTemplate.h @@ -118,7 +118,7 @@ public: // LOS int m_los; - bool m_permanent; + bool m_visionPermanent; // Is this object a territory centre? (e.g. Settlements in 0AD) bool m_isTerritoryCentre; @@ -129,6 +129,9 @@ public: // Socket entity that we can be built on, or "" for free placement CStrW m_socket; + // Can be "allied" to allow placement only in allied territories, or "" or "all" for all territories + CStrW m_territoryRestriction; + float m_speed; float m_runSpeed; float m_runRegenRate; diff --git a/source/simulation/LOSManager.cpp b/source/simulation/LOSManager.cpp index 69bee4deaf..c245447dd7 100644 --- a/source/simulation/LOSManager.cpp +++ b/source/simulation/LOSManager.cpp @@ -217,7 +217,7 @@ EUnitLOSStatus CLOSManager::GetUnitStatus(CUnit* unit, CPlayer* player) if(status & LOS_EXPLORED) { - if(unit->GetEntity() == 0 || unit->GetEntity()->m_permanent) + if(unit->GetEntity() == 0 || unit->GetEntity()->m_base->m_visionPermanent) { // both actors (which are usually for decoration) and units with the // permanent flag should be remembered diff --git a/source/simulation/TerritoryManager.cpp b/source/simulation/TerritoryManager.cpp index 2f844ac628..0845ce133b 100644 --- a/source/simulation/TerritoryManager.cpp +++ b/source/simulation/TerritoryManager.cpp @@ -62,7 +62,7 @@ void CTerritoryManager::Recalculate() g_EntityManager.GetExtant(entities); for( size_t i=0; im_isTerritoryCentre ) + if( entities[i]->m_base->m_isTerritoryCentre ) centres.push_back(entities[i]); }