UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_nation.cpp File Reference

Nation code. More...

#include "../../cl_shared.h"
#include "../../../shared/parse.h"
#include "../../../shared/shared.h"
#include "cp_campaign.h"
#include "cp_geoscape.h"
#include "cp_ufo.h"
#include "cp_time.h"
#include "save/save_nation.h"
#include "../../ui/node/ui_node_linechart.h"
#include "cp_missions.h"

Go to the source code of this file.

Macros

#define HAPPINESS_ALIEN_MISSION_LOSS   -0.02
 
#define HAPPINESS_MAX_MISSION_IMPACT   0.07
 

Functions

nation_tNAT_GetRandom (void)
 Return a pointer to a random nation. More...
 
nation_tNAT_GetNationByID (const char *nationID)
 Return a nation-pointer by the nations id. More...
 
void NAT_UpdateHappinessForAllNations (const float minhappiness)
 Lower happiness of nations depending on alien activity. More...
 
int NAT_GetFunding (const nation_t *const nation, int month)
 Get the funding of a nation at a certain month. More...
 
const nationInfo_tNAT_GetCurrentMonthInfo (const nation_t *const nation)
 Get the current month nation stats. More...
 
const char * NAT_GetHappinessString (const float happiness)
 Translates the nation happiness float value to a string. More...
 
const char * NAT_GetCurrentHappinessString (const nation_t *nation)
 Translates the current nation happiness float value to a string. More...
 
void NAT_SetHappiness (const float minhappiness, nation_t *nation, const float happiness)
 Updates the nation happiness. More...
 
bool NAT_SaveXML (xmlNode_t *p)
 Nation saving callback. More...
 
void CP_HandleNationData (float minHappiness, mission_t *mis, const nation_t *affectedNation, const missionResults_t *results, bool won)
 Updates each nation's happiness. Should be called at the completion or expiration of every mission. The nation where the mission took place will be most affected, surrounding nations will be less affected. More...
 
bool NAT_LoadXML (xmlNode_t *p)
 Nation loading xml callback. More...
 
void CL_ParseNations (const char *name, const char **text)
 Parse the nation data from script file. More...
 
city_tCITY_GetById (const char *cityId)
 Finds a city by it's scripted identifier. More...
 
city_tCITY_GetByPos (vec2_t pos)
 Finds a city by it's geoscape coordinates. More...
 
void CITY_Parse (const char *name, const char **text)
 Parse the city data from script file. More...
 
bool NAT_ScriptSanityCheck (void)
 Checks the parsed nations and cities for errors. More...
 
static void NAT_ListStats_f (void)
 Console command for UI to gather nation statistics. More...
 
static void NAT_DrawCharts_f (void)
 Console command for UI to draw charts. More...
 
void NAT_HandleBudget (const campaign_t *campaign)
 Update the nation data from all parsed nation each month. More...
 
void NAT_BackupMonthlyData (void)
 Backs up each nation's relationship values. More...
 
void NAT_InitStartup (void)
 Init actions for nation-subsystem. More...
 
void NAT_Shutdown (void)
 Closing actions for nation-subsystem. More...
 

Variables

static const value_t nation_vals []
 
static const value_t city_vals []
 
static const cmdList_t nationCmds []
 

Detailed Description

Nation code.

Note
Functions with NAT_*

Definition in file cp_nation.cpp.

Macro Definition Documentation

#define HAPPINESS_ALIEN_MISSION_LOSS   -0.02

Definition at line 38 of file cp_nation.cpp.

Referenced by NAT_UpdateHappinessForAllNations().

#define HAPPINESS_MAX_MISSION_IMPACT   0.07

Definition at line 39 of file cp_nation.cpp.

Referenced by CP_HandleNationData().

Function Documentation

city_t* CITY_GetById ( const char *  cityId)

Finds a city by it's scripted identifier.

Parameters
[in]cityIdScripted ID of the city

Definition at line 411 of file cp_nation.cpp.

References ccs, ccs_s::cities, LIST_Foreach, and Q_streq.

Referenced by CITY_Parse().

