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

Header for research related stuff. More...

Go to the source code of this file.

Data Structures

struct  requirement_s
 
union  requirement_s::typelink_t
 
struct  requirements_s
 
struct  markResearched_s
 
struct  techMail_s
 available mails for a tech - mail and mail_pre in script files More...
 
struct  technologyDescriptions_s
 
struct  technology_s
 This is the technology parsed from research.ufo. More...
 

Macros

#define MAX_RESEARCHLIST   32
 
#define MAX_TECHNOLOGIES   256
 
#define MAX_TECHLINKS   16
 
#define MAX_DESCRIPTIONS   8
 
#define TECH_INVALID   -1
 
#define ANTIMATTER_ITEM_ID   "antimatter"
 
#define RS_Collected_(tech)   ((tech)->statusCollected)
 

Typedefs

typedef enum researchStatus_s researchStatus_t
 The status of a research (per tech) More...
 
typedef enum researchType_s researchType_t
 Types of research topics. More...
 
typedef enum requirementType_s requirementType_t
 
typedef struct requirement_s requirement_t
 
typedef struct requirements_s requirements_t
 
typedef struct markResearched_s markResearched_t
 
typedef struct techMail_s techMail_t
 available mails for a tech - mail and mail_pre in script files More...
 
typedef struct
technologyDescriptions_s 
technologyDescriptions_t
 
typedef struct technology_s technology_t
 This is the technology parsed from research.ufo. More...
 

Enumerations

enum  researchStatus_s { RS_NONE, RS_RUNNING, RS_PAUSED, RS_FINISH }
 The status of a research (per tech) More...
 
enum  researchType_s {
  RS_TECH, RS_WEAPON, RS_ARMOUR, RS_CRAFT,
  RS_CRAFTITEM, RS_BUILDING, RS_ALIEN, RS_UGV,
  RS_NEWS, RS_LOGIC
}
 Types of research topics. More...
 
enum  requirementType_s {
  RS_LINK_TECH, RS_LINK_TECH_NOT, RS_LINK_ITEM, RS_LINK_ALIEN,
  RS_LINK_ALIEN_DEAD, RS_LINK_ALIEN_GLOBAL, RS_LINK_UFO, RS_LINK_ANTIMATTER,
  MAX_RS_LINKTYPES
}
 
enum  techMailType_t { TECHMAIL_PRE, TECHMAIL_RESEARCHED, TECHMAIL_MAX }
 Types for tech mail definitions - see tech->mail[]. More...
 
enum  mailSentType_t { MAILSENT_NONE, MAILSENT_PROPOSAL, MAILSENT_FINISHED, MAILSENT_MAX }
 

Functions

void RS_InitStartup (void)
 This is more or less the initial Bind some of the functions in this file to console-commands that you can call ingame. Called from UI_InitStartup resp. CL_InitLocal. More...
 
void RS_ResetTechs (void)
 This is called everytime RS_ParseTechnologies is called - to prevent cyclic hash tables. More...
 
int RS_ResearchRun (void)
 Checks the research status. More...
 
void RS_ParseTechnologies (const char *name, const char **text)
 Parses one "tech" entry in the research.ufo file and writes it into the next free entry in technologies (technology_t). More...
 
bool RS_IsResearched_idx (int techIdx)
 Checks if the technology (tech-index) has been researched. More...
 
bool RS_IsResearched_ptr (const technology_t *tech)
 Checks whether an item is already researched. More...
 
technology_tRS_GetTechForItem (const objDef_t *item)
 Returns technology entry for an item. More...
 
technology_tRS_GetTechForTeam (const teamDef_t *team)
 Returns technology entry for a team. More...
 
void RS_AddObjectTechs (void)
 
void RS_RequiredLinksAssign (void)
 Assign Link pointers to all required techs/items/etc... More...
 
void RS_InitTree (const struct campaign_s *campaign, bool load)
 
const char * RS_GetDescription (technologyDescriptions_t *desc)
 returns the currently used description for a technology. More...
 
void RS_MarkCollected (technology_t *tech) __attribute__((nonnull))
 Marks a give technology as collected. More...
 
