Skip to content

Commit

Permalink
add check for sailing into the barrier areas
Browse files Browse the repository at this point in the history
  • Loading branch information
jt-traub committed Aug 13, 2024
1 parent b84665e commit 1ca21b1
Show file tree
Hide file tree
Showing 42 changed files with 414 additions and 196 deletions.
9 changes: 5 additions & 4 deletions aregion.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ class TerrainType
int similar_type;

enum {
RIDINGMOUNTS = 0x1,
FLYINGMOUNTS = 0x2,
BARREN = 0x4,
SHOW_RULES = 0x8,
RIDINGMOUNTS = 0x1,
FLYINGMOUNTS = 0x2,
BARREN = 0x4,
SHOW_RULES = 0x8,
ANNIHILATED = 0x10,
};
int flags;

Expand Down
14 changes: 7 additions & 7 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,13 @@ void Game::WriteReport()
&& (Globals->UNDERWORLD_LEVELS + Globals->UNDERDEEP_LEVELS > 1);
fac->build_json_report(json_report, this, citems);

if (Globals->REPORT_FORMAT & GameDefs::REPORT_FORMAT_JSON) {
ofstream jsonf(report_file + ".json", ios::out | ios::ate);
if (jsonf.is_open()) {
jsonf << json_report.dump(2);
}
}

if (Globals->REPORT_FORMAT & GameDefs::REPORT_FORMAT_TEXT) {
TextReportGenerator text_report;
ofstream f(report_file, ios::out | ios::ate);
Expand All @@ -1303,13 +1310,6 @@ void Game::WriteReport()
}
}
}

if (Globals->REPORT_FORMAT & GameDefs::REPORT_FORMAT_JSON) {
ofstream jsonf(report_file + ".json", ios::out | ios::ate);
if (jsonf.is_open()) {
jsonf << json_report.dump(2);
}
}
}
Adot();
}
Expand Down
1 change: 1 addition & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ class Game
AList *CanSeeSteal(ARegion *, Unit *);
void Do1Steal(ARegion *, Object *, Unit *);
void Do1Assassinate(ARegion *, Object *, Unit *);
void Do1Annihilate(ARegion *reg);
void AdjustCityMons(ARegion *pReg);
void AdjustCityMon(ARegion *pReg, Unit *u);

Expand Down
12 changes: 6 additions & 6 deletions genrules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3729,12 +3729,12 @@ int Game::GenRules(const AString &rules, const AString &css, const AString &intr
f << anchor("annihilate") << '\n';
f << enclose("h4", true) << "ANNIHILATE REGION [x] [y] [z]\n" << enclose("h4", false);
f << enclose("p", true) << "Annihilate a region and the neighboring regions. An annihilated region will be "
<< "converted into barren land, and all structures and units in the regions will be destroyed. The "
<< "neighboring regions will also be annihilated. The region to be annihilated must be specified by "
<< "coordinates. If the Z coordinate is not specified, it is assumed to be on the same level as the "
<< "unit issuing the order. This order may only be issued by a unit which has access to the "
<< "ANNIHILATE [ANNI] skill. This skill cannot target regions which are already barren, nor can it "
<< "target the Nexus.\n";
<< "converted into barren land, and all units and all structures except for shafts and anomalies in the "
<< "regions will be destroyed. The neighboring regions will also be annihilated. The region to be "
<< "annihilated must be specified by coordinates. If the Z coordinate is not specified, it is assumed "
<< "to be on the same level as the unit issuing the order. This order may only be issued by a unit which "
<< "has access to the ANNIHILATE [ANNI] skill. This skill cannot target or affect regions which are "
<< "already barren, nor can it target the Nexus.\n";
f << enclose("p", false);
f << enclose("p", true) << "Example:\n" << enclose("p", false);
f << example_start("Annihilate the region located at coordinates <5, 5> on the surface.")
Expand Down
24 changes: 24 additions & 0 deletions monthorders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,30 @@ Location *Game::Do1SailOrder(ARegion *reg, Object *fleet, Unit *cap)
stop = 1;
}

// Check the new region for barriers and the fleet units for keys to the barriers
int needed_key = -1;
forlist_reuse(&newreg->objects) {
Object *o = (Object *) elem;
if (ObjectDefs[o->type].flags & ObjectType::KEYBARRIER) {
needed_key = ObjectDefs[o->type].key_item;
}
}
if (needed_key != -1) { // we found a barrier
bool has_key = false;
forlist_reuse(&fleet->units) {
Unit *u = (Unit *) elem;
if (u->items.GetNum(needed_key) > 0) {
has_key = true;
break;
}
}
if (!has_key) {
cap->error("SAIL: Can't sail " + DirectionStrs[x->dir] + " from " +
reg->ShortPrint(&regions).const_str() + " due to mystical barrier.");
stop = 1;
}
}

