26 #include "../client.h"
29 #include "../cl_inventory.h"
30 #include "../../shared/parse.h"
31 #include "../cl_team.h"
32 #include "../ui/ui_main.h"
33 #include "../ui/ui_popup.h"
34 #include "../ui/node/ui_node_container.h"
39 #define TEAM_SAVE_FILE_VERSION 4
55 for (
int i = 0;
i < teamSize;
i++)
96 if (ucn == chrTmp->ucn) {
134 Q_strcat(buf,
sizeof(buf),
"%s", team);
148 Q_strncpyz(pattern, relSavePath,
sizeof(pattern));
149 Q_strcat(pattern,
sizeof(pattern),
"*.mpt");
156 const char* savePath =
va(
"%s/%s", relSavePath, filename);
159 Com_Printf(
"Warning: Could not open '%s'\n", filename);
163 const int clen =
sizeof(header);
164 if (
FS_Read(&header, clen, &f) != clen) {
165 Com_Printf(
"Warning: Could not read %i bytes from savefile\n", clen);
169 Com_Printf(
"Warning: Version mismatch in '%s'\n", filename);
175 const bool uploadable =
FS_FileExists(
"%s/%s", absSavePath, filename);
247 const int requiredBufferLength = mxmlSaveString(topNode, dummy, 2, MXML_NO_CALLBACK);
254 Com_Printf(
"Error: Could not allocate enough memory to save this game\n");
257 mxmlSaveString(topNode, (
char*)buf, requiredBufferLength + 1, MXML_NO_CALLBACK);
261 memcpy(fbuf, &header,
sizeof(header));
262 memcpy(fbuf +
sizeof(header), buf, requiredBufferLength + 1);
266 FS_WriteFile(fbuf, requiredBufferLength + 1 +
sizeof(header), filename);
284 for (
int num = 0; num < 100; num++) {
285 Com_sprintf(filename, size,
"%s/team%02i.mpt", buf, num);
304 UI_Popup(
_(
"Note"),
_(
"Error saving team. Nothing to save yet."));
310 name =
_(
"New Team");
314 UI_Popup(
_(
"Note"),
_(
"Error saving team. Too many teams!"));
319 UI_Popup(
_(
"Note"),
_(
"Error saving team. Check free disk space!"));
331 Com_Printf(
"Couldn't open file '%s'\n", filename);
337 if (
FS_Read(cbuf, clen, &f) != clen) {
338 Com_Printf(
"Warning: Could not read %i bytes from savefile\n", clen);
344 memcpy(&header, cbuf,
sizeof(header));
360 Com_Printf(
"Error: Failure in loading the xml data!");
422 Com_sprintf(pattern,
sizeof(pattern),
"%s*.mpt", buf);
435 Com_sprintf(filename, filenameLength,
"%s/%s", buf, save);
472 Com_Printf(
"Could not get the file for the index: %i\n", index);
506 game_inventory.
init();
542 if (ucn == chrTmp->ucn) {
571 assert(item->
def() !=
nullptr);
597 Item* item =
nullptr;
625 for (i = 0; i <
CID_MAX; i++) {
631 Com_Printf(
"Invalid container id '%s'\n", contID);
636 if (item->
def() ==
nullptr) {
675 if (item.
def() ==
nullptr)
678 if (
INVDEF(container)->temp)
679 Com_Error(
ERR_DROP,
"GAME_LoadInventory failed, tried to add '%s' to a temp container %i", item.
def()->
id, container);
682 Com_Printf(
"GAME_LoadInventory: Item %s exceeds weight capacity\n", item.
def()->
id);
685 Com_Printf(
"Could not add item '%s' to inventory\n", item.
def() ? item.
def()->
id :
"nullptr");
717 for (
int i = 0;
i < implants;
i++) {
719 if (implant.
def ==
nullptr)
745 || (k < SKILL_NUM_TYPES && score->skills[k])) {
754 const int skills = *(score->
skills + k);
755 const int improve = skills - initial;
797 chr->
bodySkin = std::min(maxSkins, bodySkin);
820 if (bodyPartId[0] !=
'\0') {
826 Com_Printf(
"GAME_LoadCharacter: Body part id not found while loading character wounds, must be an old save\n");
830 Com_Printf(
"GAME_LoadCharacter: Invalid body part id '%s' for %s (ucn: %i)\n", bodyPartId, chr->
name, chr->
ucn);
856 Com_Printf(
"Invalid skill type '%s' for %s (ucn: %i)\n", type, chr->
name, chr->
ucn);
880 Com_Printf(
"Invalid kill type '%s' for %s (ucn: %i)\n", type, chr->
name, chr->
ucn);
#define SAVE_INVENTORY_ROTATED
equipDef_t * GAME_GetEquipmentDefinition(void)
bool Q_strnull(const char *string)
bool R_ModelExists(const char *name)
const char * Cmd_Argv(int arg)
Returns a given argument.
void GAME_GenerateTeam(const char *teamDefID, const equipDef_t *ed, int teamMembers)
void CL_UpdateCharacterValues(const character_t *chr)
const char * FS_NextFileFromFileList(const char *files)
Returns the next file that is found in the virtual filesystem identified by the given file pattern...
#define SAVE_INVENTORY_INVENTORY
#define SAVE_CHARACTER_WOUNDTYPE
void destroyInventory(Inventory *const inv)
Destroys inventory.
void setAmmoLeft(int value)
bool Com_GetConstIntFromNamespace(const char *space, const char *variable, int *value)
Searches whether a given value was registered as a string to int mapping.
bool GAME_SaveCharacter(xmlNode_t *p, const character_t *chr)
saves a character to a given xml node
int FS_CheckFile(const char *fmt,...)
Just returns the filelength and -1 if the file wasn't found.
const objDef_t * INVSH_GetItemByID(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
QGL_EXTERN GLint GLenum type
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
#define SAVE_CHARACTER_PATH
static void GAME_LoadTeamInfo(xmlNode_t *p)
Loads the wholeTeam from the xml file.
#define SAVE_CHARACTER_MORALE
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
const teamDef_t * teamDef
void resetContainer(const containerIndex_t idx)
int experience[SKILL_NUM_TYPES+1]
#define SAVE_TEAM_CHARACTER
void GAME_TeamDelete_f(void)
Removes a user created team.
const char * GAME_GetAbsoluteSavePath(char *buf, size_t bufSize)
int XML_GetInt(xmlNode_t *parent, const char *name, const int defaultval)
retrieve an Int attribute from an XML Node
#define SAVE_CHARACTER_KILLS
#define SAVE_CHARACTER_HEAD_SKIN
#define SAVE_CHARACTER_IMPLANTS
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
bool FS_FileExists(const char *filename,...)
Checks whether a file exists (not in virtual filesystem)
#define SAVE_CHARACTER_SKILLS
#define SAVE_CHARACTER_IMPLANT_IMPLANT
#define SAVE_CHARACTER_TEAMDEF
Shared game type headers.
#define SAVE_CHARACTER_HP
#define SAVE_CHARACTER_MAXHP
const objDef_t * def(void) const
unsigned int CL_GetActorSkinCount(void)
Get number of registered actorskins.
void FS_RemoveFile(const char *osPath)
invDef_t ids[MAX_INVDEFS]
static bool characterActive[MAX_ACTIVETEAM]
#define TEAM_SAVE_FILE_VERSION
bool Com_GetCharacterModel(character_t *chr)
int stuns[KILLED_NUM_TYPES]
void UI_ContainerNodeUpdateEquipment(Inventory *inv, const equipDef_t *ed)
Fills the ground container of the ui_inventory with unused items from a given equipment definition...
void Com_Printf(const char *const fmt,...)
const char * CHRSH_CharGetBody(const character_t *const chr)
Returns the body model for the soldiers for armoured and non armoured soldiers.
void setDef(const objDef_t *objDef)
int FS_BuildFileList(const char *fileList)
Build a filelist.
Defines all attributes of objects used in the inventory.
void Com_RegisterConstList(const constListEntry_t constList[])
Registers a list of string aliases.
void GAME_TeamSlotComments_f(void)
Reads the comments from team files.
const equipDef_t * INV_GetEquipmentDefinitionByID(const char *name)
Gets equipment definition by id.
#define SAVE_CHARACTER_INITSKILL
#define SAVE_CHARACTER_UCN
#define SAVE_CHARACTER_STATE
const teamDef_t * Com_GetTeamDefinitionByID(const char *team)
Returns the teamDef pointer for the searched team id - or nullptr if not found in the teamDef array...
int GAME_GetChrMaxLoad(const character_t *chr)
Returns the max weight the given character can carry.
void GAME_AutoTeam_f(void)
bool GAME_GetTeamFileName(unsigned int index, char *filename, size_t filenameLength)
Get the filename for the xth team in the file system.
static void GAME_SaveInventory(xmlNode_t *p, const Inventory *inv)
Save callback for savegames in XML Format.
bool GAME_LoadCharacter(xmlNode_t *p, character_t *chr)
Loads a character from a given xml node.
int LIST_Count(const linkedList_t *list)
#define SAVE_CHARACTER_GENDER
memPool_t * cl_genericPool
static void GAME_SaveItem(xmlNode_t *p, const Item *item, containerIndex_t container, int x, int y)
Save one item.
const char * XML_GetString(xmlNode_t *parent, const char *name)
retrieve a String attribute from an XML Node
#define SAVE_INVENTORY_CONTAINER
#define SAVE_INVENTORY_AMOUNT
void Com_Error(int code, const char *fmt,...)
#define SAVE_CHARACTER_SCORE_ASSIGNEDMISSIONS
xmlNode_t * XML_AddNode(xmlNode_t *parent, const char *name)
add a new node to the XML tree
item instance data, with linked list capability
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
inventory definition with all its containers
bool LIST_Remove(linkedList_t **list, const void *data)
void XML_AddInt(xmlNode_t *parent, const char *name, int value)
add an Int attribute to the XML Node
#define SAVE_INVENTORY_MUNITIONID
void XML_AddString(xmlNode_t *parent, const char *name, const char *value)
add a String attribute to the XML Node
void GAME_ActorSelect_f(void)
#define SAVE_CHARACTER_SKILLIMPROVE
int treatmentLevel[BODYPART_MAXTYPE]
#define SAVE_CHARACTER_WOUNDSEVERITY
void UI_ResetData(int dataId)
Reset a shared data. Type became NONE and value became nullptr.
XML tag constants for savegame.
static bool GAME_LoadItem(xmlNode_t *n, Item *item, containerIndex_t *container, int *x, int *y)
Load one item.
#define SAVE_CHARACTER_IMPLANT_INSTALLEDTIME
int kills[KILLED_NUM_TYPES]
void GAME_ResetCharacters(void)
Reset all characters in the static character array.
static void GAME_SaveTeamInfo(xmlNode_t *p)
Stores the wholeTeam into a xml structure.
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
struct teamSaveFileHeader_s teamSaveFileHeader_t
int initialSkills[SKILL_NUM_TYPES+1]
#define SAVE_TEAM_EQUIPMENT
cgame team management headers.
#define SAVE_INVENTORY_WEAPONID
#define SAVE_CHARACTER_KILLED
int FS_WriteFile(const void *buffer, size_t len, const char *filename)
XML tag constants for team savegame.
static void GAME_GetEquipment(void)
Get the equipment definition (from script files) for the current selected team and updates the equipm...
const implantDef_t * INVSH_GetImplantByID(const char *id)
Returns the implant that belongs to the given id or nullptr if it wasn't found.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
static Inventory game_inventory
#define INVDEF(containerID)
Item * getEquipContainer() const
implant_t implants[MAX_CHARACTER_IMPLANTS]
void GAME_LoadTeam_f(void)
Loads the selected teamslot.
Item * getNextItem(const Item *prev) const
#define SAVE_CHARACTER_IMPLANT_REMOVETIME
#define SAVE_TEAM_ROOTNODE
#define SAVE_TEAM_NUMLOOSE
linkedList_t * chrDisplayList
List of currently displayed or equipable characters.
const char * CHRSH_CharGetHead(const character_t *const chr)
Returns the head model for the soldiers for armoured and non armoured soldiers.
bool GAME_LoadDefaultTeam(bool force)
#define SAVE_CHARACTER_SKILLTYPE_NAMESPACE
character_t * GAME_GetCharacter(int index)
Returns a character that can be used to store the game type specific character values.
bool canHoldItemWeight(containerIndex_t from, containerIndex_t to, const Item &item, int maxWeight) const
Check that adding an item to the inventory won't exceed the max permitted weight. ...
#define SAVE_CHARACTER_KILLTYPE
#define SAVE_CHARACTER_BDOY_SKIN
int FS_FileLength(qFILE *f)
Returns the size of a given file or -1 if no file is opened.
#define SAVE_CHARACTER_EXPERIENCE
Structure of all stats collected for an actor over time.
const char * Com_GetConstVariable(const char *space, int value)
Searches the mapping variable for a given integer value and a namespace.
#define Mem_PoolAllocTypeN(type, n, pool)
Item * addToInventory(Inventory *const inv, const Item *const item, const invDef_t *container, int x, int y, int amount) __attribute__((warn_unused_result))
Add an item to a specified container in a given inventory.
void GAME_SaveTeam_f(void)
Stores a team in a specified teamslot.
void GAME_ToggleActorForTeam_f(void)
This will activate/deactivate the actor for the team.
#define SAVE_CHARACTER_IMPLANT
int FS_Read(void *buffer, int len, qFILE *f)
short numBodyParts(void) const
bool isReloadable() const
static bool GAME_SaveTeam(const char *filename, const char *name)
Saves a team in xml format.
#define SAVE_CHARACTER_STUNNED
bool GAME_TeamGetFreeFilename(char *filename, size_t size)
Searches a free team filename.
size_t GAME_GetCharacterArraySize(void)
#define SAVE_CHARACTER_WOUND
#define SAVE_INVENTORY_AMMO
void GAME_UpdateTeamMenuParameters_f(void)
Displays actor info and equipment and unused items in proper (filter) category.
const Container * getNextCont(const Container *prev, bool inclTemp=false) const
int numItems[MAX_OBJDEFS]
void GAME_AutoTeam(const char *equipmentDefinitionID, int teamMembers)
bool GAME_IsTeamEmpty(void)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void setAmmoDef(const objDef_t *od)
const BodyData * bodyTemplate
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
const objDef_t * ammoDef(void) const
#define LIST_Foreach(list, type, var)
Iterates over a linked list, it's safe to delete the returned entry from the list while looping over ...
#define SAVE_CHARACTER_STUN
xmlNode_t * XML_GetNode(xmlNode_t *parent, const char *name)
Get first Node of the XML tree by name.
void setAmount(int value)
byte numItemsLoose[MAX_OBJDEFS]
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
#define SAVE_INVENTORY_ITEM
static void GAME_UpdateInventory(Inventory *inv, const equipDef_t *ed)
#define SAVE_CHARACTER_SKILLTYPE
#define SAVE_CHARACTER_HEAD
const char * id(void) const
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
#define SAVE_CHARACTER_FIELDSIZE
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
static void GAME_LoadInventory(xmlNode_t *p, Inventory *inv, int maxLoad)
Load callback for savegames in XML Format.
void XML_AddIntValue(xmlNode_t *parent, const char *name, int value)
add a non-zero Int attribute to the XML Node
#define SAVE_CHARACTER_SCORE_RANK
const char * GAME_GetRelativeSavePath(char *buf, size_t bufSize)
void GAME_SaveTeamState_f(void)
Will remove those actors that should not be used in the team.
#define NO_TEAM_SLOT_LOADED
actorSizeEnum_t fieldSize
const char * GAME_GetTeamDef(void)
int skills[SKILL_NUM_TYPES]
#define SAVE_CHARACTER_WOUNDEDPART
xmlNode_t * XML_GetNextNode(xmlNode_t *current, xmlNode_t *parent, const char *name)
Get next Node of the XML tree by name.
#define SAVE_CHARACTER_KILLTYPE_NAMESPACE
void setContainer(const containerIndex_t idx, Item *cont)
static void GAME_UpdateActiveTeamList(void)
static const constListEntry_t saveCharacterConstants[]
XML tag constants for savegame.
#define SAVE_CHARACTER_INJURIES
bool Com_UnregisterConstList(const constListEntry_t constList[])
Unregisters a list of string aliases.
#define SAVE_CHARACTER_BODY
static bool GAME_LoadTeam(const char *filename)
Load a team from an xml file.
void LIST_AddPointer(linkedList_t **listDest, void *data)
Adds just a pointer to a new or to an already existing linked list.
xmlNode_t * XML_Parse(const char *buffer)
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
#define SAVE_CHARACTER_NAME
Describes a character with all its attributes.
#define SAVE_CHARACTER_SCORES