void RS_MarkResearchable (const struct base_s *base, bool init=false)
 
bool RS_MarkStoryLineEventResearched (const char *techID)
 
void RS_ResearchFinish (technology_t *tech)
 Sets a technology status to researched and updates the date. More...
 
void RS_StopResearch (technology_t *tech)
 Stops a research (Removes scientists from it) More...
 
void RS_MarkOneResearchable (technology_t *tech)
 Marks one tech as researchable. More...
 
void RS_AssignScientist (technology_t *tech, struct base_s *base, Employee *employee=nullptr)
 Assigns scientist to the selected research-project. More...
 
void RS_RemoveScientist (technology_t *tech, Employee *employee)
 Remove a scientist from a technology. More...
 
void RS_RemoveFiredScientist (struct base_s *base, Employee *employee)
 Remove one scientist from research project if needed. More...
 
void RS_RemoveScientistsExceedingCapacity (struct base_s *base)
 Remove all exceeding scientist. More...
 
technology_tRS_GetTechByID (const char *id)
 return a pointer to the technology identified by given id string More...
 
technology_tRS_GetTechByProvided (const char *idProvided)
 returns a pointer to the item tech (as listed in "provides") More...
 
technology_tRS_GetTechByIDX (int tech_idx)
 Returns the technology pointer for a tech index. You can use this instead of "&ccs.technologies[techIdx]" to avoid having to check valid indices. More...
 
technology_tRS_GetTechWithMostScientists (const struct base_s *base)
 Searches for the technology that has the most scientists assigned in a given base. More...
 
int RS_GetTechIdxByName (const char *name)
 Returns the index (idx) of a "tech" entry given it's name. More...
 
int RS_CountScientistsInBase (const struct base_s *base)
 
bool RS_ScriptSanityCheck (void)
 Checks the parsed tech data for errors. More...
 
void UP_AircraftDescription (const technology_t *t)
 Prints the UFOpaedia description for aircraft. More...
 
void UP_UGVDescription (const struct ugv_s *ugvType)
 
void RS_CheckRequirements (void)
 Checks if running researches still meet their requirements. More...
 
bool RS_RequirementsMet (const technology_t *tech, const struct base_s *base)
 

Detailed Description

Header for research related stuff.

Definition in file cp_research.h.

Macro Definition Documentation

#define MAX_DESCRIPTIONS   8

Maximum number of descriptions (per tech and description-type).

Definition at line 31 of file cp_research.h.

Referenced by RS_ParseTechnologies().

#define MAX_RESEARCHLIST   32

Definition at line 28 of file cp_research.h.

#define MAX_TECHLINKS   16

Maximum number of requirements in a technology (i.e in requireAND and requireOR).

Definition at line 30 of file cp_research.h.

Referenced by RS_ParseTechnologies().

#define MAX_TECHNOLOGIES   256

Maximum number of technologies overall.

Definition at line 29 of file cp_research.h.

Referenced by AII_GetCraftitemTechsByType(), RS_IsValidTechIndex(), and RS_ParseTechnologies().

#define RS_Collected_ (   tech)    ((tech)->statusCollected)
#define TECH_INVALID   -1

The value for an "undef" tech-index.

Definition at line 33 of file cp_research.h.

Referenced by RS_GetTechIdxByName(), and RS_IsValidTechIndex().

Typedef Documentation

Todo:
MAX_CAMPAIGNS is not defined unless cp_campaign.h is included before
typedef struct requirement_s requirement_t

The status of a research (per tech)

Types of research topics.

typedef struct techMail_s techMail_t

available mails for a tech - mail and mail_pre in script files

See also
eventMail_t
typedef struct technology_s technology_t

This is the technology parsed from research.ufo.

Enumeration Type Documentation

Enumerator
MAILSENT_NONE 

No mail sent yet.

MAILSENT_PROPOSAL 

Mail for research proposal already send.

MAILSENT_FINISHED 

Mail for finished research sent (and maybe the previous as well).

MAILSENT_MAX 

Definition at line 120 of file cp_research.h.

