Skip to content

Commit

Permalink
Merge pull request OpenApoc#1493 from ayrtondenner/issue-1481-no-alie…
Browse files Browse the repository at this point in the history
…n-containment-facility

Show "No Alien Containment Facility" window when ship with alien lands in base without alien storage
  • Loading branch information
FilmBoy84 authored Aug 29, 2024
2 parents 7066948 + e189d56 commit 00e93d0
Show file tree
Hide file tree
Showing 11 changed files with 2,229 additions and 2,119 deletions.
4 changes: 2 additions & 2 deletions game/state/city/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ void Base::destroyFacility(GameState &state, Vec2<int> pos)
}
}

bool Base::alienContainmentExists(GameState &state)
bool Base::alienContainmentExists() const
{
return state.current_base->getCapacityTotal(FacilityType::Capacity::Aliens) > 0;
return getCapacityTotal(FacilityType::Capacity::Aliens) > 0;
}

bool Base::alienContainmentIsEmpty(GameState &state)
Expand Down
2 changes: 1 addition & 1 deletion game/state/city/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Base : public StateObject<Base>, public std::enable_shared_from_this<Base>
void destroyFacility(GameState &state, Vec2<int> pos);

// Returns if an Alien Containment module exists at base
bool alienContainmentExists(GameState &state);
bool alienContainmentExists() const;

// Returns if Alien Containment capacity is empty at base
bool alienContainmentIsEmpty(GameState &state);
Expand Down
37 changes: 37 additions & 0 deletions game/state/city/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "game/state/tilemap/tileobject_projectile.h"
#include "game/state/tilemap/tileobject_shadow.h"
#include "game/state/tilemap/tileobject_vehicle.h"
#include "game/ui/general/messagebox.h"
#include "library/sp.h"
#include <glm/glm.hpp>
#include <glm/gtx/vector_angle.hpp>
Expand Down Expand Up @@ -1727,11 +1728,34 @@ StateRef<Building> Vehicle::getServiceDestination(GameState &state)
std::set<StateRef<Organisation>> suppliers;
StateRef<Building> destination;

// Only add aliens if alien containment is available at base
const auto vehicleContainsAlienLoot = cargoContainsAlienLoot();
const auto alienContainmentExists = currentBuilding->base->alienContainmentExists();

// Vehicle must be stopped from unloading alien cargo when vehicle has alien loot but base has
// no alien containment
const auto isVehicleAllowedToUnloadAlienCargo =
!(vehicleContainsAlienLoot && !alienContainmentExists);

if (!isVehicleAllowedToUnloadAlienCargo)
{
fw().pushEvent(
new GameVehicleEvent(GameEventType::VehicleWithAlienLootInBaseWithNoContainment,
{&state, shared_from_this()}));
}

// Step 01: Find first cargo destination and remove arrived cargo
for (auto it = cargo.begin(); it != cargo.end();)
{
if (it->destination == currentBuilding)
{
// Only unload alien cargo when base has alien containment
if (it->type == Cargo::Type::Bio && !isVehicleAllowedToUnloadAlienCargo)
{
it++;
continue;
}

it->arrive(state, cargoArrived, bioArrived, recoveryArrived, transferArrived,
suppliers);
it = cargo.erase(it);
Expand Down Expand Up @@ -3861,6 +3885,19 @@ const UString Vehicle::getFormattedVehicleNameForEventMessage(GameState &state)
return name;
}

const bool Vehicle::cargoContainsAlienLoot() const
{
for (const auto &cargoItem : cargo)
{
if (cargoItem.type == Cargo::Type::Bio)
{
return true;
}
}

return false;
}

Cargo::Cargo(GameState &state, StateRef<AEquipmentType> equipment, int count, int price,
StateRef<Organisation> originalOwner, StateRef<Building> destination)
: Cargo(state, equipment->bioStorage ? Type::Bio : Type::Agent, equipment.id, count,
Expand Down
2 changes: 2 additions & 0 deletions game/state/city/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ class Vehicle : public StateObject<Vehicle>,

const UString getFormattedVehicleNameForEventMessage(GameState &state) const;

const bool cargoContainsAlienLoot() const;

// Following members are not serialized, but rather setup during game

up<VehicleMover> mover;
Expand Down
4 changes: 4 additions & 0 deletions game/state/gameevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ UString GameVehicleEvent::message()
return format("%s %s", tr("Not enough ammo to rearm vehicle:"), vehicle->name);
case GameEventType::NotEnoughFuel:
return format("%s %s", tr("Not enough fuel to refuel vehicle"), vehicle->name);
case GameEventType::VehicleWithAlienLootInBaseWithNoContainment:
return format("%s %s",
tr("Vehicle landed with alien loot in base with no alien containment"),
vehicle->name);
default:
LogError("Invalid vehicle event type");
break;
Expand Down
1 change: 1 addition & 0 deletions game/state/gameeventtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum class GameEventType
UnauthorizedVehicle,
NotEnoughAmmo,
NotEnoughFuel,
VehicleWithAlienLootInBaseWithNoContainment,
// Vehicle event that starts recovery mission
UfoRecoveryBegin,

Expand Down
Loading

0 comments on commit 00e93d0

Please sign in to comment.