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

UFOpaedia script interpreter. More...

Go to the source code of this file.

Macros

#define MAX_UPTEXT   4096
 

Enumerations

enum  { UFOPEDIA_CHAPTERS, UFOPEDIA_INDEX, UFOPEDIA_ARTICLE, UFOPEDIA_DISPLAYEND }
 

Functions

static bool UP_TechGetsDisplayed (const technology_t *tech)
 Checks If a technology/UFOpaedia-entry will be displayed in the UFOpaedia (-list). More...
 
static void UP_ChangeDisplay (int newDisplay)
 Modify the global display var. More...
 
static const char * UP_AircraftStatToName (int stat)
 Translate a aircraft statistic integer to a translated string. More...
 
static void UP_DisplayTechTree (const technology_t *t)
 Displays the tech tree dependencies in the UFOpaedia. More...
 
static void UP_BuildingDescription (const technology_t *t)
 Prints the UFOpaedia description for buildings. More...
 
void UP_AircraftItemDescription (const objDef_t *item)
 Prints the (UFOpaedia and other) description for aircraft items. More...
 
void UP_AircraftDescription (const technology_t *tech)
 Prints the UFOpaedia description for aircraft. More...
 
void UP_UGVDescription (const ugv_t *ugvType)
 Prints the description for robots/ugvs. More...
 
int UP_GetUnreadMails (void)
 Sets the amount of unread/new mails. More...
 
static void UP_SetMailHeader (technology_t *tech, techMailType_t type, eventMail_t *mail)
 Binds the mail header (if needed) to the mn.menuText array. More...
 
static void UP_DrawAssociatedAmmo (const technology_t *tech)
 Set the ammo model to display to selected ammo (only for a reloadable weapon) More...
 
static void UP_Article (technology_t *tech, eventMail_t *mail)
 Display only the TEXT_UFOPEDIA part for a given technology. More...
 
void UP_OpenEventMail (const char *eventMailID)
 
static void UP_OpenMailWith (const char *techID)
 Opens the mail view from everywhere with the entry given through name. More...
 
void UP_OpenWith (const char *techID)
 Opens the UFOpaedia from everywhere with the entry given through name. More...
 
void UP_OpenCopyWith (const char *techID)
 Opens the UFOpaedia with the entry given through name, not deleting copies. More...
 
static void UP_FindEntry_f (void)
 Search and open the UFOpaedia with given id. More...
 
static uiNode_tUP_GenerateArticlesSummary (pediaChapter_t *parentChapter)
 Generate a list of options for all allowed articles of a chapter. More...
 
static void UP_GenerateSummary (void)
 Generate a tree of option for all allowed chapters and articles. More...
 
static void UP_Content_f (void)
 Displays the chapters in the UFOpaedia. More...
 
static void UP_Click_f (void)
 Callback when we click on the ufopedia summary. More...
 
static void UP_TechTreeClick_f (void)
 
static void UP_Update_f (void)
 Redraw the UFOpaedia article. More...
 
static void UP_MailClientClick_f (void)
 Mailclient click function callback. More...
 
static void UP_ResearchedLinkClick_f (void)
 Change UFOpaedia article when clicking on the name of associated ammo or weapon. More...
 
static void UP_OpenMail_f (void)
 Start the mailclient. More...
 
static void UP_SetAllMailsRead_f (void)
 Marks all mails read in mailclient. More...
 
void UP_InitStartup (void)
 
void UP_Shutdown (void)
 
void UP_ParseChapter (const char *name, const char **text)
 Parse the UFOpaedia chapters from scripts. More...
 

Variables

static cvar_tmn_uppretext
 
static cvar_tmn_uppreavailable
 
static pediaChapter_tupChaptersDisplayList [MAX_PEDIACHAPTERS]
 
static int numChaptersDisplayList
 
static technology_tupCurrentTech
 
static pediaChapter_tcurrentChapter
 
static char upBuffer [MAX_UPTEXT]
 
static int upDisplay = UFOPEDIA_CHAPTERS
 
static const cmdList_t ufopediaCmds []
 

Detailed Description

UFOpaedia script interpreter.

Todo:

Split the mail code into cl_mailclient.c/h

Remove direct access to nodes

Definition in file cp_ufopedia.cpp.

