Martin has been helping me (in the other forum) on how to code Cities that can only settle on specific types of terrain. I might be almost done with that, so my next attempt is along the same lines. Its to add a flag that makes it so that the player can only build terrain improvements on tiles with certain goods. I feel this will give the modder the ability to add some unique improvements and add different bonuses to a game.
I know I have to add a spot in the terrutil.cdb, but terrainutil.cpp will be my coding challenging
this is just my working start, but comment if interested....
I know I have to add a spot in the terrutil.cdb, but terrainutil.cpp will be my coding challenging
Code:
bool terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos) { sint32 i; [b] I think I need to define a variable here [/b] 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; Cell *cell = g_theWorld->GetCell(pos); Assert(cell); if(!cell) return false; if(cell->GetOwner() == -1) { if(rec->GetIntBorderRadius()) { if(!g_player[pl]->IsVisible(pos)) { return false; } } else { return false; } } if(cell->GetOwner() >= 0 && cell->GetOwner() != pl) { bool haveAlliance = AgreementMatrix.s_agreements.HasAgreement(pl, cell->GetOwner(), PROPOSAL_TREATY_ALLIANCE); if(cell->GetOwner() > 0 && haveAlliance) { if(rec->GetClassRoad() || (g_player[pl]->GetGaiaController() && g_player[pl]->GetGaiaController()->GaiaControllerTileImp(rec->GetIndex()))) { } else { return false; } } else { return false; } } if(g_theWorld->GetCity(pos).IsValid()) return false; if(rec->GetClassTerraform()) { sint32 terr; if(!rec->GetTerraformTerrainIndex(terr)) return false; if(cell->GetTerrain() == terr) return false; const TerrainRecord *tfrom = g_theTerrainDB->Get(cell->GetTerrain()); const TerrainRecord *tto = g_theTerrainDB->Get(terr); if(tfrom->GetRemoveAdvanceIndex() < 0 || tto->GetAddAdvanceIndex() < 0) return false; if(!g_player[pl]->HasAdvance(tfrom->GetRemoveAdvanceIndex()) || !g_player[pl]->HasAdvance(tto->GetAddAdvanceIndex())) { return false; } } else { const TerrainImprovementRecord::Effect *eff; eff = terrainutil_GetTerrainEffect(rec, cell->GetTerrain()); if(!eff) return false; if(!g_player[pl]->HasAdvance(eff->GetEnableAdvanceIndex())) return false; sint32 a; for(a = 0; a < eff->GetNumObsoleteAdvance(); a++) { if(g_player[pl]->HasAdvance(eff->GetObsoleteAdvanceIndex(a))) { return false; } } [i][b] I think this is the code I should base it on: [/b][/i] [b]for(i = 0; i < rec->GetNumCantBuildOn(); i++) { if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) { return FALSE; } } [/b] } [i][b] but something like this: [/b][/i] [b]for(r = 0; r < g_theResourceDB->Get(resource); r++) { if(rec->GetBuildGoodOnIndex(r) == cell->GetTerrain()) { return FALSE; //changed, thanks J } } [/b] return true; }
this is just my working start, but comment if interested....
Comment