cp_nation.c File Reference

Nation code. More...

#include "../client.h"
#include "../cl_shared.h"
#include "../ui/ui_main.h"
#include "../ui/node/ui_node_linechart.h"
#include "../../shared/parse.h"
#include "cp_campaign.h"
#include "cp_map.h"
#include "cp_ufo.h"
#include "save/save_nation.h"
Include dependency graph for cp_nation.c:

Go to the source code of this file.

Functions

nation_tNAT_GetNationByIDX (const int index)
nation_tNAT_GetNationByID (const char *nationID)
 Return a nation-pointer by the nations id (nation_t->id) text.
void NAT_UpdateHappinessForAllNations (void)
 Lower happiness of nations depending on alien activity.
int NAT_GetFunding (const nation_t *const nation, int month)
 Get the actual funding of a nation.
const char * NAT_GetHappinessString (const nation_t *nation)
 Translates the nation happiness float value to a string.
void NAT_SetHappiness (nation_t *nation, const float happiness)
 Updates the nation happiness.
qboolean NAT_SaveXML (mxml_node_t *p)
 Nation saving callback.
qboolean NAT_LoadXML (mxml_node_t *p)
 Nation loading xml callback.
void CL_ParseNations (const char *name, const char **text)
 Parse the nation data from script file.
void CL_ParseCities (const char *name, const char **text)
 Parse the city data from script file.
qboolean NAT_ScriptSanityCheck (void)
 Checks the parsed nations and cities for errors.
static void CP_NationStatsClick_f (void)
static int CL_NationsMaxFunding (void)
 Search the maximum (current) funding from all the nations (in all logged months).
static void CL_NationDrawStats (const nation_t *nation, uiNode_t *node, lineStrip_t *funding, int maxFunding, int color)
 Draws a graph for the funding values over time.
static void CL_NationStatsUpdate_f (void)
 Shows the current nation list + statistics.
static void CL_NationSelect_f (void)
 Select nation and display all relevant information for it.
void NAT_InitStartup (void)

Variables

static const value_t nation_vals []
static const value_t city_vals []
static screenPoint_t fundingPts [MAX_NATIONS][MONTHS_PER_YEAR]
static int usedFundPtslist = 0
static screenPoint_t colorLinePts [MAX_NATIONS][2]
static int usedColPtslists = 0
static const vec4_t graphColors [MAX_NATIONS]
static const vec4_t graphColorSelected = {1, 1, 1, 1}
static int selectedNation = 0
static lineStrip_t fundingLineStrip [MAX_NATIONS]
static lineStrip_t colorLineStrip [MAX_NATIONS]

Detailed Description

Nation code.

Note:
Functions with NAT_*

Definition in file cp_nation.c.


Function Documentation

static void CL_NationDrawStats ( const nation_t nation,
uiNode_t node,
lineStrip_t funding,
int  maxFunding,
int  color 
) [static]

Draws a graph for the funding values over time.

Parameters:
[in] nation The nation to draw the graph for.
[in] node A pointer to a "linestrip" node that we want to draw in.
[out] funding Funding graph data in a lineStrip_t
[in] maxFunding The upper limit of the graph - all values will be scaled to this one.
[in] color If this is -1 draw the line for the current selected nation
Todo:
Somehow the display of the months isn't really correct right now (straight line :-/)

Todo:
should be into the chart node code
Todo:
Sort this in reverse? -> Having current month on the right side?

Definition at line 611 of file cp_nation.c.

References ccs, lineStrip_s::color, Cvar_Set(), graphColors, graphColorSelected, nation_s::id, int(), nationInfo_s::inuse, m, MONTHS_PER_YEAR, NAT_GetFunding(), ccs_s::nations, lineStrip_s::numPoints, lineStrip_s::pointList, selectedNation, uiNode_s::size, nation_s::stats, usedFundPtslist, va(), Vector4Copy, screenPoint_t::x, and screenPoint_t::y.

Referenced by CL_NationStatsUpdate_f().