Macro Definition Documentation

#define MAX_UPTEXT   4096

Definition at line 46 of file cp_ufopedia.cpp.

Enumeration Type Documentation

anonymous enum
Note
don't change the order or you have to change the if statements about mn_updisplay cvar in menu_ufopedia.ufo, too
Enumerator
UFOPEDIA_CHAPTERS 
UFOPEDIA_INDEX 
UFOPEDIA_ARTICLE 
UFOPEDIA_DISPLAYEND 

Definition at line 53 of file cp_ufopedia.cpp.

Function Documentation

void UP_AircraftItemDescription ( const objDef_t item)

Prints the (UFOpaedia and other) description for aircraft items.

Parameters
itemThe object definition of the item
See also
UP_Article Not only called from UFOpaedia but also from other places to display
Todo:
Don't display things like speed for base defence items - a missile facility isn't getting slower or faster due a special weapon or ammunition

Definition at line 227 of file cp_ufopedia.cpp.

References _, AC_ITEM_AMMO, AC_ITEM_BASE_LASER, AC_ITEM_BASE_MISSILE, AC_ITEM_WEAPON, AII_GetItemWeightBySize(), AII_WeightToName(), AIR_AircraftMenuStatsValues(), AIR_STATS_MAX, AIR_STATS_WRANGE, objDef_s::ammo, objDef_s::ammos, cgi, objDef_s::craftitem, cgame_import_s::Cvar_Set(), EQUAL, i, objDef_s::id, objDef_s::isVirtual, technology_s::mdl, objDef_s::name, objDef_s::numAmmos, Q_strcat(), RS_GetTechForItem(), RS_IsResearched_ptr(), craftitem_s::stats, TEXT_ITEMDESCRIPTION, craftitem_s::type, UP_AircraftStatToName(), craftitem_s::weaponDamage, and craftitem_s::weaponDelay.

Referenced by AIM_UpdateItemDescription(), BDEF_SelectItem_f(), BS_ShowInfo_f(), and UP_Article().

static const char* UP_AircraftStatToName ( int  stat)
static
static void UP_ChangeDisplay ( int  newDisplay)
static
static void UP_Click_f ( void  )
static

Callback when we click on the ufopedia summary.

Note
when we click on a chapter, param=chapterId, when we click on an article, param='@'+techIdx

Definition at line 878 of file cp_ufopedia.cpp.

References ccs, cgi, cgame_import_s::Cmd_Argv(), ccs_s::numTechnologies, ccs_s::technologies, UFOPEDIA_CHAPTERS, UP_Article(), and UP_ChangeDisplay().

static void UP_Content_f ( void  )
static

Displays the chapters in the UFOpaedia.

Definition at line 867 of file cp_ufopedia.cpp.

References UFOPEDIA_CHAPTERS, UP_ChangeDisplay(), and UP_GenerateSummary().

static void UP_DisplayTechTree ( const technology_t t)
static

Displays the tech tree dependencies in the UFOpaedia.

See also
UP_Article
Todo:

Add support for "requireAND"

re-iterate trough logic blocks (i.e. append the tech-names it references recursively)

Only display tech if it is ok to do so.

Todo:
If it is one (a logic tech) we may want to re-iterate from its requirements?

Definition at line 164 of file cp_ufopedia.cpp.

References _, cgi, cgame_import_s::Cvar_Set(), ERR_DROP, i, requirement_s::id, requirement_s::link, requirements_s::links, technology_s::name, requirements_s::numLinks, technology_s::requireAND, RS_LINK_TECH, requirement_s::typelink_t::tech, TEXT_UFOPEDIA_REQUIREMENT, requirement_s::type, and UP_TechGetsDisplayed().

Referenced by UP_AircraftDescription(), UP_Article(), and UP_BuildingDescription().

static void UP_DrawAssociatedAmmo ( const technology_t tech)
static

Set the ammo model to display to selected ammo (only for a reloadable weapon)

Parameters
techtechnology_t pointer for the weapon's tech
See also
UP_Article

Definition at line 576 of file cp_ufopedia.cpp.

References objDef_s::ammos, cgi, cgame_import_s::Cvar_Set(), INVSH_GetItemByID(), technology_s::mdl, objDef_s::numAmmos, technology_s::provides, and RS_GetTechForItem().

