Territorial limits applied
This was SVN commit r5244.
This commit is contained in:
parent
2ce74c53b1
commit
7eaa6d3454
@ -29,6 +29,7 @@
|
||||
<Stone>100</Stone>
|
||||
<Metal>100</Metal>
|
||||
</Resource>
|
||||
<BuildingLimitCategory>CivilCentre</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -24,6 +24,7 @@
|
||||
<Resource>
|
||||
<Wood>100</Wood>
|
||||
</Resource>
|
||||
<BuildingLimitCategory>House</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -25,6 +25,7 @@
|
||||
<Wood>50</Wood>
|
||||
<Stone>50</Stone>
|
||||
</Resource>
|
||||
<BuildingLimitCategory>ScoutTower</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
<Creation>
|
||||
<Foundation>foundation_3x3</Foundation>
|
||||
<BuildingLimitCategory>Farmstead</BuildingLimitCategory>
|
||||
<Resource>
|
||||
<Wood>200</Wood>
|
||||
</Resource>
|
||||
|
@ -25,6 +25,7 @@
|
||||
<Wood>200</Wood>
|
||||
<Stone>100</Stone>
|
||||
</Resource>
|
||||
<BuildingLimitCategory>Barracks</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -26,6 +26,7 @@
|
||||
</Creation>
|
||||
<Creation>
|
||||
<Foundation>foundation_4x4</Foundation>
|
||||
<BuildingLimitCategory>Dock</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -25,6 +25,7 @@
|
||||
<Metal>200</Metal>
|
||||
<Stone>800</Stone>
|
||||
</Resource>
|
||||
<BuildingLimitCategory>Fortress</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
<Creation>
|
||||
<Foundation>foundation_3x3</Foundation>
|
||||
<BuildingLimitCategory>Field</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
<Creation>
|
||||
<Foundation>foundation_5x5</Foundation>
|
||||
<BuildingLimitCategory>Special</BuildingLimitCategory>
|
||||
</Creation>
|
||||
|
||||
<Footprint>
|
||||
|
@ -110,6 +110,7 @@ function entityInit( evt )
|
||||
this.buildPoints = new Object();
|
||||
this.buildPoints.curr = 0.0;
|
||||
this.buildPoints.max = parseFloat( building.traits.creation.time );
|
||||
this.traits.creation.buildingLimitCategory = building.traits.creation.buildingLimitCategory;
|
||||
}
|
||||
|
||||
// Generate civ code (1st four characters of civ name, in lower case eg "Carthaginians" => "cart").
|
||||
@ -2178,3 +2179,24 @@ function entityEventFormation( evt )
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function getBuildingLimit( category/*, gameMode*/ )
|
||||
{
|
||||
console.write(category);
|
||||
// Civil
|
||||
if(category=="CivilCentre") return 1;
|
||||
if(category=="House") return 15;
|
||||
if(category=="Farmstead") return 2;
|
||||
if(category=="Field") return 5;
|
||||
// Military
|
||||
if(category=="Dock") return 2;
|
||||
if(category=="Fortress") return 1;
|
||||
if(category=="Barracks") return 2;
|
||||
if(category=="ScoutTower") return 10;
|
||||
// Other
|
||||
if(category=="Special") return 1;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1376,7 +1376,6 @@ bool CBuildingPlacer::Activate(CStrW& templateName)
|
||||
return false;
|
||||
}
|
||||
|
||||
// m_actor
|
||||
CStr actorName ( m_template->m_actorName ); // convert CStrW->CStr8
|
||||
|
||||
std::set<CStr8> selections;
|
||||
@ -1393,6 +1392,8 @@ bool CBuildingPlacer::Activate(CStrW& templateName)
|
||||
m_bounds = new CBoundingBox( 0, 0, CVector2D(1, 0), m_template->m_bound_box );
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1508,7 +1509,7 @@ void CBuildingPlacer::Update( float timeStep )
|
||||
}
|
||||
|
||||
// Validate placement location.
|
||||
CheckValid(pos, onSocket);
|
||||
CheckValidLocation(pos, onSocket);
|
||||
|
||||
// Flash our actor red if the position is invalid.
|
||||
|
||||
@ -1525,12 +1526,16 @@ void CBuildingPlacer::Update( float timeStep )
|
||||
m_actor->GetModel()->SetShadingColor( col );
|
||||
}
|
||||
|
||||
// Alex's mess
|
||||
void CBuildingPlacer::CheckValid( CVector3D pos, bool onSocket )
|
||||
/**
|
||||
* Check whether the placement location is valid (look at whether we're
|
||||
* on the map, who owns the territory, whether we are on a socket, and
|
||||
* whether we are colliding with anything).
|
||||
*
|
||||
* @param pos position under the cursor
|
||||
* @param onSocket whether on a socket or not
|
||||
*/
|
||||
void CBuildingPlacer::CheckValidLocation( CVector3D pos, bool onSocket )
|
||||
{
|
||||
// Check whether the placement location is valid (look at whether we're
|
||||
// on the map, who owns the territory, whether we are on a socket, and
|
||||
// whether we are colliding with anything).
|
||||
CTerrain *pTerrain=g_Game->GetWorld()->GetTerrain();
|
||||
if( pTerrain->IsOnMap( pos.X, pos.Z ) )
|
||||
{
|
||||
@ -1550,8 +1555,11 @@ void CBuildingPlacer::CheckValid( CVector3D pos, bool onSocket )
|
||||
// anything except possibly our socket (which we find out by passing an
|
||||
// ignoreClass to GetCollisionObject); also, if we are a socketed object,
|
||||
// we check that we are actually on a socket, using onSocket (set above).
|
||||
// UPDATED: Check for territorial building limit
|
||||
|
||||
m_valid = ( m_template->m_socket == L"" || onSocket )
|
||||
&& ( GetCollisionObject( m_bounds, 0, &m_template->m_socket ) == 0 );
|
||||
&& ( GetCollisionObject( m_bounds, 0, &m_template->m_socket ) == 0 )
|
||||
&& IsWithinLimit(pos); // Is this building within its appropriate territorial limit?
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1559,3 +1567,50 @@ void CBuildingPlacer::CheckValid( CVector3D pos, bool onSocket )
|
||||
m_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether there is space (territorial limit) in the current territory
|
||||
*
|
||||
* @param pos position under the cursor
|
||||
*
|
||||
* @returns true if within limit, false otherwise
|
||||
*/
|
||||
bool CBuildingPlacer::IsWithinLimit( CVector3D pos )
|
||||
{
|
||||
// Get the territorial building limit based on its category
|
||||
CStrW category = m_template->m_buildingLimitCategory;
|
||||
jsval param = ToJSVal(category);
|
||||
int limit = ToPrimitive<int>(g_ScriptingHost.CallFunction("getBuildingLimit", ¶m, 1));
|
||||
|
||||
if( limit == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CTerritory* territory = g_Game->GetWorld()->GetTerritoryManager()->GetTerritory( pos.X, pos.Z );
|
||||
|
||||
std::vector<CEntity*> extantEntities;
|
||||
std::vector<CEntity*>::iterator entIter;
|
||||
int buildingCount = 0; // Number of buildings in the current territory
|
||||
|
||||
g_EntityManager.GetExtant(extantEntities);
|
||||
|
||||
// NOTE: This loop runs continuously because the function is called in Update()
|
||||
for( entIter = extantEntities.begin(); entIter != extantEntities.end(); entIter++ )
|
||||
{
|
||||
if((*entIter)->m_buildingLimitCategory == m_template->m_buildingLimitCategory
|
||||
&& g_Game->GetWorld()->GetTerritoryManager()->GetTerritory( (*entIter)->m_position.X, (*entIter)->m_position.Z ) == territory)
|
||||
{
|
||||
buildingCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if(buildingCount < limit)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -178,7 +178,8 @@ struct CBuildingPlacer : public Singleton<CBuildingPlacer>
|
||||
void MousePressed();
|
||||
void MouseReleased();
|
||||
void Update( float timeStep );
|
||||
void CheckValid( CVector3D pos, bool onSocket );
|
||||
void CheckValidLocation( CVector3D pos, bool onSocket );
|
||||
bool IsWithinLimit( CVector3D pos );
|
||||
};
|
||||
|
||||
bool IsMouseoverType( CEntity* ev, void* userdata );
|
||||
|
@ -164,6 +164,9 @@ public:
|
||||
// If the object is a territory centre, this points to its territory
|
||||
CTerritory* m_associatedTerritory;
|
||||
|
||||
// Territorial limit
|
||||
CStrW m_buildingLimitCategory;
|
||||
|
||||
// Auras
|
||||
AuraTable m_auras;
|
||||
AuraSet m_aurasInfluencingMe;
|
||||
|
@ -121,6 +121,8 @@ void CEntity::ScriptingInit()
|
||||
AddClassProperty( L"building", &CEntity::m_building );
|
||||
AddClassProperty( L"visible", &CEntity::m_visible );
|
||||
AddClassProperty( L"productionQueue", &CEntity::m_productionQueue );
|
||||
AddClassProperty( L"traits.creation.buildingLimitCategory", &CEntity::m_buildingLimitCategory );
|
||||
|
||||
|
||||
CJSComplex<CEntity>::ScriptingInit( "Entity", Construct, 2 );
|
||||
}
|
||||
|
@ -466,6 +466,9 @@ void CEntityTemplate::ScriptingInit()
|
||||
AddClassProperty( L"traits.creation.foundation", &CEntityTemplate::m_foundation );
|
||||
AddClassProperty( L"traits.creation.socket", &CEntityTemplate::m_socket );
|
||||
AddClassProperty( L"traits.creation.territoryRestriction", &CEntityTemplate::m_territoryRestriction );
|
||||
AddClassProperty( L"traits.creation.buildingLimitCategory", &CEntityTemplate::m_buildingLimitCategory );
|
||||
|
||||
|
||||
|
||||
CJSComplex<CEntityTemplate>::ScriptingInit( "EntityTemplate" );
|
||||
}
|
||||
|
@ -136,6 +136,9 @@ public:
|
||||
// Can be "allied" to allow placement only in allied territories, or "" or "all" for all territories
|
||||
CStrW m_territoryRestriction;
|
||||
|
||||
// Territorial limit
|
||||
CStrW m_buildingLimitCategory;
|
||||
|
||||
float m_speed;
|
||||
float m_runSpeed;
|
||||
float m_runRegenRate;
|
||||
|
Loading…
Reference in New Issue
Block a user