 |
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:32
|
|
for cultureOnly...
code:
//----------------------------------------------------------------------------
//
// Name : Player::CanBuildUnit
//
// Description: Checks whether the city can build the unit specified by type.
//
// Parameters : type: The unit type for that is checked whether the player can
// build it.
//
// Globals : g_player: The list of players
// g_theUnitDB: The unit database
// g_theWonderTracker: The wonder tracker
// g_exclusions: The exclusions data
//
// Returns : Whether the city can build the unit specified by type.
//
// Remark(s) : CultureOnly flag added by E. It allows only civilizations with
// the same CityStyle as CultureOnly's style to build that unit
//
//----------------------------------------------------------------------------
BOOL Player::CanBuildUnit(const sint32 type) const
{
const UnitRecord *rec = g_theUnitDB->Get(type);
if (!HasAdvance(rec->GetEnableAdvanceIndex()))
return FALSE;
sint32 o;
for(o = rec->GetNumObsoleteAdvance() - 1; o >= 0; o--) {
if(HasAdvance(rec->GetObsoleteAdvanceIndex(o)))
return FALSE;
}
if(g_exclusions->IsUnitExcluded(type))
return FALSE;
if(rec->GetCantBuild()) {
return FALSE;
}
if(rec->GetNumGovernmentType() > 0) {
sint32 i;
bool found = false;
for(i = 0; i < rec->GetNumGovernmentType(); i++) {
if(rec->GetGovernmentTypeIndex(i) == m_government_type) {
found = true;
break;
}
}
if(!found)
return FALSE;
}
if(rec->GetNuclearAttack() &&
wonderutil_GetNukesEliminated(g_theWonderTracker->GetBuiltWonders())) {
return FALSE;
}
if(rec->GetSlaveRaids() || rec->GetSettlerSlaveRaids() ||
rec->GetSlaveUprising()) {
if(wonderutil_GetFreeSlaves(g_theWonderTracker->GetBuiltWonders())) {
return FALSE;
}
}
if(rec->GetSlaveRaids() || rec->GetSettlerSlaveRaids()) {
sint32 i, n = m_all_units->Num();
for(i = 0; i < n; i++) {
if(m_all_units->Access(i).GetDBRec()->GetNoSlaves())
return FALSE;
}
}
if(rec->GetNoSlaves()) {
sint32 i, n = m_all_cities->Num();
for(i = 0; i < n; i++) {
if(m_all_cities->Access(i).CountSlaves() > 0)
return FALSE;
}
n = g_player[m_owner]->m_all_units->Num();
for(i = 0; i < n; i++) {
if(m_all_units->Access(i).GetDBRec()->GetSlaveRaids())
return FALSE;
}
}
if(rec->GetCreateParks() &&
!wonderutil_GetParkRangersEnabled(g_theWonderTrack
er->GetBuiltWonders())) {
return FALSE;
}
#if !defined(ACTIVISION_ORIGINAL)
if(rec->GetNumCultureOnly() > 0) {
sint32 s;
for(s = 0; s < rec->GetNumCultureOnly(); s++) {
if(rec->GetCultureOnlyIndex(s) == GetCivilisation()->GetCityStyle()) {
return TRUE;
}
}
return FALSE;
}
#endif
return TRUE;
}
Last edited by E on 15-03-2005 at 09:58
|
|
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:32
|
|
ok, I added the code in unit.cdb as such...
code:
Record Advance EnableAdvance
Record Advance[0..5] ObsoleteAdvance
Record Government[] GovernmentsModified
Record Terrain[] CanSettleOn //added by E
Record CityStyle[] CultureOnly //added by E -- can only build units if civ has certain citystyle
Record CityStyle[] CityStyleOnly //added by E--can only build units at cities with certain citystyle
I think I got it right. I say citystyle in the citystyle.cdb and since my code mirrors government type I copied the same in and renamed it (obviously)
If this is okay I'm going to added it to buildings, terrain improvements, wonders, governments, and advances. Of course they won't use the citystyle one just cultureonly, but I'm thinking advances might be difficult because they may be captured.
Also, once I do this I'm thinking I'll add the government type code to them as well and when I add my code fragment to the other CanBuild stuff I'll put the government Type in there, I don't think it should cause any problems...
Last edited by E on 16-03-2005 at 10:53
|
|
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:32
|
|
Martin, I've added most of the code snipits to the citydata, player, wonder_util, but I'm little unsure where to put it in terrain improvements:
code:
bool terrainutil_CanPlayerBuild(const TerrainImprovementRecord *rec, sint32 pl, bool checkMaterials)
{
Assert(rec != NULL);
if(rec == NULL)
return false;
Assert(pl >= 0);
Assert(pl < k_MAX_PLAYERS);
if(pl < 0 || pl >= k_MAX_PLAYERS)
return false;
Assert(g_player[pl]);
if(!g_player[pl])
return false;
if(terrainutil_PlayerHasAdvancesFor(rec, pl)) {
if(!checkMaterials)
return true;
sint32 i;
for(i = 0; i < g_theTerrainDB->NumRecords(); i++) {
if(terrainutil_PlayerHasAdvancesForTerrain(rec,
pl, i)) {
HERE? since it access the DB but would that affect terraforming?
if(rec->GetClassTerraform()) {
sint32 toterrain;
if(!rec->GetTerraformTerrainIndex(toterrain))
return false;
const TerrainRecord::TransformData *tfrom = terrainutil_GetTransformData(toterrain, true);
const TerrainRecord::TransformData *tto = terrainutil_GetTransformData(toterrain, false);
OR HERE BEFORE IT CHECKS MATERIALS?
if(g_player[pl]->m_materialPool->GetMaterials() >= tfrom->GetMaterials() + tto->GetMaterials()) {
return true;
}
} else {
const TerrainImprovementRecord::Effect *eff;
eff = terrainutil_GetTerrainEffect(rec, i);
if(eff) {
if(g_player[pl]->m_materialPool->GetMaterials() >= eff->GetProductionCost()) {
return true;
}
}
}
}
}
}
return false;
}
|
|
|  |
 |
|  |
All times are GMT. The time now is 05:32. Apolyton Time is 00:32. |
top of page
|
|
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|