city_t* CITY_GetByPos ( vec2_t  pos)

Finds a city by it's geoscape coordinates.

Parameters
[in]posPosition of the city

Definition at line 424 of file cp_nation.cpp.

References ccs, ccs_s::cities, LIST_Foreach, and Vector2Equal.

Referenced by MIS_LoadXML().

void CITY_Parse ( const char *  name,
const char **  text 
)

Parse the city data from script file.

Parameters
[in]nameID of the found nation
[in]textThe text of the nation node

Definition at line 445 of file cp_nation.cpp.

References ccs, cgi, ccs_s::cities, CITY_GetById(), cp_campaignPool, city_s::id, city_s::idx, LIST_Add(), ccs_s::numCities, OBJZERO, and cgame_import_s::PoolStrDup().

Referenced by CP_ParseScriptFirst().

void CL_ParseNations ( const char *  name,
const char **  text 
)

Parse the nation data from script file.

Parameters
[in]nameName or ID of the found nation
[in]textThe text of the nation node
See also
nation_vals
CL_ParseScriptFirst
Note
write into cp_campaignPool - free on every game restart and reparse

Definition at line 382 of file cp_nation.cpp.

References ccs, cgi, cp_campaignPool, DEBUG_CLIENT, nation_s::id, nation_s::idx, nationInfo_s::inuse, LIST_Add(), NAT_Foreach, ccs_s::nations, ccs_s::numNations, OBJZERO, cgame_import_s::PoolStrDup(), Q_streq, and nation_s::stats.

Referenced by CP_ParseScriptFirst().

void CP_HandleNationData ( float  minHappiness,
mission_t mis,
const nation_t affectedNation,
const missionResults_t results,
bool  won 
)

Updates each nation's happiness. Should be called at the completion or expiration of every mission. The nation where the mission took place will be most affected, surrounding nations will be less affected.

Parameters
[in]minHappinessMinimum value of mean happiness before the game is lost
[in]misMission to evaluate
[in]affectedNationNation that's happiness is changing
[in]resultsMission result structure
[in]wonif PHALANX won
Todo:
Scoring should eventually be expanded to include such elements as infected humans and mission objectives other than xenocide.
Todo:
HACK: This should be handled properly, i.e. civilians should only factor into the scoring if the mission objective is actually to save civilians.
Todo:
The score for aliens should be dependent on the mission objective. In a mission that has a special objective, the amount of killed aliens should only serve to increase the score, not reduce the penalty.

Definition at line 263 of file cp_nation.cpp.

References missionResults_s::aliensKilled, missionResults_s::aliensStunned, missionResults_s::aliensSurvived, missionResults_s::civiliansKilled, missionResults_s::civiliansKilledFriendlyFire, missionResults_s::civiliansSurvived, nationInfo_s::happiness, HAPPINESS_MAX_MISSION_IMPACT, mission_s::mapDef, NAT_Foreach, NAT_GetCurrentMonthInfo(), NAT_SetHappiness(), and mapDef_s::victoryBonusPerAlien.

Referenced by CP_MissionEnd().

void NAT_BackupMonthlyData ( void  )

Backs up each nation's relationship values.

Note
Right after the copy the stats for the current month are the same as the ones from the (end of the) previous month. They will change while the curent month is running of course :)
Todo:
other stuff to back up?

Back up nation relationship . "inuse" is copied as well so we do not need to set it anywhere.

Definition at line 826 of file cp_nation.cpp.

References i, MONTHS_PER_YEAR, and NAT_Foreach.

Referenced by CP_CampaignRun().

static void NAT_DrawCharts_f ( void  )
static

Console command for UI to draw charts.

Definition at line 584 of file cp_nation.cpp.

References cgi, cgame_import_s::Cmd_Argv(), int(), MAX_VAR, MONTHS_PER_YEAR, NAT_Foreach, NAT_GetFunding(), Q_streq, Q_strncpyz(), type, and cgame_import_s::UI_GetNodeByPath().

const char* NAT_GetCurrentHappinessString ( const nation_t nation)

Translates the current nation happiness float value to a string.

