Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocationFilter: conditions, reachable, mapped, elsewhere, entered, landed #23

Draft
wants to merge 1 commit into
base: experimental
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions source/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@ void AI::Step(const PlayerInfo &player, Command &activeCommands)
bool isPresent = (it->GetSystem() == playerSystem);
bool isStranded = IsStranded(*it);
bool thisIsLaunching = (isPresent && HasDeployments(*it));

// Check if this ship's government has the authority to enforce scans & fines in this system.
if(!scanPermissions.count(gov))
scanPermissions.emplace(gov, gov && gov->CanEnforce(player, playerSystem));


if(isStranded || it->IsDisabled())
{
// Derelicts never ask for help (only the player should repair them).
Expand Down Expand Up @@ -4334,10 +4340,6 @@ void AI::UpdateStrengths(map<const Government *, int64_t> &strength, const Syste
{
const Government *gov = it->GetGovernment();

// Check if this ship's government has the authority to enforce scans & fines in this system.
if(!scanPermissions.count(gov))
scanPermissions.emplace(gov, gov && gov->CanEnforce(playerSystem));

// Only have ships update their strength estimate once per second on average.
if(!gov || it->GetSystem() != playerSystem || it->IsDisabled() || Random::Int(60))
continue;
Expand Down
14 changes: 14 additions & 0 deletions source/DistanceMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ DistanceMap::DistanceMap(const System *center, WormholeStrategy wormholeStrategy



// Find paths to the system containing the given ship. If the given
// maximum count is above zero, it is a limit on how many systems
// should be returned. If it is below zero it specifies the maximum
// distance away that paths should be found.
DistanceMap::DistanceMap(const Ship &ship, int maxCount, int maxDistance)
: center(ship.IsEnteringHyperspace() ? ship.GetTargetSystem() : ship.GetSystem()),
maxCount(maxCount), maxDistance(maxDistance)
{
if(center)
Init(&ship);
}



// If a player is given, the map will only use hyperspace paths known to the
// player; that is, one end of the path has been visited. Also, if the
// player's flagship has a jump drive, the jumps will be make use of it.
Expand Down
5 changes: 5 additions & 0 deletions source/DistanceMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class DistanceMap {
// Find paths to the given system. The optional arguments put a limit on how
// many systems will be returned and how far away they are allowed to be.
explicit DistanceMap(const System *center, int maxCount = -1, int maxDistance = -1);
// Find paths to the ship's system, restricting the travel methods to
// what is possible with that ship. The optional arguments put a limit
// on how many systems will be returned and how far away they are
// allowed to be.
explicit DistanceMap(const Ship &ship, int maxCount = -1, int maxDistance = -1);
// Find paths to the given system, potentially using wormholes, a jump drive, or both.
// Optional arguments are as above.
explicit DistanceMap(const System *center, WormholeStrategy wormholeStrategy,
Expand Down
18 changes: 10 additions & 8 deletions source/Government.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,24 +524,26 @@ bool Government::Trusts(const Government *government) const



// Returns true if this government has no enforcement restrictions, or if the
// indicated system matches at least one enforcement zone.
bool Government::CanEnforce(const System *system) const
// Returns true if this government has no enforcement restrictions for
// the given player at this system, or if the indicated system and
// player matches at least one enforcement zone.
bool Government::CanEnforce(const PlayerInfo &player, const System *system) const
{
for(const LocationFilter &filter : enforcementZones)
if(filter.Matches(system))
if(filter.Matches(system, &player))
return true;
return enforcementZones.empty();
}



// Returns true if this government has no enforcement restrictions, or if the
// indicated planet matches at least one enforcement zone.
bool Government::CanEnforce(const Planet *planet) const
// Returns true if this government has no enforcement restrictions for
// the given player, or if the indicated planet matches at least one
// enforcement zone for this player.
bool Government::CanEnforce(const PlayerInfo &player, const Planet *planet) const
{
for(const LocationFilter &filter : enforcementZones)
if(filter.Matches(planet))
if(filter.Matches(planet, &player))
return true;
return enforcementZones.empty();
}
Expand Down
4 changes: 2 additions & 2 deletions source/Government.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class Government {
bool Trusts(const Government *other) const;
// A government might not exercise the ability to perform scans or fine
// the player in every system.
bool CanEnforce(const System *system) const;
bool CanEnforce(const Planet *planet) const;
bool CanEnforce(const PlayerInfo &player, const System *system) const;
bool CanEnforce(const PlayerInfo &player, const Planet *planet) const;
// Get the conversation that will be shown if this government gives a death
// sentence to the player (for carrying highly illegal cargo).
const Conversation *DeathSentence() const;
Expand Down
2 changes: 1 addition & 1 deletion source/HailPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ HailPanel::HailPanel(PlayerInfo &player, const StellarObject *object)
// to bypass language barriers.
if(planet && player.Flagship())
for(const Mission &mission : player.Missions())
if(mission.HasClearance(planet) && mission.ClearanceMessage() != "auto"
if(mission.HasClearance(player, planet) && mission.ClearanceMessage() != "auto"
&& mission.HasFullClearance())
{
planet->Bribe();
Expand Down
Loading