if (!stop) {
fleet->movepoints -= cost * Globals->MAX_SPEED;
if (x->dir != MOVE_PAUSE) {
Expand Down
21 changes: 19 additions & 2 deletions runorders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3102,12 +3102,12 @@ void Game::CheckTransportOrders()
bool target_has_qm_skill = tar->unit->GetSkill(S_QUARTERMASTER) > 0;
bool sender_owns_qm_building = (
u == obj->GetOwner() &&
obj->incomplete == 0 &&
!(obj->incomplete > 0) &&
(ObjectDefs[obj->type].flags & ObjectType::TRANSPORT)
);
bool target_owns_qm_building = (
tar->unit == tar->obj->GetOwner() &&
tar->obj->incomplete == 0 &&
!(tar->obj->incomplete > 0) &&
(ObjectDefs[tar->obj->type].flags & ObjectType::TRANSPORT)
);

Expand Down Expand Up @@ -3326,3 +3326,20 @@ void Game::RunTransportPhase(TransportOrder::TransportPhase phase) {
}
}
}

void Game::RunSacrificeOrders() {
// Check all units for sacrifice orders. Only allow a sacrifice if there is an object in the hex which accepts
// the item they are sacrificing. If the sacrifice is successful, the item(s) are removed and the object is
// destroyed/transformed/provides a reward as appropriate.
}

void Game::Do1Annihilate(ARegion *reg) {
// converts the type of the region to a barren type (either wasteland or barren ocean). When a region is
// annihilated all units, and any city/markets/production in the region are destroyed. Shafts and anomalies are
// unaffected.
}

void Game::RunAnnihilateOrders() {
// Check all units for annihilate orders. A unit my only annihilate if they have access to the annihilate skill.
// Annihilate will destroy the target hex and all surrounding hexes. Barren regions cannot be annihilated.
}
12 changes: 6 additions & 6 deletions skillshows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,12 +1465,12 @@ AString *ShowSkill::Report(Faction *f) const
if (level > 1) break;
*str += "A unit with access to the Annihilation skill may destroy a region and all "
"surrounding regions. Regions destroyed in this way will become barren. All units "
"and structures in the region and the surrounding regions will be destroyed as will "
"production and cities. This skill is only available to the unit which controls the "
"World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith "
"must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not "
"specified, it will default to the same z coordinate as the region containing the "
"World-breaker Monolith.";
"and structures except for shafts and anomalies in the region and the surrounding regions "
"will be destroyed as will production and cities. This skill is only available to the unit "
"which controls the World-breaker Monolith. To use this skill, the owner of the "
"World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z "
"coordinate is not specified, it will default to the same z coordinate as the region "
"containing the World-breaker Monolith.";
break;
}

Expand Down
19 changes: 10 additions & 9 deletions snapshot-tests/neworigins_turns/turn_0/report.1
Original file line number Diff line number Diff line change
Expand Up @@ -1729,15 +1729,16 @@ transmutation [TRNS] 5: At this level the mage may transmute 2 horses

annihilation [ANNI] 1: A unit with access to the Annihilation skill
may destroy a region and all surrounding regions. Regions destroyed
in this way will become barren. All units and structures in the
region and the surrounding regions will be destroyed as will
production and cities. This skill is only available to the unit
which controls the World-breaker Monolith. To use this skill, the
owner of the World-breaker Monolith must issue the order ANNIHILATE
REGION <x> <y> <z>. If the z coordinate is not specified, it will
default to the same z coordinate as the region containing the
World-breaker Monolith. This skill cannot be studied via normal
means. This skill cannot be taught to other units.
in this way will become barren. All units and structures except for
shafts and anomalies in the region and the surrounding regions will
be destroyed as will production and cities. This skill is only
available to the unit which controls the World-breaker Monolith. To
use this skill, the owner of the World-breaker Monolith must issue
the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is
not specified, it will default to the same z coordinate as the
region containing the World-breaker Monolith. This skill cannot be
studied via normal means. This skill cannot be taught to other
units.