Referenced by UP_Article().

static void UP_FindEntry_f ( void  )
static

Search and open the UFOpaedia with given id.

Definition at line 761 of file cp_ufopedia.cpp.

References cgi, cgame_import_s::Cmd_Argv(), DEBUG_CLIENT, technology_s::redirect, RS_GetTechByID(), and UP_Article().

static uiNode_t* UP_GenerateArticlesSummary ( pediaChapter_t parentChapter)
static

Generate a list of options for all allowed articles of a chapter.

Parameters
[in]parentChapterrequested chapter
Returns
The first option of the list, else nullptr if no articles

Definition at line 797 of file cp_ufopedia.cpp.

References cgi, pediaChapter_s::first, technology_s::idx, technology_s::name, cgame_import_s::UI_AddOption(), UP_TechGetsDisplayed(), technology_s::upNext, and va().

Referenced by UP_GenerateSummary().

void UP_InitStartup ( void  )
See also
cgi->UI_InitStartup

Definition at line 1156 of file cp_ufopedia.cpp.

References cgi, cgame_import_s::Cvar_Get(), and cgame_import_s::Cvar_Set().

Referenced by CP_InitStartup().

void UP_OpenCopyWith ( const char *  techID)

Opens the UFOpaedia with the entry given through name, not deleting copies.

Parameters
techIDUFOpaedia entry id (technology script id)
See also
UP_FindEntry_f

Definition at line 751 of file cp_ufopedia.cpp.

References cgi.

void UP_OpenEventMail ( const char *  eventMailID)
See also
CL_EventAddMail_f

Definition at line 707 of file cp_ufopedia.cpp.

References cgi, CL_GetEventMail(), and UP_Article().

Referenced by CL_EventAddMail(), and UP_MailClientClick_f().

static void UP_OpenMailWith ( const char *  techID)
static

Opens the mail view from everywhere with the entry given through name.

Parameters
techIDmail entry id (technology script id)
See also
UP_FindEntry_f

Definition at line 723 of file cp_ufopedia.cpp.

References cgi.

Referenced by UP_MailClientClick_f().

void UP_OpenWith ( const char *  techID)

Opens the UFOpaedia from everywhere with the entry given through name.

Parameters
techIDUFOpaedia entry id (technology script id)
See also
UP_FindEntry_f

Definition at line 737 of file cp_ufopedia.cpp.

References cgi.

Referenced by B_BuildingOpenAfterClick_f(), BS_MarketInfoClick_f(), PR_ProductionListRightClick_f(), RS_ResearchFinish(), UP_ResearchedLinkClick_f(), and UP_TechTreeClick_f().

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

Parse the UFOpaedia chapters from scripts.

Parameters
[in]nameChapter ID
[in]textText for chapter ID
See also
CL_ParseFirstScript

Definition at line 1187 of file cp_ufopedia.cpp.

References ccs, cgi, cgame_import_s::Com_EParse(), Com_Parse(), cp_campaignPool, ERR_DROP, pediaChapter_s::id, pediaChapter_s::idx, MAX_PEDIACHAPTERS, pediaChapter_s::name, ccs_s::numChapters, OBJZERO, cgame_import_s::PoolStrDup(), Q_streq, and ccs_s::upChapters.

Referenced by CP_ParseScriptFirst().

static void UP_ResearchedLinkClick_f ( void  )
static

Change UFOpaedia article when clicking on the name of associated ammo or weapon.

Definition at line 1009 of file cp_ufopedia.cpp.

References objDef_s::ammos, technology_s::id, INVSH_GetItemByID(), objDef_s::isAmmo(), objDef_s::isReloadable(), technology_s::provides, RS_GetTechForItem(), UP_OpenWith(), UP_TechGetsDisplayed(), objDef_s::weapon, and objDef_s::weapons.

void UP_Shutdown ( void  )
See also
UI_InitStartup

Definition at line 1170 of file cp_ufopedia.cpp.

References cgi.

Referenced by CP_RemoveCampaignCallbackCommands().

static bool UP_TechGetsDisplayed ( const technology_t tech)
static

Checks If a technology/UFOpaedia-entry will be displayed in the UFOpaedia (-list).

