Skip to content

Commit

Permalink
Added BordersModifier GSM province function
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed May 26, 2016
1 parent 71fa686 commit 82e851b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/include/grand_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class CGrandStrategyProvince : public CProvince
void SetBorderProvinceConnectionTransportLevel(CGrandStrategyProvince *province, int transport_level);
bool HasBuildingClass(std::string building_class_name);
bool HasModifier(CUpgrade *modifier);
bool BordersModifier(CUpgrade *modifier);
bool HasFactionClaim(int civilization_id, int faction_id);
bool HasResource(int resource, bool ignore_prospection = false);
bool BordersProvince(CGrandStrategyProvince *province);
Expand Down
42 changes: 36 additions & 6 deletions src/stratagus/grand_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,10 +1382,12 @@ void CGrandStrategyGame::DoEvents()
{
for (int i = 0; i < MAX_RACES; ++i) {
for (size_t j = 0; j < PlayerRaces.Factions[i].size(); ++j) {
for (size_t k = 0; k < GrandStrategyGame.AvailableEvents.size(); ++k) {
CclCommand("EventFaction = GetFactionFromName(\"" + PlayerRaces.Factions[i][j]->Name + "\");");
if (GrandStrategyGame.AvailableEvents[k]->CanTrigger(GrandStrategyGame.Factions[i][j])) {
GrandStrategyGame.AvailableEvents[k]->Trigger(GrandStrategyGame.Factions[i][j]);
if (GrandStrategyGame.Factions[i][j]->IsAlive()) {
for (size_t k = 0; k < GrandStrategyGame.AvailableEvents.size(); ++k) {
CclCommand("EventFaction = GetFactionFromName(\"" + PlayerRaces.Factions[i][j]->Name + "\");");
if (GrandStrategyGame.AvailableEvents[k]->CanTrigger(GrandStrategyGame.Factions[i][j])) {
GrandStrategyGame.AvailableEvents[k]->Trigger(GrandStrategyGame.Factions[i][j]);
}
}
}
}
Expand Down Expand Up @@ -3324,6 +3326,30 @@ bool CGrandStrategyProvince::HasModifier(CUpgrade *modifier)
return std::find(this->Modifiers.begin(), this->Modifiers.end(), modifier) != this->Modifiers.end();
}

bool CGrandStrategyProvince::BordersModifier(CUpgrade *modifier)
{
//see if any provinces bordering this one have the modifier (count provinces reachable through water as well)

for (size_t i = 0; i < this->BorderProvinces.size(); ++i) {
CGrandStrategyProvince *border_province = this->BorderProvinces[i];
if (border_province->HasModifier(modifier)) {
return true;
}
}

for (size_t i = 0; i < this->LandProvincesReachableThroughWater.size(); ++i) {
CGrandStrategyProvince *border_province = this->LandProvincesReachableThroughWater[i];
if (this->HasBuildingClass("dock") == false || border_province->HasBuildingClass("dock") == false) {
continue;
}
if (border_province->HasModifier(modifier)) {
return true;
}
}

return false;
}

bool CGrandStrategyProvince::HasFactionClaim(int civilization_id, int faction_id)
{
for (size_t i = 0; i < this->Claims.size(); ++i) {
Expand Down Expand Up @@ -5377,6 +5403,8 @@ CGrandStrategyEvent::~CGrandStrategyEvent()

void CGrandStrategyEvent::Trigger(CGrandStrategyFaction *faction)
{
// fprintf(stderr, "Triggering event \"%s\" for faction %s.\n", this->Name.c_str(), PlayerRaces.Factions[faction->Civilization][faction->Faction]->Name.c_str());

CclCommand("EventFaction = GetFactionFromName(\"" + PlayerRaces.Factions[faction->Civilization][faction->Faction]->Name + "\");");
CclCommand("GrandStrategyEvent(EventFaction, \"" + this->Name + "\");");
CclCommand("EventFaction = nil;");
Expand All @@ -5390,6 +5418,8 @@ void CGrandStrategyEvent::Trigger(CGrandStrategyFaction *faction)

bool CGrandStrategyEvent::CanTrigger(CGrandStrategyFaction *faction)
{
// fprintf(stderr, "Checking for triggers for event \"%s\" for faction %s.\n", this->Name.c_str(), PlayerRaces.Factions[faction->Civilization][faction->Faction]->Name.c_str());

if (this->MinYear && GrandStrategyYear < this->MinYear) {
return false;
}
Expand Down Expand Up @@ -5737,7 +5767,7 @@ void SetWorldMapTileRiver(int x, int y, std::string direction_name, std::string

int river_id = GetRiverId(river_name);

return; //deactivate this for now, while there aren't proper graphics for the rivers
// return; //deactivate this for now, while there aren't proper graphics for the rivers

if (direction_name == "north") {
GrandStrategyGame.WorldMapTiles[x][y]->River[North] = river_id;
Expand Down Expand Up @@ -5826,7 +5856,7 @@ void SetWorldMapTileRiverhead(int x, int y, std::string direction_name, std::str

int river_id = GetRiverId(river_name);

return; //deactivate this for now, while there aren't proper graphics for the rivers
// return; //deactivate this for now, while there aren't proper graphics for the rivers

if (direction_name == "north") {
GrandStrategyGame.WorldMapTiles[x][y]->River[North] = river_id;
Expand Down
10 changes: 10 additions & 0 deletions src/stratagus/script_grand_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ static int CclGetGrandStrategyProvinceData(lua_State *l)
lua_rawseti(l, -2, i);
}
return 1;
} else if (!strcmp(data, "BordersModifier")) {
LuaCheckArgs(l, 3);

CUpgrade *modifier = CUpgrade::Get(LuaToString(l, 3));
if (modifier == NULL) {
LuaError(l, "Modifier doesn't exist.");
}

lua_pushboolean(l, province->BordersModifier(modifier));
return 1;
} else if (!strcmp(data, "Governor")) {
if (province->Governor != NULL) {
lua_pushstring(l, province->Governor->GetFullName().c_str());
Expand Down

0 comments on commit 82e851b

Please sign in to comment.