2020-12-31 07:32:16 -08:00
|
|
|
// Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
|
2012-09-23 23:35:18 -07:00
|
|
|
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
|
|
|
|
|
2012-09-12 04:46:27 -07:00
|
|
|
#ifndef _FACTIONS_H
|
|
|
|
#define _FACTIONS_H
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "DeleteEmitter.h"
|
|
|
|
#include "Polit.h"
|
|
|
|
#include "fixed.h"
|
2014-07-15 18:41:44 -07:00
|
|
|
#include "galaxy/Economy.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "galaxy/Sector.h"
|
2012-09-12 04:46:27 -07:00
|
|
|
#include "galaxy/StarSystem.h"
|
|
|
|
#include "vector3.h"
|
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
2019-01-02 08:59:07 -08:00
|
|
|
#include <vector>
|
2012-09-12 04:46:27 -07:00
|
|
|
|
2014-04-26 09:41:15 -07:00
|
|
|
class Galaxy;
|
2014-04-17 10:45:59 -07:00
|
|
|
class CustomSystem;
|
|
|
|
|
2012-10-27 15:45:21 -07:00
|
|
|
class Faction : public DeleteEmitter {
|
2014-04-26 09:41:15 -07:00
|
|
|
friend class FactionsDatabase;
|
2019-01-02 08:59:07 -08:00
|
|
|
|
2012-09-12 04:46:27 -07:00
|
|
|
public:
|
2020-03-18 16:37:32 -07:00
|
|
|
static const Uint32 BAD_FACTION_IDX; // used by the no faction object to denote it's not a proper faction
|
2019-01-02 08:59:07 -08:00
|
|
|
static const Color BAD_FACTION_COLOUR; // factionColour to use on failing to find an appropriate faction
|
|
|
|
static const float FACTION_BASE_ALPHA; // Alpha to use on factionColour of systems with unknown population
|
2012-11-26 02:40:23 -08:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
Faction(Galaxy *galaxy);
|
2012-09-12 04:46:27 -07:00
|
|
|
|
2020-03-18 16:37:32 -07:00
|
|
|
Uint32 idx; // faction index
|
|
|
|
std::string name; // Formal name "Federation", "Empire", "Bob's Rib-shack consortium of delicious worlds (tm)", etc.
|
2019-01-02 08:59:07 -08:00
|
|
|
std::string description_short; // short description
|
2020-03-18 16:37:32 -07:00
|
|
|
std::string description; // detailed description describing formation, current status, etc
|
2012-11-26 02:40:23 -08:00
|
|
|
|
|
|
|
// government types with weighting
|
2012-11-21 15:48:01 -08:00
|
|
|
typedef std::pair<Polit::GovType, Sint32> GovWeight;
|
2019-01-02 08:59:07 -08:00
|
|
|
typedef std::vector<GovWeight> GovWeightVec;
|
|
|
|
typedef GovWeightVec::const_iterator GovWeightIterator;
|
|
|
|
GovWeightVec govtype_weights;
|
|
|
|
Sint32 govtype_weights_total;
|
|
|
|
|
|
|
|
bool hasHomeworld;
|
2020-03-18 16:37:32 -07:00
|
|
|
SystemPath homeworld; // sector(x,y,x) + system index + body index = location in a (custom?) system of homeworld
|
|
|
|
double foundingDate; // date faction came into existence
|
|
|
|
double expansionRate; // lightyears per year that the volume expands.
|
2019-01-02 08:59:07 -08:00
|
|
|
std::string military_name; // "Space Defense Force", "Imperial Will Enforcement Division"...
|
2012-09-12 04:46:27 -07:00
|
|
|
//military logo
|
2019-01-02 08:59:07 -08:00
|
|
|
std::string police_name; // "Police", "Polizia Locale"...
|
|
|
|
std::string police_ship; // "kanara", "varada"...
|
2012-09-12 04:46:27 -07:00
|
|
|
//police logo
|
|
|
|
//goods/equipment availability (1-per-economy-type: aka agricultural, industrial, tourist, etc)
|
2012-11-26 02:40:23 -08:00
|
|
|
|
2018-01-05 15:05:10 -08:00
|
|
|
typedef std::vector<SystemPath> ClaimList;
|
2019-01-02 08:59:07 -08:00
|
|
|
ClaimList m_ownedsystemlist;
|
2018-01-05 15:05:10 -08:00
|
|
|
void PushClaim(SystemPath path) { m_ownedsystemlist.push_back(path); }
|
|
|
|
bool IsClaimed(SystemPath) const;
|
|
|
|
|
2014-07-15 18:41:44 -07:00
|
|
|
// commodity legality
|
2020-03-18 16:37:32 -07:00
|
|
|
typedef std::map<GalacticEconomy::CommodityId, Uint32> CommodityProbMap;
|
2019-01-02 08:59:07 -08:00
|
|
|
CommodityProbMap commodity_legality;
|
2012-11-26 02:40:23 -08:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
Color colour;
|
2012-10-31 03:25:48 -07:00
|
|
|
|
2020-04-24 15:33:07 -07:00
|
|
|
double Radius() const { return (FACTION_CURRENT_YEAR - foundingDate) * expansionRate; };
|
|
|
|
bool IsValid() const { return idx != BAD_FACTION_IDX; };
|
|
|
|
Color AdjustedColour(fixed population, bool inRange) const;
|
|
|
|
Polit::GovType PickGovType(Random &rand) const;
|
2012-10-25 00:55:00 -07:00
|
|
|
|
2012-11-12 16:50:59 -08:00
|
|
|
// set the homeworld to one near the supplied co-ordinates
|
2012-12-22 03:02:32 -08:00
|
|
|
void SetBestFitHomeworld(Sint32 x, Sint32 y, Sint32 z, Sint32 si, Uint32 bi, Sint32 axisChange);
|
2014-09-10 15:11:14 -07:00
|
|
|
RefCountedPtr<const Sector> GetHomeSector() const;
|
2012-11-24 07:46:17 -08:00
|
|
|
|
2012-10-31 03:25:48 -07:00
|
|
|
private:
|
2019-01-02 08:59:07 -08:00
|
|
|
static const double FACTION_CURRENT_YEAR; // used to calculate faction radius
|
2012-11-01 13:18:45 -07:00
|
|
|
|
2020-03-18 16:37:32 -07:00
|
|
|
Galaxy *const m_galaxy; // galaxy we are part of
|
2019-01-02 08:59:07 -08:00
|
|
|
mutable RefCountedPtr<const Sector> m_homesector; // cache of home sector to use in distance calculations
|
2020-04-24 15:33:07 -07:00
|
|
|
bool IsCloserAndContains(double &closestFactionDist, const Sector::System *sys) const;
|
2012-09-12 04:46:27 -07:00
|
|
|
};
|
|
|
|
|
2012-11-28 03:29:09 -08:00
|
|
|
/* One day it might grow up to become a full tree, on the other hand it might be
|
2012-11-27 14:13:38 -08:00
|
|
|
cut down before it's full growth to be replaced by
|
|
|
|
a proper spatial data structure.
|
|
|
|
*/
|
|
|
|
|
2014-04-26 09:41:15 -07:00
|
|
|
class FactionsDatabase {
|
2012-11-27 14:13:38 -08:00
|
|
|
public:
|
2019-01-02 08:59:07 -08:00
|
|
|
FactionsDatabase(Galaxy *galaxy, const std::string &factionDir) :
|
|
|
|
m_galaxy(galaxy),
|
|
|
|
m_factionDirectory(factionDir),
|
|
|
|
m_no_faction(galaxy),
|
|
|
|
m_may_assign_factions(false),
|
|
|
|
m_initialized(false) {}
|
2014-04-26 09:41:15 -07:00
|
|
|
~FactionsDatabase();
|
|
|
|
|
|
|
|
void Init();
|
2014-09-29 12:06:39 -07:00
|
|
|
void PostInit();
|
2014-09-20 12:41:08 -07:00
|
|
|
void ClearCache() { ClearHomeSectors(); }
|
2014-09-10 15:11:14 -07:00
|
|
|
bool IsInitialized() const;
|
2019-01-02 08:59:07 -08:00
|
|
|
Galaxy *GetGalaxy() const { return m_galaxy; }
|
|
|
|
void RegisterCustomSystem(CustomSystem *cs, const std::string &factionName);
|
|
|
|
void AddFaction(Faction *faction);
|
2014-04-26 09:41:15 -07:00
|
|
|
|
2014-09-10 15:11:14 -07:00
|
|
|
const Faction *GetFaction(const Uint32 index) const;
|
2019-01-02 08:59:07 -08:00
|
|
|
const Faction *GetFaction(const std::string &factionName) const;
|
|
|
|
const Faction *GetNearestClaimant(const Sector::System *sys) const;
|
|
|
|
bool IsHomeSystem(const SystemPath &sysPath) const;
|
2014-04-26 09:41:15 -07:00
|
|
|
|
2020-04-24 15:33:07 -07:00
|
|
|
Uint32 GetNumFactions() const;
|
2014-04-26 09:41:15 -07:00
|
|
|
|
2014-09-10 15:11:14 -07:00
|
|
|
bool MayAssignFactions() const;
|
2012-11-27 14:13:38 -08:00
|
|
|
|
|
|
|
private:
|
2014-04-26 09:41:15 -07:00
|
|
|
class Octsapling {
|
|
|
|
public:
|
2019-01-02 08:59:07 -08:00
|
|
|
void Add(const Faction *faction);
|
|
|
|
const std::vector<const Faction *> &CandidateFactions(const Sector::System *sys) const;
|
2014-04-26 09:41:15 -07:00
|
|
|
|
|
|
|
private:
|
2019-01-02 08:59:07 -08:00
|
|
|
std::vector<const Faction *> octbox[2][2][2];
|
2020-04-24 15:33:07 -07:00
|
|
|
static int BoxIndex(Sint32 sectorIndex) { return sectorIndex < 0 ? 0 : 1; };
|
2014-04-26 09:41:15 -07:00
|
|
|
void PruneDuplicates(const int bx, const int by, const int bz);
|
|
|
|
};
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
typedef std::vector<Faction *> FactionList;
|
2014-04-26 09:41:15 -07:00
|
|
|
typedef FactionList::iterator FactionIterator;
|
2019-01-02 08:59:07 -08:00
|
|
|
typedef const std::vector<const Faction *> ConstFactionList;
|
2014-04-26 09:41:15 -07:00
|
|
|
typedef ConstFactionList::const_iterator ConstFactionIterator;
|
2019-01-02 08:59:07 -08:00
|
|
|
typedef std::map<std::string, Faction *> FactionMap;
|
|
|
|
typedef std::set<SystemPath> HomeSystemSet;
|
|
|
|
typedef std::map<std::string, std::list<CustomSystem *>> MissingFactionsMap;
|
2014-04-26 09:41:15 -07:00
|
|
|
|
2014-04-26 10:53:32 -07:00
|
|
|
void ClearHomeSectors();
|
|
|
|
void SetHomeSectors();
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
Galaxy *const m_galaxy;
|
2014-09-27 14:01:06 -07:00
|
|
|
const std::string m_factionDirectory;
|
2019-01-02 08:59:07 -08:00
|
|
|
Faction m_no_faction; // instead of answering null, we often want to answer a working faction object for no faction
|
|
|
|
FactionList m_factions;
|
|
|
|
FactionMap m_factions_byName;
|
|
|
|
HomeSystemSet m_homesystems;
|
|
|
|
Octsapling m_spatial_index;
|
|
|
|
bool m_may_assign_factions;
|
|
|
|
bool m_initialized = false;
|
2014-04-26 09:41:15 -07:00
|
|
|
MissingFactionsMap m_missingFactionsMap;
|
|
|
|
};
|
2012-11-27 14:13:38 -08:00
|
|
|
|
2012-11-28 03:29:09 -08:00
|
|
|
#endif /* _FACTIONS_H */
|