Parameters
[in]nation
Returns
Translated happiness string
Note
happiness is between 0 and 1.0

Definition at line 176 of file cp_nation.cpp.

References nationInfo_s::happiness, NAT_GetCurrentMonthInfo(), and NAT_GetHappinessString().

Referenced by NAT_HandleBudget(), and NAT_SetHappiness().

const nationInfo_t* NAT_GetCurrentMonthInfo ( const nation_t *const  nation)
int NAT_GetFunding ( const nation_t *const  nation,
int  month 
)

Get the funding of a nation at a certain month.

Parameters
[in]nationPointer to the nation
[in]monthidx of the month – 0 for current month
Returns
actual funding of a nation

Definition at line 120 of file cp_nation.cpp.

References nationInfo_s::happiness, nation_s::maxFunding, MONTHS_PER_YEAR, and nation_s::stats.

Referenced by NAT_DrawCharts_f(), NAT_HandleBudget(), and NAT_ListStats_f().

const char* NAT_GetHappinessString ( const float  happiness)

Translates the nation happiness float value to a string.

Parameters
[in]happinessvalue
Returns
Translated happiness string
Note
happiness is between 0 and 1.0

Definition at line 143 of file cp_nation.cpp.

References _.

Referenced by NAT_GetCurrentHappinessString(), NAT_ListStats_f(), and UR_DialogInitSell_f().

nation_t* NAT_GetNationByID ( const char *  nationID)

Return a nation-pointer by the nations id.

Parameters
[in]nationIDnation id as defined in scripts
Returns
nation_t pointer or nullptr if nothing found

Definition at line 63 of file cp_nation.cpp.

References cgi, NAT_Foreach, and Q_streq.

Referenced by E_LoadXML(), NAT_LoadXML(), TEST_F(), and UR_DialogStartSell_f().

nation_t* NAT_GetRandom ( void  )

Return a pointer to a random nation.

Returns
nation_t pointer

Definition at line 45 of file cp_nation.cpp.

References ccs, i, NAT_Foreach, and ccs_s::numNations.

Referenced by E_InitialEmployees().

void NAT_HandleBudget ( const campaign_t campaign)

Update the nation data from all parsed nation each month.

Note
give us nation support by:
  • credits
  • new soldiers
  • new scientists
  • new pilots
Called from CP_CampaignRun
See also
CP_CampaignRun
B_CreateEmployee
Todo:
This is very redundant with STATS_Update_f. Investigate and clean up.

Definition at line 714 of file cp_nation.cpp.

References _, AIR_CRASHED, AIR_Foreach, salary_s::aircraftDivisor, salary_s::aircraftFactor, B_GetNext(), ccs, Com_sprintf(), count, CP_GameTimeStop(), CP_GetSalaryUpKeepBase(), CP_UpdateCredits(), ccs_s::credits, ccs_s::curCampaign, salary_s::debtInterest, E_CreateEmployee(), E_Foreach, E_GetEmployeeString(), EMPL_PILOT, EMPL_SCIENTIST, EMPL_SOLDIER, EMPL_WORKER, campaign_s::employeeRate, nationInfo_s::happiness, i, int(), MAX_EMPL, MS_AddNewMessage(), base_s::name, NAT_Foreach, NAT_GetCurrentHappinessString(), NAT_GetCurrentMonthInfo(), NAT_GetFunding(), ngettext, and campaign_s::salaries.

Referenced by CP_CampaignRun(), and TEST_F().

void NAT_InitStartup ( void  )

Init actions for nation-subsystem.

Definition at line 852 of file cp_nation.cpp.

References cgi.

Referenced by CP_InitStartup().

static void NAT_ListStats_f ( void  )
static

Console command for UI to gather nation statistics.

Definition at line 543 of file cp_nation.cpp.

References _, cgi, cgame_import_s::Cmd_Argv(), MAX_VAR, MONTHS_PER_YEAR, NAT_Foreach, NAT_GetFunding(), NAT_GetHappinessString(), Q_streq, and Q_strncpyz().