annihilation [ANNI] 2: This skill cannot be studied via normal means.
This skill cannot be taught to other units.
Expand Down
2 changes: 1 addition & 1 deletion snapshot-tests/neworigins_turns/turn_0/report.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -25874,7 +25874,7 @@
"tag": "TRNS"
},
{
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures except for shafts and anomalies in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"level": 1,
"name": "annihilation",
"tag": "ANNI"
Expand Down
19 changes: 10 additions & 9 deletions snapshot-tests/neworigins_turns/turn_1/report.1
Original file line number Diff line number Diff line change
Expand Up @@ -1729,15 +1729,16 @@ transmutation [TRNS] 5: At this level the mage may transmute 2 horses

annihilation [ANNI] 1: A unit with access to the Annihilation skill
may destroy a region and all surrounding regions. Regions destroyed
in this way will become barren. All units and structures in the
region and the surrounding regions will be destroyed as will
production and cities. This skill is only available to the unit
which controls the World-breaker Monolith. To use this skill, the
owner of the World-breaker Monolith must issue the order ANNIHILATE
REGION <x> <y> <z>. If the z coordinate is not specified, it will
default to the same z coordinate as the region containing the
World-breaker Monolith. This skill cannot be studied via normal
means. This skill cannot be taught to other units.
in this way will become barren. All units and structures except for
shafts and anomalies in the region and the surrounding regions will
be destroyed as will production and cities. This skill is only
available to the unit which controls the World-breaker Monolith. To
use this skill, the owner of the World-breaker Monolith must issue
the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is
not specified, it will default to the same z coordinate as the
region containing the World-breaker Monolith. This skill cannot be
studied via normal means. This skill cannot be taught to other
units.

annihilation [ANNI] 2: This skill cannot be studied via normal means.
This skill cannot be taught to other units.
Expand Down
2 changes: 1 addition & 1 deletion snapshot-tests/neworigins_turns/turn_1/report.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -25917,7 +25917,7 @@
"tag": "TRNS"
},
{
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures except for shafts and anomalies in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"level": 1,
"name": "annihilation",
"tag": "ANNI"
Expand Down
19 changes: 10 additions & 9 deletions snapshot-tests/neworigins_turns/turn_10/report.1
Original file line number Diff line number Diff line change
Expand Up @@ -1729,15 +1729,16 @@ transmutation [TRNS] 5: At this level the mage may transmute 2 horses

annihilation [ANNI] 1: A unit with access to the Annihilation skill
may destroy a region and all surrounding regions. Regions destroyed
in this way will become barren. All units and structures in the
region and the surrounding regions will be destroyed as will
production and cities. This skill is only available to the unit
which controls the World-breaker Monolith. To use this skill, the
owner of the World-breaker Monolith must issue the order ANNIHILATE
REGION <x> <y> <z>. If the z coordinate is not specified, it will
default to the same z coordinate as the region containing the
World-breaker Monolith. This skill cannot be studied via normal
means. This skill cannot be taught to other units.
in this way will become barren. All units and structures except for
shafts and anomalies in the region and the surrounding regions will
be destroyed as will production and cities. This skill is only
available to the unit which controls the World-breaker Monolith. To
use this skill, the owner of the World-breaker Monolith must issue
the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is
not specified, it will default to the same z coordinate as the
region containing the World-breaker Monolith. This skill cannot be
studied via normal means. This skill cannot be taught to other
units.

annihilation [ANNI] 2: This skill cannot be studied via normal means.
This skill cannot be taught to other units.
Expand Down
2 changes: 1 addition & 1 deletion snapshot-tests/neworigins_turns/turn_10/report.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -26311,7 +26311,7 @@
"tag": "TRNS"
},
{
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures except for shafts and anomalies in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"level": 1,
"name": "annihilation",
"tag": "ANNI"
Expand Down
19 changes: 10 additions & 9 deletions snapshot-tests/neworigins_turns/turn_11/report.1
Original file line number Diff line number Diff line change
Expand Up @@ -1729,15 +1729,16 @@ transmutation [TRNS] 5: At this level the mage may transmute 2 horses

annihilation [ANNI] 1: A unit with access to the Annihilation skill
may destroy a region and all surrounding regions. Regions destroyed
in this way will become barren. All units and structures in the
region and the surrounding regions will be destroyed as will
production and cities. This skill is only available to the unit
which controls the World-breaker Monolith. To use this skill, the
owner of the World-breaker Monolith must issue the order ANNIHILATE
REGION <x> <y> <z>. If the z coordinate is not specified, it will
default to the same z coordinate as the region containing the
World-breaker Monolith. This skill cannot be studied via normal
means. This skill cannot be taught to other units.
in this way will become barren. All units and structures except for
shafts and anomalies in the region and the surrounding regions will
be destroyed as will production and cities. This skill is only
available to the unit which controls the World-breaker Monolith. To
use this skill, the owner of the World-breaker Monolith must issue
the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is
not specified, it will default to the same z coordinate as the
region containing the World-breaker Monolith. This skill cannot be
studied via normal means. This skill cannot be taught to other
units.

annihilation [ANNI] 2: This skill cannot be studied via normal means.
This skill cannot be taught to other units.
Expand Down
2 changes: 1 addition & 1 deletion snapshot-tests/neworigins_turns/turn_11/report.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -26446,7 +26446,7 @@
"tag": "TRNS"
},
{
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"description": "A unit with access to the Annihilation skill may destroy a region and all surrounding regions. Regions destroyed in this way will become barren. All units and structures except for shafts and anomalies in the region and the surrounding regions will be destroyed as will production and cities. This skill is only available to the unit which controls the World-breaker Monolith. To use this skill, the owner of the World-breaker Monolith must issue the order ANNIHILATE REGION <x> <y> <z>. If the z coordinate is not specified, it will default to the same z coordinate as the region containing the World-breaker Monolith. This skill cannot be studied via normal means. This skill cannot be taught to other units.",
"level": 1,
"name": "annihilation",
"tag": "ANNI"
Expand Down
Loading

0 comments on commit 1ca21b1

Please sign in to comment.