Enumerator
RS_LINK_TECH 
RS_LINK_TECH_NOT 
RS_LINK_ITEM 
RS_LINK_ALIEN 
RS_LINK_ALIEN_DEAD 
RS_LINK_ALIEN_GLOBAL 
RS_LINK_UFO 
RS_LINK_ANTIMATTER 
MAX_RS_LINKTYPES 

Definition at line 59 of file cp_research.h.

The status of a research (per tech)

Enumerator
RS_NONE 
RS_RUNNING 
RS_PAUSED 
RS_FINISH 

Definition at line 38 of file cp_research.h.

Types of research topics.

Enumerator
RS_TECH 
RS_WEAPON 
RS_ARMOUR 
RS_CRAFT 
RS_CRAFTITEM 
RS_BUILDING 
RS_ALIEN 
RS_UGV 
RS_NEWS 
RS_LOGIC 

Definition at line 46 of file cp_research.h.

Types for tech mail definitions - see tech->mail[].

Enumerator
TECHMAIL_PRE 

this is a mail_pre (proposal) definition

TECHMAIL_RESEARCHED 

this is the mail definition (after research was completed)

TECHMAIL_MAX 

Definition at line 97 of file cp_research.h.

Function Documentation

void RS_AddObjectTechs ( void  )
void RS_AssignScientist ( technology_t tech,
base_t base,
Employee employee 
)

Assigns scientist to the selected research-project.

Note
The lab will be automatically selected (the first one that has still free space).
Parameters
[in]techWhat technology you want to assign the scientist to.
[in]basePointer to base where the research is ongoing.
[in]employeePointer to the scientist to assign. It can be nullptr! That means "any".
Note
if employee is nullptr, te system selects an unassigned scientist on the selected (or tech-) base
See also
RS_AssignScientist_f
RS_RemoveScientist

Definition at line 653 of file cp_research.cpp.

References _, technology_s::base, CAP_AddCurrent(), CAP_GetFreeCapacity(), CAP_LABSPACE, cgi, CP_Popup(), DEBUG_CLIENT, E_GetUnassignedEmployee(), EMPL_SCIENTIST, technology_s::id, technology_s::idx, base_s::name, technology_s::name, RS_RUNNING, technology_s::scientists, Employee::setAssigned(), technology_s::statusResearch, and technology_s::statusResearchable.

Referenced by RS_Change_f(), RS_Max_f(), RS_RemoveFiredScientist(), and TEST_F().

int RS_CountScientistsInBase ( const struct base_s base)
const char* RS_GetDescription ( technologyDescriptions_t desc)

returns the currently used description for a technology.

Parameters
[in,out]descA list of possible descriptions (with tech-links that decide which one is the correct one)

< Stored used description

Definition at line 270 of file cp_research.cpp.

References i, technologyDescriptions_s::numDescriptions, RS_GetTechByID(), RS_IsResearched_ptr(), technologyDescriptions_s::tech, technologyDescriptions_s::text, and technologyDescriptions_s::usedDescription.

Referenced by RS_MarkOneResearchable(), RS_ResearchFinish(), and UP_Article().

technology_t* RS_GetTechByID ( const char *  id)
technology_t* RS_GetTechByIDX ( int  techIdx)

Returns the technology pointer for a tech index. You can use this instead of "&ccs.technologies[techIdx]" to avoid having to check valid indices.

Parameters
[in]techIdxIndex in the global ccs.technologies[] array.
Returns
technology_t pointer or nullptr if an error occurred.

Definition at line 1589 of file cp_research.cpp.

References ccs, RS_IsValidTechIndex(), and ccs_s::technologies.

Referenced by AIM_AircraftEquipMenuClick_f(), CP_ParseResearchableCampaignStates(), CP_ParseResearchedCampaignItems(), RS_CheckRequirements(), RS_FillTechnologyList_f(), RS_GetTechWithMostScientists(), RS_MarkResearchable(), RS_RequiredLinksAssign(), RS_ResearchRun(), RS_SaveXML(), and RS_ShowActiveResearch_f().

technology_t* RS_GetTechByProvided ( const char *  idProvided)

returns a pointer to the item tech (as listed in "provides")

Parameters
[in]idProvidedUnique identifier of the object the tech is providing
Returns
The tech for the given object id or nullptr if not found