bool NAT_SaveXML ( xmlNode_t p)
void NAT_SetHappiness ( const float  minhappiness,
nation_t nation,
const float  happiness 
)

Updates the nation happiness.

Parameters
[in]minhappinessMinimum value of mean happiness before the game is lost
[in]nationThe nation to update the happiness for
[in]happinessThe new happiness value to set for the given nation
Todo:
need to more specific message

Definition at line 188 of file cp_nation.cpp.

References _, Com_sprintf(), cp_messageBuffer, nationInfo_s::happiness, MSO_CheckAddNewMessage(), nation_s::name, NAT_GetCurrentHappinessString(), NT_HAPPINESS_CHANGED, NT_HAPPINESS_MIN, NT_HAPPINESS_PLEASED, NT_NUM_NOTIFYTYPE, and nation_s::stats.

Referenced by CP_BuildBaseGovernmentLeave(), CP_ChangeNationHappiness_f(), CP_HandleNationData(), NAT_UpdateHappinessForAllNations(), and UR_DialogStartSell_f().

void NAT_Shutdown ( void  )

Closing actions for nation-subsystem.

Definition at line 860 of file cp_nation.cpp.

References ccs, cgi, ccs_s::cities, and ccs_s::nations.

Referenced by CP_Shutdown().

void NAT_UpdateHappinessForAllNations ( const float  minhappiness)

Variable Documentation

const value_t city_vals[]
static
Initial value:
= {
{"name", V_TRANSLATION_STRING, offsetof(city_t, name), 0},
{"pos", V_POS, offsetof(city_t, pos), MEMBER_SIZEOF(city_t, pos)},
{nullptr, V_NULL, 0, 0}
}
City definition.
Definition: cp_nation.h:68
Definition: scripts.h:49
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
#define MEMBER_SIZEOF(TYPE, MEMBER)
Definition: scripts.h:34
Definition: scripts.h:55

Definition at line 433 of file cp_nation.cpp.

const value_t nation_vals[]
static
Initial value:
= {
{"name", V_TRANSLATION_STRING, offsetof(nation_t, name), 0},
{"pos", V_POS, offsetof(nation_t, pos), MEMBER_SIZEOF(nation_t, pos)},
{"color", V_COLOR, offsetof(nation_t, color), MEMBER_SIZEOF(nation_t, color)},
{"funding", V_INT, offsetof(nation_t, maxFunding), MEMBER_SIZEOF(nation_t, maxFunding)},
{"happiness", V_FLOAT, offsetof(nation_t, stats[0].happiness), MEMBER_SIZEOF(nation_t, stats[0].happiness)},
{"soldiers", V_INT, offsetof(nation_t, maxSoldiers), MEMBER_SIZEOF(nation_t, maxSoldiers)},
{"scientists", V_INT, offsetof(nation_t, maxScientists), MEMBER_SIZEOF(nation_t, maxScientists)},
{"workers", V_INT, offsetof(nation_t, maxWorkers), MEMBER_SIZEOF(nation_t, maxWorkers)},
{"pilots", V_INT, offsetof(nation_t, maxPilots), MEMBER_SIZEOF(nation_t, maxPilots)},
{nullptr, V_NULL, 0, 0}
}
Nation definition.
Definition: cp_nation.h:44
Definition: scripts.h:49
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
#define MEMBER_SIZEOF(TYPE, MEMBER)
Definition: scripts.h:34
Definition: scripts.h:52
Definition: scripts.h:55

Definition at line 360 of file cp_nation.cpp.

const cmdList_t nationCmds[]
static
Initial value:
= {
{"nation_getstats", NAT_ListStats_f, "Returns nation happiness and funding stats through a UI callback."},
{"nation_drawcharts", NAT_DrawCharts_f, "Draws nation happiness and funding charts."},
{nullptr, nullptr, nullptr}
}
static void NAT_DrawCharts_f(void)
Console command for UI to draw charts.
Definition: cp_nation.cpp:584
static void NAT_ListStats_f(void)
Console command for UI to gather nation statistics.
Definition: cp_nation.cpp:543

Definition at line 839 of file cp_nation.cpp.