static void CL_NationSelect_f ( void   )  [static]

Select nation and display all relevant information for it.

Definition at line 761 of file cp_nation.c.

References ccs, CL_NationStatsUpdate_f(), Cmd_Argc(), Cmd_Argv(), Com_Printf(), ccs_s::numNations, and selectedNation.

Referenced by NAT_InitStartup().

static int CL_NationsMaxFunding ( void   )  [static]

Search the maximum (current) funding from all the nations (in all logged months).

Note:
nation->maxFunding is _not_ the real funding value.
Returns:
The maximum funding value.
Todo:
Extend to other values?
See also:
NAT_GetFunding

Definition at line 577 of file cp_nation.c.

References ccs, nationInfo_s::inuse, m, MONTHS_PER_YEAR, NAT_GetFunding(), ccs_s::nations, ccs_s::numNations, and nation_s::stats.

Referenced by CL_NationStatsUpdate_f().

static void CL_NationStatsUpdate_f ( void   )  [static]
void CL_ParseCities ( const char *  name,
const char **  text 
)

Parse the city data from script file.

Parameters:
[in] name ID of the found nation
[in] text The text of the nation node
See also:
city_vals
CL_ParseScriptFirst
Note:
write into cp_campaignPool - free on every game restart and reparse

Definition at line 379 of file cp_nation.c.

References byte, ccs, ccs_s::cities, Com_DPrintf(), Com_EParse(), Com_EParseValue(), Com_Parse(), Com_Printf(), cp_campaignPool, linkedList_s::data, DEBUG_CLIENT, city_s::id, city_s::idx, LIST_Add(), Mem_PoolStrDup, Mem_PoolStrDupTo, linkedList_s::next, ccs_s::numCities, value_s::ofs, value_s::size, value_s::string, value_s::type, V_CLIENT_HUNK_STRING, and V_TRANSLATION_STRING.

Referenced by CL_ParseScriptFirst().

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

Parse the nation data from script file.

Parameters:
[in] name Name or ID of the found nation
[in] text The 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 286 of file cp_nation.c.

References ccs, Com_DPrintf(), Com_EParse(), Com_EParseValue(), Com_Parse(), Com_Printf(), cp_campaignPool, DEBUG_CLIENT, i, nation_s::id, nation_s::idx, nationInfo_s::inuse, MAX_NATIONS, Mem_PoolStrDup, Mem_PoolStrDupTo, ccs_s::nations, ccs_s::numNations, value_s::ofs, qtrue, value_s::size, nation_s::stats, value_s::string, value_s::type, V_CLIENT_HUNK_STRING, and V_TRANSLATION_STRING.

Referenced by CL_ParseScriptFirst().

static void CP_NationStatsClick_f ( void   )  [static]

Definition at line 533 of file cp_nation.c.

References Cbuf_AddText(), ccs, Cmd_Argc(), Cmd_Argv(), Com_Printf(), ccs_s::numNations, UI_PushWindow(), and va().

Referenced by NAT_InitStartup().

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

Get the actual funding of a nation.

Parameters:
[in] nation Pointer to the nation
[in] month idx of the month -- 0 for current month (sa nation_t)
Returns:
actual funding of a nation
See also:
CL_NationsMaxFunding

Definition at line 115 of file cp_nation.c.

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

Referenced by CL_NationDrawStats(), CL_NationsMaxFunding(), CL_NationStatsUpdate_f(), CL_StatsUpdate_f(), and CP_NationHandleBudget().

const char* NAT_GetHappinessString ( const nation_t nation  ) 

Translates the 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 126 of file cp_nation.c.

References _, nationInfo_s::happiness, and nation_s::stats.

Referenced by CL_StatsUpdate_f(), CP_NationHandleBudget(), NAT_SetHappiness(), and UR_DialogFillNations().

nation_t* NAT_GetNationByID ( const char *  nationID  ) 

Return a nation-pointer by the nations id (nation_t->id) text.