Definition at line 1621 of file cp_research.cpp.

References cgi, Com_HashKey(), DEBUG_CLIENT, hash, technology_s::hashProvidedNext, technology_s::provides, Q_strcasecmp, and TECH_HASH_SIZE.

Referenced by AII_LoadOneSlotXML(), AIRFIGHT_LoadXML(), B_ParseBuildings(), BS_FillMarket_f(), BS_MarketInfoClick_f(), GAME_CP_GetItemModel(), INS_LinkTechnologies(), RS_InitTree(), UFO_GetTechnologyFromType(), and UP_UGVDescription().

technology_t* RS_GetTechForTeam ( const teamDef_t team)

Returns technology entry for a team.

Parameters
[in]teamPointer to the team definition

Definition at line 470 of file cp_research.cpp.

References ccs, cgi, ERR_DROP, teamDef_s::id, teamDef_s::idx, lengthof, and ccs_s::teamDefTechs.

Referenced by AC_Init_f(), AC_KillOne_f(), and AlienContainment::add().

int RS_GetTechIdxByName ( const char *  name)

Returns the index (idx) of a "tech" entry given it's name.

Parameters
[in]namethe name of the tech

Definition at line 1669 of file cp_research.cpp.

References cgi, Com_HashKey(), hash, technology_s::hashNext, technology_s::id, technology_s::idx, Q_strcasecmp, TECH_HASH_SIZE, and TECH_INVALID.

technology_t* RS_GetTechWithMostScientists ( const struct base_s base)

Searches for the technology that has the most scientists assigned in a given base.

Parameters
[in]baseIn what base the tech should be researched.

Definition at line 1644 of file cp_research.cpp.

References technology_s::base, ccs, i, ccs_s::numTechnologies, RS_GetTechByIDX(), RS_RUNNING, technology_s::scientists, and technology_s::statusResearch.

Referenced by RS_RemoveFiredScientist(), and RS_RemoveScientistsExceedingCapacity().

void RS_InitStartup ( void  )

This is more or less the initial Bind some of the functions in this file to console-commands that you can call ingame. Called from UI_InitStartup resp. CL_InitLocal.

Definition at line 1068 of file cp_research.cpp.

References cgi.

Referenced by CP_InitStartup().

void RS_InitTree ( const struct campaign_s campaign,
bool  load 
)
bool RS_IsResearched_idx ( int  techIdx)

Checks if the technology (tech-index) has been researched.

Parameters
[in]techIdxindex of the technology.
Returns
true if the technology has been researched, otherwise (or on error) false;
See also
RS_IsResearched_ptr

Definition at line 1560 of file cp_research.cpp.

References ccs, RS_FINISH, RS_IsValidTechIndex(), technology_s::statusResearch, and ccs_s::technologies.

void RS_MarkOneResearchable ( technology_t tech)

Marks one tech as researchable.

Parameters
techThe technology to be marked.
See also
RS_MarkCollected
RS_MarkResearchable

At this point we define what research proposal description is used when displayed. (i.e. "usedDescription" is set here). That's because this is the first the player will see anything from the tech and any later changes may make the content (proposal) of the tech inconsistent for the player.

See also
RS_ResearchFinish

Definition at line 106 of file cp_research.cpp.

References _, ccs, cgi, Com_sprintf(), cp_messageBuffer, ccs_s::date, date_s::day, DEBUG_CLIENT, technology_s::id, technology_s::mailSent, MAILSENT_FINISHED, MAILSENT_PROPOSAL, MSG_RESEARCH_PROPOSAL, MSO_CheckAddNewMessage(), technology_s::name, NT_RESEARCH_PROPOSED, technology_s::preDescription, technology_s::preResearchedDate, RS_GetDescription(), technology_s::statusResearchable, and technology_s::time.

Referenced by CP_AddTechAsResearchable_f(), CP_ParseResearchableCampaignStates(), RS_MarkResearchable(), and TEST_F().

void RS_MarkResearchable ( const struct base_s base,
bool  init = false 
)
bool RS_MarkStoryLineEventResearched ( const char *  techID)

Pick a random base to research a story line event tech