Note
This does not check for different display modes (only pre-research text, what statistics, etc...). The content is mostly checked in UP_Article
Returns
true if the tech gets displayed at all, otherwise false.
See also
UP_Article

Definition at line 69 of file cp_ufopedia.cpp.

References INVSH_GetItemByIDSilent(), objDef_s::isVirtual, technologyDescriptions_s::numDescriptions, technology_s::preDescription, technology_s::provides, technology_s::redirect, RS_Collected_, RS_IsResearched_ptr(), RS_LOGIC, technology_s::statusResearchable, and technology_s::type.

Referenced by UP_DisplayTechTree(), UP_GenerateArticlesSummary(), UP_GenerateSummary(), and UP_ResearchedLinkClick_f().

void UP_UGVDescription ( const ugv_t ugvType)

Prints the description for robots/ugvs.

Parameters
[in]ugvTypeWhat type of robot/ugv to print the description for.
See also
BS_MarketClick_f
UP_Article
Todo:
make me shiny
Todo:
Display crippled info and pre-research text here

Definition at line 400 of file cp_ufopedia.cpp.

References _, cgi, Com_sprintf(), cgame_import_s::Cvar_Set(), ugv_s::id, technology_s::name, technology_s::provides, RS_Collected_, RS_GetTechByProvided(), RS_IsResearched_ptr(), TEXT_ITEMDESCRIPTION, and ugv_s::weapon.

Referenced by UP_Article().

static void UP_Update_f ( void  )
static

Redraw the UFOpaedia article.

Definition at line 940 of file cp_ufopedia.cpp.

References UP_Article().

Variable Documentation

pediaChapter_t* currentChapter
static

Definition at line 44 of file cp_ufopedia.cpp.

cvar_t* mn_uppreavailable
static

Definition at line 38 of file cp_ufopedia.cpp.

cvar_t* mn_uppretext
static

Definition at line 37 of file cp_ufopedia.cpp.

int numChaptersDisplayList
static

Definition at line 41 of file cp_ufopedia.cpp.

Referenced by UP_GenerateSummary().

const cmdList_t ufopediaCmds[]
static
Initial value:
= {
{"mn_upcontent", UP_Content_f, "Shows the UFOpaedia chapters"},
{"mn_upupdate", UP_Update_f, "Redraw the current UFOpaedia article"},
{"ufopedia", UP_FindEntry_f, "Open the UFOpaedia with the given article"},
{"ufopedia_click", UP_Click_f, nullptr},
{"mailclient_click", UP_MailClientClick_f, nullptr},
{"mn_mail_readall", UP_SetAllMailsRead_f, "Mark all mails read"},
{"ufopedia_openmail", UP_OpenMail_f, "Start the mailclient"},
{"techtree_click", UP_TechTreeClick_f, nullptr},
{"mn_upgotoresearchedlink", UP_ResearchedLinkClick_f, nullptr},
{nullptr, nullptr, nullptr}
}
static void UP_MailClientClick_f(void)
Mailclient click function callback.
static void UP_OpenMail_f(void)
Start the mailclient.
static void UP_TechTreeClick_f(void)
static void UP_Click_f(void)
Callback when we click on the ufopedia summary.
static void UP_Content_f(void)
Displays the chapters in the UFOpaedia.
static void UP_Update_f(void)
Redraw the UFOpaedia article.
static void UP_SetAllMailsRead_f(void)
Marks all mails read in mailclient.
static void UP_FindEntry_f(void)
Search and open the UFOpaedia with given id.
static void UP_ResearchedLinkClick_f(void)
Change UFOpaedia article when clicking on the name of associated ammo or weapon.

Definition at line 1141 of file cp_ufopedia.cpp.

char upBuffer[MAX_UPTEXT]
static

Definition at line 47 of file cp_ufopedia.cpp.

Referenced by UP_AircraftDescription(), and UP_BuildingDescription().

pediaChapter_t* upChaptersDisplayList[MAX_PEDIACHAPTERS]
static

Definition at line 40 of file cp_ufopedia.cpp.

technology_t* upCurrentTech
static

Definition at line 43 of file cp_ufopedia.cpp.

int upDisplay = UFOPEDIA_CHAPTERS
static

Definition at line 60 of file cp_ufopedia.cpp.

Referenced by UP_Article(), and UP_ChangeDisplay().