Parameters:
[in] nationID nation id as defined in (nation_t->id)
Returns:
nation_t pointer or NULL if nothing found (=error).

Definition at line 50 of file cp_nation.c.

References ccs, Com_Printf(), i, nation_s::id, ccs_s::nations, and ccs_s::numNations.

Referenced by E_LoadXML(), and NAT_LoadXML().

nation_t* NAT_GetNationByIDX ( const int  index  ) 

Definition at line 37 of file cp_nation.c.

References ccs, ccs_s::nations, and ccs_s::numNations.

Referenced by NAT_SaveXML(), UR_DialogInitSell_f(), and UR_DialogStartSell_f().

void NAT_InitStartup ( void   ) 
qboolean NAT_LoadXML ( mxml_node_t p  ) 
qboolean NAT_SaveXML ( mxml_node_t p  ) 
qboolean NAT_ScriptSanityCheck ( void   ) 
void NAT_SetHappiness ( nation_t nation,
const float  happiness 
)

Updates the nation happiness.

Parameters:
[in] nation The nation to update the happiness for
[in] happiness The new happiness value to set for the given nation

Todo:
need to more specific message

Definition at line 157 of file cp_nation.c.

References _, ccs, Com_sprintf(), cp_messageBuffer, ccs_s::curCampaign, nationInfo_s::happiness, campaign_s::minhappiness, MSG_STANDARD, MSO_CheckAddNewMessage(), nation_s::name, NAT_GetHappinessString(), NT_HAPPINESS_CHANGED, NT_HAPPINESS_MIN, NT_HAPPINESS_PLEASED, NT_NUM_NOTIFYTYPE, qfalse, and nation_s::stats.

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

void NAT_UpdateHappinessForAllNations ( void   ) 

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)},

    {NULL, 0, 0, 0}
}

Definition at line 364 of file cp_nation.c.

screenPoint_t colorLinePts[MAX_NATIONS][2] [static]

Space for 1 line (2 points) for each nation.

Definition at line 555 of file cp_nation.c.

lineStrip_t colorLineStrip[MAX_NATIONS] [static]

Definition at line 666 of file cp_nation.c.

lineStrip_t fundingLineStrip[MAX_NATIONS] [static]

Definition at line 600 of file cp_nation.c.

screenPoint_t fundingPts[MAX_NATIONS][MONTHS_PER_YEAR] [static]

Space for month-lines with 12 points for each nation.

Definition at line 552 of file cp_nation.c.

const vec4_t graphColors[MAX_NATIONS] [static]
Initial value:
 {
    {1.0, 0.5, 0.5, 1.0},
    {0.5, 1.0, 0.5, 1.0},
    {0.5, 0.5, 1.0, 1.0},
    {1.0, 0.0, 0.0, 1.0},
    {0.0, 1.0, 0.0, 1.0},
    {0.0, 0.0, 1.0, 1.0},
    {1.0, 1.0, 0.0, 1.0},
    {0.0, 1.0, 1.0, 1.0}
}

Definition at line 558 of file cp_nation.c.

Referenced by CL_NationDrawStats(), and CL_NationStatsUpdate_f().

const vec4_t graphColorSelected = {1, 1, 1, 1} [static]

Definition at line 568 of file cp_nation.c.

Referenced by CL_NationDrawStats(), and CL_NationStatsUpdate_f().

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)},

    {NULL, 0, 0, 0}
}

Definition at line 266 of file cp_nation.c.

int selectedNation = 0 [static]

Definition at line 598 of file cp_nation.c.

Referenced by CL_NationDrawStats(), CL_NationSelect_f(), and CL_NationStatsUpdate_f().

int usedColPtslists = 0 [static]

Definition at line 556 of file cp_nation.c.

Referenced by CL_NationStatsUpdate_f().

int usedFundPtslist = 0 [static]

Definition at line 553 of file cp_nation.c.

Referenced by CL_NationDrawStats(), and CL_NationStatsUpdate_f().


Generated by  doxygen 1.6.2