Parameters
techIDThe event technology script id to research
Note
If there is no base available the tech is not marked as researched, too

Definition at line 773 of file cp_research.cpp.

References B_GetNext(), RS_GetTechByID(), RS_IsResearched_ptr(), and RS_MarkResearched().

Referenced by CP_CheckCampaignEvents().

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

Parses one "tech" entry in the research.ufo file and writes it into the next free entry in technologies (technology_t).

Parameters
[in]nameUnique id of a technology_t. This is parsed from "tech xxx" -> id=xxx
[in]textthe whole following text that is part of the "tech" item definition in research.ufo.
See also
CL_ParseScriptFirst
GAME_SetMode
Note
write into cp_campaignPool - free on every game restart and reparse
Todo:
use cgi->Com_RegisterConstInt();

Definition at line 1133 of file cp_research.cpp.

References _, requirement_s::amount, ccs, cgi, cgame_import_s::Com_EParse(), Com_HashKey(), Com_Parse(), cp_campaignPool, linkedList_t::data, DEBUG_CLIENT, technology_s::description, ERR_DROP, pediaChapter_s::first, hash, technology_s::hashNext, technology_s::hashProvidedNext, i, pediaChapter_s::id, requirement_s::id, technology_s::id, technology_s::idx, pediaChapter_s::last, requirements_s::links, technology_s::mail, MAX_DESCRIPTIONS, MAX_TECHLINKS, MAX_TECHNOLOGIES, techMail_s::model, linkedList_t::next, ccs_s::numChapters, technologyDescriptions_s::numDescriptions, requirements_s::numLinks, technology_s::numTechMails, ccs_s::numTechnologies, OBJZERO, technology_s::overallTime, cgame_import_s::PoolStrDup(), technology_s::preDescription, technology_s::provides, Q_streq, technology_s::requireAND, technology_s::requireForProduction, technology_s::requireOR, RS_ALIEN, RS_ARMOUR, RS_BUILDING, RS_CRAFT, RS_CRAFTITEM, RS_LINK_ALIEN, RS_LINK_ALIEN_DEAD, RS_LINK_ALIEN_GLOBAL, RS_LINK_ANTIMATTER, RS_LINK_ITEM, RS_LINK_TECH, RS_LINK_TECH_NOT, RS_LINK_UFO, RS_LOGIC, RS_NEWS, RS_NONE, RS_TECH, RS_UGV, RS_WEAPON, technology_s::statusResearch, technology_s::statusResearchable, Sys_Error(), technologyDescriptions_s::tech, TECH_HASH_SIZE, TECHMAIL_MAX, TECHMAIL_PRE, TECHMAIL_RESEARCHED, ccs_s::technologies, technologyDescriptions_s::text, technology_s::time, requirement_s::type, technology_s::type, technology_s::upChapter, ccs_s::upChapters, technology_s::upNext, technology_s::upPrev, and technologyDescriptions_s::usedDescription.

Referenced by CP_ParseScriptFirst().

void RS_RemoveFiredScientist ( base_t base,
Employee employee 
)

Remove one scientist from research project if needed.

Parameters
[in]basePointer to base where a scientist should be removed.
[in]employeePointer to the employee that is fired.
Note
used when a scientist is fired.
This function is called before the employee is actually fired.

Definition at line 730 of file cp_research.cpp.

References cgi, Employee::chr, E_GetUnassignedEmployee(), EMPL_SCIENTIST, base_s::idx, RS_AssignScientist(), RS_GetTechWithMostScientists(), RS_RemoveScientist(), Employee::setAssigned(), and character_s::ucn.

Referenced by Employee::unassign().

void RS_RemoveScientist ( technology_t tech,
Employee employee 
)

Remove a scientist from a technology.

