Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/pioneerspacesim/pioneer.git

… into PL
  • Loading branch information...
commit 6bc362941b8f0b47cf4f697b1d20b6cc83585d67 2 parents 75f90ef + 50c1ace
radius75 radius75 authored
5 Changelog.txt
View
@@ -1,12 +1,13 @@
Alpha 27
* New features
- * The settings screen is now acessible from the main menu (#1187, #1512)
- * There's now an option to enable texture compression (#1522)
+ * Factions, with custom goods illegality and colour coding (#1505)
* New mission type, Scout (get paid to scan particular planets) (#1348, #779)
* New view modes (Left/Right/Top/Bottom, Cockpit Front/Rear) (#1454, #1539, #1544)
NOTE -- view mode controls are bound to Numeric Keypad by default
(they can be rebound in the View tab of the Settings screen)
+ * The settings screen is now acessible from the main menu (#1187, #1512)
+ * There's now an option to enable texture compression (#1522)
* Minor changes and tweaks
* Smooth zoom animation in World, System, Sector and Galactic views (#1170)
10 data/factions/00_default.lua
View
@@ -0,0 +1,10 @@
+local f = Faction:new('Independent')
+ :description_short('Worlds without a group allegience')
+ :description('Free and independent worlds, self governing and either self reliant or striving for it.')
+ :foundingDate(2900.0)
+ :expansionRate(2.0)
+ :military_name('Independent Space Fleet')
+ :police_name('Police')
+ :colour(1.0,1.0,0.4)
+
+f:add_to_factions('Independent')
20 data/factions/01_federation.lua
View
@@ -0,0 +1,20 @@
+local f = Faction:new('Federation')
+ :description_short('The historical birthplace of humankind')
+ :description([[Sol is a fine joint]])
+ :govtype('EARTHDEMOC')
+ :homeworld(0,0,0,0,4)
+ :foundingDate(3050.0)
+ :expansionRate(1.0)
+ :military_name('United Nations Space Force')
+ :police_name('Police')
+ :colour(0.4,0.4,1.0)
+
+f:illegal_goods_probability('ANIMAL_MEAT',75) -- fed/cis
+f:illegal_goods_probability('LIVE_ANIMALS',75) -- fed/cis
+f:illegal_goods_probability('HAND_WEAPONS',100) -- fed
+f:illegal_goods_probability('BATTLE_WEAPONS',50) --fed/cis
+f:illegal_goods_probability('NERVE_GAS',100)--fed/cis
+f:illegal_goods_probability('NARCOTICS',100)--fed
+f:illegal_goods_probability('SLAVES',100)--fed/cis
+
+f:add_to_factions('Federation')
20 data/factions/02_CIS.lua
View
@@ -0,0 +1,20 @@
+local f = Faction:new('Confederation of Independent Systems')
+ :description_short('Socially democratic grouping of independent Star Systems')
+ :description('Socially democratic grouping of independent Star Systems, I dunno, added them because they seem hard coded into the politics.')
+ :govtype('CISSOCDEM')
+ :homeworld(6,12,0,1,3)
+ :foundingDate(3125.0)
+ :expansionRate(1.0)
+ :military_name('Confederation Fleet')
+ :police_name('Confederal Police')
+ :colour(0.4,1.0,0.4)
+
+f:illegal_goods_probability('ANIMAL_MEAT',75) -- fed/cis
+f:illegal_goods_probability('LIVE_ANIMALS',75) -- fed/cis
+f:illegal_goods_probability('HAND_WEAPONS',25) -- cis
+f:illegal_goods_probability('BATTLE_WEAPONS',50) --fed/cis
+f:illegal_goods_probability('NERVE_GAS',100)--fed/cis
+f:illegal_goods_probability('NARCOTICS',86)--cis
+f:illegal_goods_probability('SLAVES',100)--fed/cis
+
+f:add_to_factions('CIS')
19 data/factions/03_red.lua
View
@@ -0,0 +1,19 @@
+local f = Faction:new('Red')
+ :description_short('Not Blue')
+ :description('The RED team are not Blue')
+ :govtype('EMPIRERULE')
+ :homeworld(4,-9,-16,0,16)
+ :foundingDate(3150.0)
+ :expansionRate(3.0)
+ :military_name('Red Fleet')
+ :police_name('Red Right Hands')
+ :colour(1.0,0.4,0.4)
+
+f:illegal_goods_probability('LIQUOR',88) -- independent/empire
+f:illegal_goods_probability('HAND_WEAPONS',50) -- empire/etc
+f:illegal_goods_probability('BATTLE_WEAPONS',100) --empire/etc
+f:illegal_goods_probability('NERVE_GAS',90)--empire
+f:illegal_goods_probability('NARCOTICS',50)--empire
+f:illegal_goods_probability('SLAVES',94)--empire
+
+f:add_to_factions('Red')
2  data/lang/English.txt
View
@@ -1056,6 +1056,8 @@ ECONOMY_TYPE
Economy type:
ALLEGIANCE
Allegiance:
+FACTION
+ Faction:
POPULATION
Population:
OVER_N_BILLION
344 src/Factions.cpp
View
@@ -0,0 +1,344 @@
+// Copyright © 2008-2012 Pioneer Developers. See AUTHORS.txt for details
+// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
+
+#include "Factions.h"
+#include "galaxy/SystemPath.h"
+#include "galaxy/Sector.h"
+
+#include "LuaUtils.h"
+#include "LuaVector.h"
+#include "LuaFixed.h"
+#include "LuaConstants.h"
+#include "Polit.h"
+#include "FileSystem.h"
+
+typedef std::vector<Faction> FactionList;
+typedef FactionList::iterator FactionIterator;
+static FactionList s_factions;
+
+// ------- Faction --------
+
+static const char LuaFaction_TypeName[] = "Faction";
+
+static Faction **l_fac_check_ptr(lua_State *L, int idx) {
+ Faction **facptr = static_cast<Faction**>(
+ luaL_checkudata(L, idx, LuaFaction_TypeName));
+ if (!(*facptr)) {
+ luaL_argerror(L, idx, "invalid body (this body has already been used)");
+ abort();
+ }
+ return facptr;
+}
+
+static Faction *l_fac_check(lua_State *L, int idx)
+{
+ return *l_fac_check_ptr(L, idx);
+}
+
+static int l_fac_new(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 2);
+
+ Faction **facptr = static_cast<Faction**>(lua_newuserdata(L, sizeof(Faction*)));
+ *facptr = new Faction;
+ luaL_setmetatable(L, LuaFaction_TypeName);
+
+ (*facptr)->name = name;
+
+ return 1;
+}
+
+#define LFAC_FIELD_SETTER_FIXED(luaname, fieldname) \
+ static int l_fac_ ## luaname (lua_State *L) { \
+ Faction *fac = l_fac_check(L, 1); \
+ const fixed *value = LuaFixed::CheckFromLua(L, 2); \
+ fac->fieldname = *value; \
+ lua_settop(L, 1); return 1; \
+ }
+
+#define LFAC_FIELD_SETTER_FLOAT(luaname, fieldname) \
+ static int l_fac_ ## luaname (lua_State *L) { \
+ Faction *fac = l_fac_check(L, 1); \
+ double value = luaL_checknumber(L, 2); \
+ fac->fieldname = value; \
+ lua_settop(L, 1); return 1; \
+ }
+
+#define LFAC_FIELD_SETTER_INT(luaname, fieldname) \
+ static int l_fac_ ## luaname (lua_State *L) { \
+ Faction *fac = l_fac_check(L, 1); \
+ int value = luaL_checkinteger(L, 2); \
+ fac->fieldname = value; \
+ lua_settop(L, 1); return 1; \
+ }
+
+static int l_fac_description_short(lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ fac->description_short = luaL_checkstring(L, 2);
+ lua_settop(L, 1);
+ return 1;
+}
+
+static int l_fac_description(lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ fac->description = luaL_checkstring(L, 2);
+ lua_settop(L, 1);
+ return 1;
+}
+
+static int l_fac_govtype(lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ fac->govType = static_cast<Polit::GovType>(LuaConstants::GetConstantFromArg(L, "PolitGovType", 2));
+ lua_settop(L, 1);
+ return 1;
+}
+
+// sector(x,y,x) + system index + body index = location in a (custom?) system of homeworld
+static int l_fac_homeworld (lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ Sint32 x = luaL_checkinteger(L, 2);
+ Sint32 y = luaL_checkinteger(L, 3);
+ Sint32 z = luaL_checkinteger(L, 4);
+ Uint32 si = luaL_checkinteger(L, 5);
+ Uint32 bi = luaL_checkinteger(L, 6);
+ fac->homeworld = SystemPath(x,y,z,si,bi);
+ fac->hasHomeworld = true;
+ lua_settop(L, 1);
+ return 1;
+}
+
+LFAC_FIELD_SETTER_FLOAT(foundingDate, foundingDate) // date faction came into existence
+LFAC_FIELD_SETTER_FLOAT(expansionRate, expansionRate) // lightyears per year that the volume expands.
+
+static int l_fac_military_name(lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ fac->military_name = luaL_checkstring(L, 2);
+ lua_settop(L, 1);
+ return 1;
+}
+
+//military logo
+static int l_fac_police_name(lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ fac->police_name = luaL_checkstring(L, 2);
+ lua_settop(L, 1);
+ return 1;
+}
+
+//police logo
+//goods/equipment availability (1-per-economy-type: aka agricultural, industrial, tourist, etc)
+//goods/equipment legality
+static int l_fac_illegal_goods_probability(lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ const char *typeName = luaL_checkstring(L, 2);
+ const Equip::Type e = static_cast<Equip::Type>(LuaConstants::GetConstant(L, "EquipType", typeName));
+ const uint32_t probability = luaL_checkunsigned(L, 3);
+
+ if (e < Equip::FIRST_COMMODITY || e > Equip::LAST_COMMODITY) {
+ pi_lua_warn(L,
+ "argument out of range: Faction{%s}:IllegalGoodsProbability('%s', %d)",
+ fac->name.c_str(), typeName, probability);
+ return 0;
+ }
+
+ if (probability > 100) {
+ pi_lua_warn(L,
+ "argument (probability 0-100) out of range: Faction{%s}:IllegalGoodsProbability('%s', %d)",
+ fac->name.c_str(), typeName, probability);
+ return 0;
+ }
+
+ fac->equip_legality[e] = probability;
+ lua_settop(L, 1);
+
+ return 1;
+}
+
+//ship availability
+static int l_fac_colour(lua_State *L)
+{
+ Faction *fac = l_fac_check(L, 1);
+ const float r = luaL_checknumber(L, 2);
+ const float g = luaL_checknumber(L, 3);
+ const float b = luaL_checknumber(L, 4);
+
+ fac->colour = Color(r,g,b);
+
+ lua_settop(L, 1);
+
+ return 1;
+}
+
+#undef LFAC_FIELD_SETTER_FIXED
+#undef LFAC_FIELD_SETTER_FLOAT
+#undef LFAC_FIELD_SETTER_INT
+
+static int l_fac_add_to_factions(lua_State *L)
+{
+ Faction **facptr = l_fac_check_ptr(L, 1);
+
+ const std::string factionName(luaL_checkstring(L, 2));
+
+ printf("l_fac_add_to_factions: added '%s' [%s]\n", (*facptr)->name.c_str(), factionName.c_str());
+
+ s_factions.push_back(**facptr);
+
+ return 0;
+}
+
+static int l_fac_gc(lua_State *L)
+{
+ Faction **facptr = static_cast<Faction**>(
+ luaL_checkudata(L, 1, LuaFaction_TypeName));
+ delete *facptr; // does nothing if *facptr is null
+ return 0;
+}
+
+static luaL_Reg LuaFaction_meta[] = {
+ { "new", &l_fac_new },
+ { "description_short", &l_fac_description_short },
+ { "description", &l_fac_description },
+ { "govtype", &l_fac_govtype },
+ { "homeworld", &l_fac_homeworld },
+ { "foundingDate", &l_fac_foundingDate },
+ { "expansionRate", &l_fac_expansionRate },
+ { "military_name", &l_fac_military_name },
+ { "police_name", &l_fac_police_name },
+ { "illegal_goods_probability", &l_fac_illegal_goods_probability },
+ { "colour", &l_fac_colour },
+ { "add_to_factions", &l_fac_add_to_factions },
+ { "__gc", &l_fac_gc },
+ { 0, 0 }
+};
+
+// ------ Factions initialisation ------
+
+static void register_class(lua_State *L, const char *tname, luaL_Reg *meta)
+{
+ LUA_DEBUG_START(L);
+ luaL_newmetatable(L, tname);
+ luaL_setfuncs(L, meta, 0);
+
+ // map the metatable to its own __index
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "__index");
+
+ // publish the metatable
+ lua_setglobal(L, tname);
+
+ LUA_DEBUG_END(L, 0);
+}
+
+static void RegisterFactionsAPI(lua_State *L)
+{
+ register_class(L, LuaFaction_TypeName, LuaFaction_meta);
+}
+
+//static
+void Faction::Init()
+{
+ lua_State *L = luaL_newstate();
+ LUA_DEBUG_START(L);
+
+ pi_lua_open_standard_base(L);
+
+ LuaConstants::Register(L);
+
+ LUA_DEBUG_CHECK(L, 0);
+
+ RegisterFactionsAPI(L);
+
+ LUA_DEBUG_CHECK(L, 0);
+ pi_lua_dofile_recursive(L, "factions");
+
+ LUA_DEBUG_END(L, 0);
+ lua_close(L);
+
+ printf("Number of factions added: " SIZET_FMT "\n", s_factions.size());
+}
+
+void Faction::Uninit()
+{
+ s_factions.clear();
+}
+
+const Faction *Faction::GetFaction(const Uint32 index)
+{
+ assert( index < s_factions.size() );
+ return &s_factions[index];
+}
+
+const Uint32 Faction::GetNumFactions()
+{
+ return s_factions.size();
+}
+
+const Uint32 Faction::GetNearestFactionIndex(const SystemPath& sysPath)
+{
+ // Iterate through all of the factions and find the one nearest to the system we're checking it against.
+ const Faction *foundFaction = 0;
+ Sint32 nearestDistance = INT_MAX;
+
+ // get the current year
+ // XXX: cannot access the PI::game->GetTime() method here as game is NULL when deserialised from save game -
+ // - I had hoped to use this to give a simple expanding spherical volume to each faction. Use 3200 as the-
+ // - base year, all factions should have come into existence prior to this date.
+ const double current_year = 3200;//get_year(Pi::game->GetTime());
+
+ // iterate
+ Uint32 ret_index = 0;
+ for (Uint32 index = 0; index < s_factions.size(); ++index) {
+ const Faction &fac = s_factions[index];
+
+ if( !fac.hasHomeworld && !foundFaction ) {
+ // We've not yet found a faction that we're within the radius of
+ // and we're currently iterating over a faction that is decentralised (probably Independent)
+ foundFaction = &fac;
+ ret_index = index;
+ }
+
+ else if( fac.hasHomeworld ) {
+ // We can end early here if they're the same as factions homeworld like Earth or Achernar
+ if( fac.homeworld.IsSameSector(sysPath) ) {
+ foundFaction = &fac;
+ return index;
+ }
+
+ // get the distance
+ const Sector sec1(fac.homeworld.sectorX, fac.homeworld.sectorY, fac.homeworld.sectorZ);
+ const Sector sec2(sysPath.sectorX, sysPath.sectorY, sysPath.sectorZ);
+ const double distance = Sector::DistanceBetween(&sec1, fac.homeworld.systemIndex, &sec2, sysPath.systemIndex);
+
+ // calculate the current radius the faction occupies
+ const double radius = (current_year - fac.foundingDate) * fac.expansionRate;
+
+ // check we've found a closer faction
+ if( (distance <= radius) && (distance < nearestDistance) ) {
+ nearestDistance = distance;
+ foundFaction = &fac;
+ ret_index = index;
+ }
+ }
+ }
+
+ return ret_index;
+}
+
+Faction::Faction() :
+ govType(Polit::GOV_INVALID),
+ hasHomeworld(false),
+ foundingDate(0.0),
+ expansionRate(0.0)
+{
+}
+
+Faction::~Faction()
+{
+}
49 src/Factions.h
View
@@ -0,0 +1,49 @@
+// Copyright © 2008-2012 Pioneer Developers. See AUTHORS.txt for details
+// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
+
+#ifndef _FACTIONS_H
+#define _FACTIONS_H
+
+#include "galaxy/StarSystem.h"
+#include "Polit.h"
+#include "vector3.h"
+#include "fixed.h"
+#include <map>
+#include <utility>
+
+class Faction {
+public:
+ static void Init();
+ static void Uninit();
+
+ // XXX this is not as const-safe as it should be
+ static const Faction *GetFaction(const Uint32 index);
+ static const Uint32 GetNumFactions();
+ static const Uint32 GetNearestFactionIndex(const SystemPath& sysPath);
+
+ Faction();
+ ~Faction();
+
+ std::string name; // Formal name "Federation", "Empire", "Bob's Rib-shack consortium of delicious worlds (tm)", etc.
+ std::string description_short; // short description
+ std::string description; // detailed description describing formation, current status, etc
+ Polit::GovType govType;
+ bool hasHomeworld;
+ 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.
+ std::string military_name; // "Space Defense Force", "Imperial Will Enforcement Division"...
+ //military logo
+ std::string police_name; // "Police", "Polizia Locale"...
+ //police logo
+ //goods/equipment availability (1-per-economy-type: aka agricultural, industrial, tourist, etc)
+ //static const int SC_NUM_ECONOMY_TYPES = 3;
+ //EquipType types[SC_NUM_ECONOMY_TYPES][Equip::TYPE_MAX];
+ //goods/equipment legality
+ typedef std::map<Equip::Type, uint32_t> EquipProbMap;
+ EquipProbMap equip_legality;
+ //ship availability
+ Color colour;
+};
+
+#endif /* _FACTIONS_H */
1  src/LangStrings.inc.h
View
@@ -525,6 +525,7 @@ DECLARE_STRING(SYSTEM_TYPE)
DECLARE_STRING(GOVERNMENT_TYPE)
DECLARE_STRING(ECONOMY_TYPE)
DECLARE_STRING(ALLEGIANCE)
+DECLARE_STRING(FACTION)
DECLARE_STRING(POPULATION)
DECLARE_STRING(OVER_N_BILLION)
DECLARE_STRING(OVER_N_MILLION)
21 src/LuaConstants.cpp
View
@@ -286,27 +286,6 @@ void LuaConstants::Register(lua_State *l)
*/
_create_constant_table_nonconsecutive(l, "PolitCrime", ENUM_PolitCrime);
-
- /*
- * Constants: PolitBloc
- *
- * Political alignment
- *
- * NONE - independent
- * EARTHFED - Federation
- * CIS - Confederation of Independent Systems
- * EMPIRE - Empire
- *
- * Availability:
- *
- * alpha 10
- *
- * Status:
- *
- * experimental
- */
- _create_constant_table_nonconsecutive(l, "PolitBloc", ENUM_PolitBloc);
-
/*
* Constants: PolitEcon
*
2  src/Makefile.am
View
@@ -38,6 +38,7 @@ noinst_HEADERS = \
EquipSet.h \
EquipType.h \
FaceVideoLink.h \
+ Factions.h \
FileSelectorWidget.h \
FileSystem.h \
FontCache.h \
@@ -182,6 +183,7 @@ pioneer_SOURCES = \
DynamicBody.cpp \
EquipType.cpp \
FaceVideoLink.cpp \
+ Factions.cpp \
FileSelectorWidget.cpp \
FileSourceZip.cpp \
FileSystem.cpp \
4 src/Pi.cpp
View
@@ -6,6 +6,7 @@
#include "AmbientSounds.h"
#include "CargoBody.h"
#include "CityOnPlanet.h"
+#include "Factions.h"
#include "FileSystem.h"
#include "Frame.h"
#include "GalacticView.h"
@@ -340,6 +341,9 @@ void Pi::Init()
Galaxy::Init();
draw_progress(0.2f);
+ Faction::Init();
+ draw_progress(0.3f);
+
CustomSystem::Init();
draw_progress(0.4f);
153 src/Polit.cpp
View
@@ -6,6 +6,7 @@
#include "Polit.h"
#include "galaxy/StarSystem.h"
#include "galaxy/Sector.h"
+#include "Factions.h"
#include "Space.h"
#include "Ship.h"
#include "ShipCpanel.h"
@@ -21,15 +22,17 @@ namespace Polit {
static PersistSystemData<Sint64> s_criminalRecord;
static PersistSystemData<Sint64> s_outstandingFine;
struct crime_t {
+ crime_t() : record(0), fine(0) {}
Sint64 record;
Sint64 fine;
-} s_playerPerBlocCrimeRecord[BLOC_MAX];
+};
+static std::vector<crime_t> s_playerPerBlocCrimeRecord;
const char *crimeNames[64] = {
Lang::TRADING_ILLEGAL_GOODS,
Lang::UNLAWFUL_WEAPONS_DISCHARGE,
Lang::PIRACY,
- Lang::MURDER,
+ Lang::MURDER
};
// in 1/100th credits, as all money is
static const Sint64 crimeBaseFine[64] = {
@@ -38,12 +41,6 @@ static const Sint64 crimeBaseFine[64] = {
1000000,
1500000,
};
-const char *s_blocDesc[BLOC_MAX] = {
- Lang::INDEPENDENT,
- Lang::EARTH_FEDERATION,
- Lang::INDEPENDENT_CONFEDERATION,
- Lang::EMPIRE
-};
const char *s_econDesc[ECON_MAX] = {
Lang::NO_ESTABLISHED_ORDER,
Lang::HARD_CAPITALIST,
@@ -55,42 +52,56 @@ const char *s_econDesc[ECON_MAX] = {
struct politDesc_t {
const char *description;
int rarity;
- Bloc bloc;
+ Uint32 faction; // default (i.e. Invalid) is UINT_MAX
PolitEcon econ;
fixed baseLawlessness;
};
-const politDesc_t s_govDesc[GOV_MAX] = {
- { "<invalid turd>", 0, BLOC_NONE, ECON_NONE, fixed(1,1) },
- { Lang::NO_CENTRAL_GOVERNANCE, 0, BLOC_NONE, ECON_NONE, fixed(1,1) },
- { Lang::EARTH_FEDERATION_COLONIAL_RULE, 2, BLOC_EARTHFED, ECON_CAPITALIST, fixed(3,10) },
- { Lang::EARTH_FEDERATION_DEMOCRACY, 3, BLOC_EARTHFED, ECON_CAPITALIST, fixed(15,100) },
- { Lang::IMPERIAL_RULE, 3, BLOC_EMPIRE, ECON_PLANNED, fixed(15,100) },
- { Lang::LIBERAL_DEMOCRACY, 2, BLOC_CIS, ECON_CAPITALIST, fixed(25,100) },
- { Lang::SOCIAL_DEMOCRACY, 2, BLOC_CIS, ECON_MIXED, fixed(20,100) },
- { Lang::LIBERAL_DEMOCRACY, 2, BLOC_NONE, ECON_CAPITALIST, fixed(25,100) },
- { Lang::CORPORATE_SYSTEM, 2, BLOC_NONE, ECON_CAPITALIST, fixed(40,100) },
- { Lang::SOCIAL_DEMOCRACY, 2, BLOC_NONE, ECON_MIXED, fixed(25,100) },
- { Lang::MILITARY_DICTATORSHIP, 5, BLOC_EARTHFED, ECON_CAPITALIST, fixed(40,100) },
- { Lang::MILITARY_DICTATORSHIP, 6, BLOC_NONE, ECON_CAPITALIST, fixed(25,100) },
- { Lang::MILITARY_DICTATORSHIP, 6, BLOC_NONE, ECON_MIXED, fixed(25,100) },
- { Lang::MILITARY_DICTATORSHIP, 5, BLOC_EMPIRE, ECON_MIXED, fixed(40,100) },
- { Lang::COMMUNIST, 10, BLOC_NONE, ECON_PLANNED, fixed(25,100) },
- { Lang::PLUTOCRATIC_DICTATORSHIP, 4, BLOC_NONE, ECON_VERY_CAPITALIST, fixed(45,100) },
- { Lang::VIOLENT_ANARCHY, 2, BLOC_NONE, ECON_NONE, fixed(90,100) },
+static politDesc_t s_govDesc[GOV_MAX] = {
+ { "<invalid turd>", 0, UINT_MAX, ECON_NONE, fixed(1,1) },
+ { Lang::NO_CENTRAL_GOVERNANCE, 0, UINT_MAX, ECON_NONE, fixed(1,1) },
+ { Lang::EARTH_FEDERATION_COLONIAL_RULE, 2, UINT_MAX, ECON_CAPITALIST, fixed(3,10) },
+ { Lang::EARTH_FEDERATION_DEMOCRACY, 3, UINT_MAX, ECON_CAPITALIST, fixed(15,100) },
+ { Lang::IMPERIAL_RULE, 3, UINT_MAX, ECON_PLANNED, fixed(15,100) },
+ { Lang::LIBERAL_DEMOCRACY, 2, UINT_MAX, ECON_CAPITALIST, fixed(25,100) },
+ { Lang::SOCIAL_DEMOCRACY, 2, UINT_MAX, ECON_MIXED, fixed(20,100) },
+ { Lang::LIBERAL_DEMOCRACY, 2, UINT_MAX, ECON_CAPITALIST, fixed(25,100) },
+ { Lang::CORPORATE_SYSTEM, 2, UINT_MAX, ECON_CAPITALIST, fixed(40,100) },
+ { Lang::SOCIAL_DEMOCRACY, 2, UINT_MAX, ECON_MIXED, fixed(25,100) },
+ { Lang::MILITARY_DICTATORSHIP, 5, UINT_MAX, ECON_CAPITALIST, fixed(40,100) },
+ { Lang::MILITARY_DICTATORSHIP, 6, UINT_MAX, ECON_CAPITALIST, fixed(25,100) },
+ { Lang::MILITARY_DICTATORSHIP, 6, UINT_MAX, ECON_MIXED, fixed(25,100) },
+ { Lang::MILITARY_DICTATORSHIP, 5, UINT_MAX, ECON_MIXED, fixed(40,100) },
+ { Lang::COMMUNIST, 10, UINT_MAX, ECON_PLANNED, fixed(25,100) },
+ { Lang::PLUTOCRATIC_DICTATORSHIP, 4, UINT_MAX, ECON_VERY_CAPITALIST, fixed(45,100) },
+ { Lang::VIOLENT_ANARCHY, 2, UINT_MAX, ECON_NONE, fixed(90,100) },
};
void Init()
{
s_criminalRecord.Clear();
s_outstandingFine.Clear();
- memset(s_playerPerBlocCrimeRecord, 0, sizeof(crime_t)*BLOC_MAX);
+
+ // setup the per faction criminal records
+ const Uint32 numFactions = Faction::GetNumFactions();
+ s_playerPerBlocCrimeRecord.clear();
+ s_playerPerBlocCrimeRecord.resize( numFactions );
+
+ // now setup the faction links, hopefully.
+ for (Uint32 i=0; i<numFactions; i++) {
+ const Faction *fac = Faction::GetFaction(i);
+ if( fac ) {
+ s_govDesc[ fac->govType ].faction = i;
+ }
+ }
+
}
void Serialize(Serializer::Writer &wr)
{
s_criminalRecord.Serialize(wr);
s_outstandingFine.Serialize(wr);
- for (int i=0; i<BLOC_MAX; i++) {
+ wr.Int32(s_playerPerBlocCrimeRecord.size());
+ for (Uint32 i=0; i < s_playerPerBlocCrimeRecord.size(); i++) {
wr.Int64(s_playerPerBlocCrimeRecord[i].record);
wr.Int64(s_playerPerBlocCrimeRecord[i].fine);
}
@@ -101,7 +112,9 @@ void Unserialize(Serializer::Reader &rd)
Init();
PersistSystemData<Sint64>::Unserialize(rd, &s_criminalRecord);
PersistSystemData<Sint64>::Unserialize(rd, &s_outstandingFine);
- for (int i=0; i<BLOC_MAX; i++) {
+ const Uint32 numFactions = rd.Int32();
+ assert(s_playerPerBlocCrimeRecord.size() == numFactions);
+ for (Uint32 i=0; i < numFactions; i++) {
s_playerPerBlocCrimeRecord[i].record = rd.Int64();
s_playerPerBlocCrimeRecord[i].fine = rd.Int64();
}
@@ -146,8 +159,8 @@ void AddCrime(Sint64 crimeBitset, Sint64 addFine)
{
int politType = Pi::game->GetSpace()->GetStarSystem()->GetSysPolit().govType;
- if (s_govDesc[politType].bloc != BLOC_NONE) {
- const Bloc b = s_govDesc[politType].bloc;
+ if (s_govDesc[politType].faction != UINT_MAX) {
+ const Uint32 b = s_govDesc[politType].faction;
s_playerPerBlocCrimeRecord[b].record |= crimeBitset;
s_playerPerBlocCrimeRecord[b].fine += addFine;
} else {
@@ -170,8 +183,8 @@ void GetCrime(Sint64 *crimeBitset, Sint64 *fine)
int politType = Pi::game->GetSpace()->GetStarSystem()->GetSysPolit().govType;
- if (s_govDesc[politType].bloc != BLOC_NONE) {
- const Bloc b = s_govDesc[politType].bloc;
+ if (s_govDesc[politType].faction != UINT_MAX) {
+ const Uint32 b = s_govDesc[politType].faction;
*crimeBitset = s_playerPerBlocCrimeRecord[b].record;
*fine = s_playerPerBlocCrimeRecord[b].fine;
} else {
@@ -202,7 +215,14 @@ void GetSysPolitStarSystem(const StarSystem *s, const fixed human_infestedness,
if (path == SystemPath(0,0,0,0)) {
a = Polit::GOV_EARTHDEMOC;
} else if (human_infestedness > 0) {
- a = static_cast<GovType>(rand.Int32(GOV_RAND_MIN, GOV_RAND_MAX));
+ const Faction *fac = Faction::GetFaction( s->GetFactionIndex() );
+ if( fac && fac->govType != GOV_INVALID) {
+ // found valid faction
+ a = fac->govType;
+ } else {
+ // found an invalid faction, meaning index 0 and thus independent, pick something at random
+ a = static_cast<GovType>(rand.Int32(GOV_RAND_MIN, GOV_RAND_MAX));
+ }
} else {
a = GOV_NONE;
}
@@ -214,44 +234,43 @@ void GetSysPolitStarSystem(const StarSystem *s, const fixed human_infestedness,
#define POLIT_SALT 0x8732abdf
-bool IsCommodityLegal(const StarSystem *s, Equip::Type t)
+bool IsCommodityLegal(const StarSystem *s, const Equip::Type t)
{
SystemPath path = s->GetPath();
const unsigned long _init[5] = { Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), path.systemIndex, POLIT_SALT };
MTRand rand(_init, 5);
Polit::GovType a = s->GetSysPolit().govType;
- const Bloc b = s_govDesc[a].bloc;
-
if (a == GOV_NONE) return true;
- switch (t) {
- case Equip::ANIMAL_MEAT:
- case Equip::LIVE_ANIMALS:
- if ((b == BLOC_EARTHFED) || (b == BLOC_CIS)) return rand.Int32(4)!=0;
- else return true;
- case Equip::LIQUOR:
- if ((b != BLOC_EARTHFED) && (b != BLOC_CIS)) return rand.Int32(8)!=0;
- else return true;
- case Equip::HAND_WEAPONS:
- if (b == BLOC_EARTHFED) return false;
- if (b == BLOC_CIS) return rand.Int32(3)!=0;
- else return rand.Int32(2) == 0;
- case Equip::BATTLE_WEAPONS:
- if ((b != BLOC_EARTHFED) && (b != BLOC_CIS)) return rand.Int32(3)==0;
- return false;
- case Equip::NERVE_GAS:
- if ((b != BLOC_EARTHFED) && (b != BLOC_CIS)) return rand.Int32(10)==0;
- return false;
- case Equip::NARCOTICS:
- if (b == BLOC_EARTHFED) return false;
- if (b == BLOC_CIS) return rand.Int32(7)==0;
- else return rand.Int32(2)==0;
- case Equip::SLAVES:
- if ((b != BLOC_EARTHFED) && (b != BLOC_CIS)) return rand.Int32(16)==0;
- return false;
- default: return true;
+ const Uint32 b = s_govDesc[a].faction;
+ if( b != UINT_MAX ) {
+ const Faction *fac = Faction::GetFaction( b );
+ assert(fac);
+ Faction::EquipProbMap::const_iterator iter = fac->equip_legality.find(t);
+ if( iter != fac->equip_legality.end() ) {
+ const uint32_t per = (*iter).second;
+ return (rand.Int32(100) >= per);
+ }
+ }
+ else
+ {
+ // this is a non-faction system - do some hardcoded test
+ switch (t) {
+ case Equip::HAND_WEAPONS:
+ return rand.Int32(2) == 0;
+ case Equip::BATTLE_WEAPONS:
+ return rand.Int32(3) == 0;
+ case Equip::NERVE_GAS:
+ return rand.Int32(10) == 0;
+ case Equip::NARCOTICS:
+ return rand.Int32(2) == 0;
+ case Equip::SLAVES:
+ return rand.Int32(16) == 0;
+ default: return true;
+ }
}
+ return true;
}
}
@@ -268,6 +287,10 @@ const char *SysPolit::GetEconomicDesc() const
const char *SysPolit::GetAllegianceDesc() const
{
- return Polit::s_blocDesc[ Polit::s_govDesc[govType].bloc ];
+ if( Polit::s_govDesc[govType].faction != UINT_MAX ) {
+ const Faction *ptr = Faction::GetFaction( Polit::s_govDesc[govType].faction );
+ return ptr ? ptr->name.c_str() : Lang::NO_CENTRAL_GOVERNANCE;
+ }
+ return Polit::s_govDesc[govType].description;
}
10 src/Polit.h
View
@@ -19,14 +19,6 @@ namespace Polit {
CRIME_MURDER = (1<<3),
};
- enum Bloc { // <enum scope='Polit' name=PolitBloc prefix=BLOC_>
- BLOC_NONE,
- BLOC_EARTHFED,
- BLOC_CIS,
- BLOC_EMPIRE,
- BLOC_MAX // <enum skip>
- };
-
enum PolitEcon { // <enum scope='Polit' name=PolitEcon prefix=ECON_>
ECON_NONE,
ECON_VERY_CAPITALIST,
@@ -61,7 +53,7 @@ namespace Polit {
void NotifyOfCrime(Ship *s, enum Crime c);
void GetSysPolitStarSystem(const StarSystem *s, const fixed human_infestedness, SysPolit &outSysPolit);
- bool IsCommodityLegal(const StarSystem *s, Equip::Type t);
+ bool IsCommodityLegal(const StarSystem *s, const Equip::Type t);
void Init();
void Serialize(Serializer::Writer &wr);
void Unserialize(Serializer::Reader &rd);
7 src/SectorView.cpp
View
@@ -556,6 +556,9 @@ void SectorView::DrawSector(int sx, int sy, int sz, const vector3f &playerAbsPos
{
(*i).SetInhabited(false);
}
+ if( pSS->GetFactionIndex() != UINT_MAX ) {
+ (*i).factionColour = pSS->GetFactionColour();
+ }
}
}
@@ -630,8 +633,8 @@ void SectorView::DrawSector(int sx, int sy, int sz, const vector3f &playerAbsPos
Color labelColor(0.8f,0.8f,0.8f,0.5f);
if ((*i).IsSetInhabited() && (*i).IsInhabited()) {
- labelColor.r = 0.5;
- labelColor.b = labelColor.g = 1.0f;
+ labelColor = (*i).factionColour;
+ labelColor.a = 0.5f;
}
if (m_inSystem) {
5 src/SystemInfoView.cpp
View
@@ -362,9 +362,9 @@ void SystemInfoView::SystemChanged(const SystemPath &path)
{
Gui::Fixed *col1 = new Gui::Fixed();
- demographicsTab->Add(col1, 200, 350);
+ demographicsTab->Add(col1, 200, 300);
Gui::Fixed *col2 = new Gui::Fixed();
- demographicsTab->Add(col2, 400, 350);
+ demographicsTab->Add(col2, 400, 300);
const float YSEP = Gui::Screen::GetFontHeight() * 1.2f;
@@ -391,6 +391,7 @@ void SystemInfoView::SystemChanged(const SystemPath &path)
col1->Add((new Gui::Label(Lang::SECTOR_COORDINATES))->Color(1,1,0), 0, 6*YSEP);
col2->Add(new Gui::Label(stringf("%0{d}, %1{d}, %2{d}", path.sectorX, path.sectorY, path.sectorZ)), 0, 6*YSEP);
+
col1->Add((new Gui::Label(Lang::SYSTEM_NUMBER))->Color(1,1,0), 0, 7*YSEP);
col2->Add(new Gui::Label(stringf("%0", path.systemIndex)), 0, 7*YSEP);
}
8 src/enum_table.cpp
View
@@ -136,14 +136,6 @@ const struct EnumItem ENUM_PolitCrime[] = {
{ 0, 0 },
};
-const struct EnumItem ENUM_PolitBloc[] = {
- { "NONE", Polit::BLOC_NONE },
- { "EARTHFED", Polit::BLOC_EARTHFED },
- { "CIS", Polit::BLOC_CIS },
- { "EMPIRE", Polit::BLOC_EMPIRE },
- { 0, 0 },
-};
-
const struct EnumItem ENUM_PolitEcon[] = {
{ "NONE", Polit::ECON_NONE },
{ "VERY_CAPITALIST", Polit::ECON_VERY_CAPITALIST },
4 src/galaxy/CustomSystem.cpp
View
@@ -123,7 +123,7 @@ static int l_csb_orbital_phase_at_start(lua_State *L)
CustomSystemBody *csb = l_csb_check(L, 1);
const fixed *value = LuaFixed::CheckFromLua(L, 2);
if ((value->ToDouble() < 0.0) || (value->ToDouble() > double(2.0*M_PI)))
- return luaL_error(L, "Error: Custom system definition: Orbital phase at game start must be between 0 and 2 PI radians (including 0 but not 2 PI).");
+ return luaL_error(L, "Error: Custom system definition: Orbital phase at game start must be between 0 and 2 PI radians (including 0 but not 2 PI).");
csb->orbitalPhaseAtStart = *value;
lua_settop(L, 1);
return 1;
@@ -516,7 +516,7 @@ CustomSystem::CustomSystem():
numStars(0),
seed(0),
want_rand_explored(true),
- govType(Polit::GOV_NONE)
+ govType(Polit::GOV_INVALID)
{
for (int i = 0; i < 4; ++i)
primaryType[i] = SystemBody::TYPE_GRAVPOINT;
1  src/galaxy/Sector.h
View
@@ -37,6 +37,7 @@ class Sector {
SystemBody::BodyType starType[4];
Uint32 seed;
const CustomSystem *customSys;
+ Color factionColour;
private:
bool m_queriedStarSystem;
23 src/galaxy/StarSystem.cpp
View
@@ -3,6 +3,7 @@
#include "StarSystem.h"
#include "Sector.h"
+#include "Factions.h"
#include "Serializer.h"
#include "Pi.h"
@@ -883,7 +884,7 @@ vector3d Orbit::OrbitalPosAtTime(double t) const
return pos;
}
-// used for stepping through the orbit in small fractions
+// used for stepping through the orbit in small fractions
// therefore the orbital phase at game start (mean anomalty at t = 0)
// does not need to be taken into account
vector3d Orbit::EvenSpacedPosAtTime(double t) const
@@ -1226,7 +1227,7 @@ void SystemBody::PickRings(bool forceRings)
// from wikipedia: http://en.wikipedia.org/wiki/Roche_limit
// basic Roche limit calculation assuming a rigid satellite
// d = R (2 p_M / p_m)^{1/3}
- //
+ //
// where R is the radius of the primary, p_M is the density of
// the primary and p_m is the density of the satellite
//
@@ -1272,7 +1273,7 @@ SystemBody::AtmosphereParameters SystemBody::CalcAtmosphereParams() const
// The equation for pressure is:
// Pressure at height h = Pressure surface * e^((-Mg/RT)*h)
- // calculate (inverse) atmosphere scale height
+ // calculate (inverse) atmosphere scale height
// The formula for scale height is:
// h = RT / Mg
// h is height above the surface in meters
@@ -1312,7 +1313,7 @@ SystemBody::AtmosphereParameters SystemBody::CalcAtmosphereParams() const
*
* We must be sneaky and avoid floating point in these places.
*/
-StarSystem::StarSystem(const SystemPath &path) : m_path(path)
+StarSystem::StarSystem(const SystemPath &path) : m_path(path), m_factionIdx(UINT_MAX)
{
assert(path.IsSystemPath());
memset(m_tradeLevel, 0, sizeof(m_tradeLevel));
@@ -1888,6 +1889,17 @@ void StarSystem::MakeShortDescription(MTRand &rand)
}
}
+const Color StarSystem::GetFactionColour() const
+{
+ if (m_factionIdx != UINT_MAX) {
+ const Faction *fac = Faction::GetFaction(m_factionIdx);
+ if( fac ) {
+ return fac->colour;
+ }
+ }
+ return Color(0.8f,0.8f,0.8f,0.5f);
+}
+
/* percent */
#define MAX_COMMODITY_BASE_PRICE_ADJUSTMENT 25
@@ -1905,6 +1917,9 @@ void StarSystem::Populate(bool addSpaceStations)
m_industrial = rand.Fixed();
m_agricultural = 0;
+ // find the faction we're probably aligned with
+ m_factionIdx = Faction::GetNearestFactionIndex(m_path);
+
/* system attributes */
m_totalPop = fixed(0);
rootBody->PopulateStage1(this, m_totalPop);
3  src/galaxy/StarSystem.h
View
@@ -239,6 +239,8 @@ class StarSystem : public DeleteEmitter, public RefCounted {
const char *GetLongDescription() const { return m_longDesc.c_str(); }
int GetNumStars() const { return m_numStars; }
const SysPolit &GetSysPolit() const { return m_polit; }
+ const Uint32 GetFactionIndex() const { return m_factionIdx; }
+ const Color GetFactionColour() const;
static float starColors[][3];
static float starRealColors[][3];
@@ -293,6 +295,7 @@ class StarSystem : public DeleteEmitter, public RefCounted {
std::string m_name;
std::string m_shortDesc, m_longDesc;
SysPolit m_polit;
+ Uint32 m_factionIdx;
bool m_isCustom;
bool m_hasCustomBodies;
1  src/win32/pch.h
View
@@ -16,6 +16,7 @@
#include "galaxy/StarSystem.h"
#include "DynamicBody.h"
#include "EquipType.h"
+#include "Factions.h"
#include "FileSystem.h"
#include "fixed.h"
#include "Frame.h"
2  win32/vc2010/pioneer.vcxproj
View
@@ -116,6 +116,7 @@
<ClCompile Include="..\..\src\enum_table.cpp" />
<ClCompile Include="..\..\src\EquipType.cpp" />
<ClCompile Include="..\..\src\FaceVideoLink.cpp" />
+ <ClCompile Include="..\..\src\Factions.cpp" />
<ClCompile Include="..\..\src\FileSelectorWidget.cpp" />
<ClCompile Include="..\..\src\FileSourceZip.cpp" />
<ClCompile Include="..\..\src\FileSystem.cpp" />
@@ -269,6 +270,7 @@
<ClInclude Include="..\..\src\enum_table.h" />
<ClInclude Include="..\..\src\EquipType.h" />
<ClInclude Include="..\..\src\FaceVideoLink.h" />
+ <ClInclude Include="..\..\src\Factions.h" />
<ClInclude Include="..\..\src\FileSelectorWidget.h" />
<ClInclude Include="..\..\src\FileSourceZip.h" />
<ClInclude Include="..\..\src\FileSystem.h" />
8 win32/vc2010/pioneer.vcxproj.filters
View
@@ -393,6 +393,9 @@
<ClCompile Include="..\..\src\LuaRef.cpp">
<Filter>src</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\Factions.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\DeathView.cpp">
<Filter>src</Filter>
</ClCompile>
@@ -840,6 +843,9 @@
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\src\LuaPushPull.h">
+ <Filter>src</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\src\Factions.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\contrib\vcacheopt\vcacheopt.h">
@@ -871,4 +877,4 @@
<Filter>src\win32</Filter>
</ResourceCompile>
</ItemGroup>
-</Project>
+</Project>
4 win32/vc2012/pioneer.vcxproj
View
@@ -119,6 +119,7 @@
<ClCompile Include="..\..\src\enum_table.cpp" />
<ClCompile Include="..\..\src\EquipType.cpp" />
<ClCompile Include="..\..\src\FaceVideoLink.cpp" />
+ <ClCompile Include="..\..\src\Factions.cpp" />
<ClCompile Include="..\..\src\FileSelectorWidget.cpp" />
<ClCompile Include="..\..\src\FileSourceZip.cpp" />
<ClCompile Include="..\..\src\FileSystem.cpp" />
@@ -269,6 +270,7 @@
<ClInclude Include="..\..\src\enum_table.h" />
<ClInclude Include="..\..\src\EquipType.h" />
<ClInclude Include="..\..\src\FaceVideoLink.h" />
+ <ClInclude Include="..\..\src\Factions.h" />
<ClInclude Include="..\..\src\FileSelectorWidget.h" />
<ClInclude Include="..\..\src\FileSourceZip.h" />
<ClInclude Include="..\..\src\FileSystem.h" />
@@ -400,4 +402,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
8 win32/vc2012/pioneer.vcxproj.filters
View
@@ -393,6 +393,9 @@
<ClCompile Include="..\..\src\LuaRef.cpp">
<Filter>src</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\Factions.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\DeathView.cpp">
<Filter>src</Filter>
</ClCompile>
@@ -836,6 +839,9 @@
<ClInclude Include="..\..\src\LuaPushPull.h">
<Filter>src</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\Factions.h">
+ <Filter>src</Filter>
+ </ClInclude>
<ClInclude Include="..\..\src\DeathView.h">
<Filter>src</Filter>
</ClInclude>
@@ -848,4 +854,4 @@
<Filter>src</Filter>
</None>
</ItemGroup>
-</Project>
+</Project>
Please sign in to comment.
Something went wrong with that request. Please try again.