Parameters
[in]techThe technology you want to remove the scientist from.
[in]employeeEmployee you want to remove (nullptr if you don't care which one should be removed).
See also
RS_RemoveScientist_f
RS_AssignScientist

Definition at line 694 of file cp_research.cpp.

References technology_s::base, CAP_AddCurrent(), CAP_LABSPACE, cgi, E_GetAssignedEmployee(), EMPL_SCIENTIST, RS_PAUSED, technology_s::scientists, Employee::setAssigned(), and technology_s::statusResearch.

Referenced by RS_Change_f(), RS_RemoveFiredScientist(), RS_RemoveScientistsExceedingCapacity(), and RS_StopResearch().

void RS_RemoveScientistsExceedingCapacity ( base_t base)

Remove all exceeding scientist.

Parameters
[in,out]basePointer to base where a scientist should be removed.

Definition at line 1706 of file cp_research.cpp.

References CAP_GetFreeCapacity(), CAP_LABSPACE, CAP_SetCurrent(), RS_CountScientistsInBase(), RS_GetTechWithMostScientists(), and RS_RemoveScientist().

Referenced by CAP_CheckOverflow().

void RS_RequiredLinksAssign ( void  )

Assign Link pointers to all required techs/items/etc...

Note
This replaces the RS_InitRequirementList function (since the switch to the _OR and _AND list)

< Use this so we do not change the original redirectedTechs pointer.

Definition at line 419 of file cp_research.cpp.

References ccs, cgi, linkedList_t::data, i, linkedList_t::next, requirements_s::numLinks, ccs_s::numTechnologies, technology_s::redirect, redirectedTechs, technology_s::requireAND, technology_s::requireForProduction, technology_s::requireOR, RS_AssignTechLinks(), RS_GetTechByID(), and RS_GetTechByIDX().

Referenced by CP_ParseCampaignData().

bool RS_RequirementsMet ( const technology_t tech,
const struct base_s base 
)
void RS_ResearchFinish ( technology_t tech)

Sets a technology status to researched and updates the date.

Parameters
[in]techThe technology that was researched.

At this point we define what research-report description is used when displayed. (i.e. "usedDescription" is set here). That's because this is the first the player will see the research result and any later changes may make the content inconsistent for the player.

See also
RS_MarkOneResearchable

Definition at line 51 of file cp_research.cpp.

References _, technology_s::announce, ccs, cgi, Com_sprintf(), cp_messageBuffer, ccs_s::date, technology_s::description, technology_s::finishedResearchEvent, technology_s::id, technology_s::mailSent, MAILSENT_FINISHED, MSG_RESEARCH_FINISHED, MSO_CheckAddNewMessage(), technology_s::name, NT_RESEARCH_COMPLETED, technology_s::preDescription, technology_s::preResearchedDate, technology_s::researchedDate, RS_FINISH, RS_GetDescription(), RS_LOGIC, RS_StopResearch(), technology_s::statusResearch, technology_s::statusResearchable, technology_s::type, UP_OpenWith(), and technologyDescriptions_s::usedDescription.

Referenced by RS_InitTree(), RS_MarkResearchable(), and RS_MarkResearched().

int RS_ResearchRun ( void  )
void RS_ResetTechs ( void  )

This is called everytime RS_ParseTechnologies is called - to prevent cyclic hash tables.

Definition at line 1082 of file cp_research.cpp.

References cgi, and OBJZERO.

Referenced by CP_ResetCampaignData().

bool RS_ScriptSanityCheck ( void  )

Checks the parsed tech data for errors.

Returns
false if there are errors - true otherwise
Todo:
error++; Crafts still give errors - are there any definitions missing?

Definition at line 1845 of file cp_research.cpp.

References ccs, cgi, technology_s::description, i, technology_s::id, technology_s::name, ccs_s::numTechnologies, technology_s::produceTime, technology_s::provides, RS_ALIEN, RS_BUILDING, RS_LOGIC, RS_NEWS, RS_TECH, ccs_s::technologies, technologyDescriptions_s::text, and technology_s::type.

void RS_StopResearch ( technology_t tech)

Stops a research (Removes scientists from it)

Parameters
[in]techThe technology that is being researched.

Definition at line 93 of file cp_research.cpp.

References RS_RemoveScientist(), and technology_s::scientists.

Referenced by B_AddToStorage(), RS_CheckRequirements(), RS_ResearchFinish(), RS_ResearchRun(), and RS_Stop_f().

void UP_UGVDescription ( const struct ugv_s ugvType)

Referenced by BS_ShowInfo_f().