UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_game_team.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.m
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "../client.h"
27#include "cl_game.h"
28#include "cl_game_team.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"
35#include "save_team.h"
36#include "save_character.h"
37#include "save_inventory.h"
38
39#define TEAM_SAVE_FILE_VERSION 4
40
43
44typedef struct teamSaveFileHeader_s {
45 uint32_t version;
46 uint32_t soldiercount;
47 char name[32];
48 uint32_t xmlSize;
50
51static void GAME_UpdateActiveTeamList (void)
52{
53 const int teamSize = LIST_Count(chrDisplayList);
55 for (int i = 0; i < teamSize; i++)
56 characterActive[i] = true;
57}
58
59void GAME_AutoTeam (const char* equipmentDefinitionID, int teamMembers)
60{
61 const equipDef_t* ed = INV_GetEquipmentDefinitionByID(equipmentDefinitionID);
62 const char* teamDefID = GAME_GetTeamDef();
63 cls.teamSaveSlotIndex = NO_TEAM_SLOT_LOADED;
64
65 GAME_GenerateTeam(teamDefID, ed, teamMembers);
66}
67
68void GAME_AutoTeam_f (void)
69{
70 if (Cmd_Argc() != 2) {
71 Com_Printf("Usage: %s <equipment-definition>\n", Cmd_Argv(0));
72 return;
73 }
74
77}
78
84{
85 if (Cmd_Argc() != 3) {
86 Com_Printf("Usage: %s <num> <value>\n", Cmd_Argv(0));
87 return;
88 }
89
90 const int ucn = atoi(Cmd_Argv(1));
91 const int value = atoi(Cmd_Argv(2));
92
93 int i = 0;
94 bool found = false;
96 if (ucn == chrTmp->ucn) {
97 found = true;
98 break;
99 }
100 i++;
101 }
102 if (!found)
103 return;
104
105 characterActive[i] = (value != 0);
106}
107
113{
114 int i = 0;
116 if (!characterActive[i++])
118 }
119}
120
125{
126 if (Cmd_Argc() != 2) {
127 Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0));
128 return;
129 }
130
131 const char* team = Cmd_Argv(1);
132 char buf[MAX_OSPATH];
134 Q_strcat(buf, sizeof(buf), "%s", team);
136}
137
142{
143 UI_ExecuteConfunc("teamsaveslotsclear");
144
145 char relSavePath[MAX_OSPATH];
146 GAME_GetRelativeSavePath(relSavePath, sizeof(relSavePath));
147 char pattern[MAX_OSPATH];
148 Q_strncpyz(pattern, relSavePath, sizeof(pattern));
149 Q_strcat(pattern, sizeof(pattern), "*.mpt");
150
151 FS_BuildFileList(pattern);
152 int i = 0;
153 const char* filename;
154 while ((filename = FS_NextFileFromFileList(pattern)) != nullptr) {
156 const char* savePath = va("%s/%s", relSavePath, filename);
157 FS_OpenFile(savePath, &f, FILE_READ);
158 if (!f) {
159 Com_Printf("Warning: Could not open '%s'\n", filename);
160 continue;
161 }
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);
166 continue;
167 }
169 Com_Printf("Warning: Version mismatch in '%s'\n", filename);
170 continue;
171 }
172
173 char absSavePath[MAX_OSPATH];
174 GAME_GetAbsoluteSavePath(absSavePath, sizeof(absSavePath));
175 const bool uploadable = FS_FileExists("%s/%s", absSavePath, filename);
176 UI_ExecuteConfunc("teamsaveslotadd %i \"%s\" \"%s\" %i %i", i++, filename, header.name, LittleLong(header.soldiercount), uploadable ? 1 : 0);
177 }
179}
180
193
200{
201 const size_t size = GAME_GetCharacterArraySize();
202
205
206 /* header */
207 int i = 0;
210 GAME_LoadCharacter(n, chr);
211 UI_ExecuteConfunc("team_memberadd %i \"%s\" \"%s\" \"%s\" %i", i, chr->name, chr->path, chr->head, chr->headSkin);
212 LIST_AddPointer(&chrDisplayList, (void*)chr);
213 }
214
216}
217
221static bool GAME_SaveTeam (const char* filename, const char* name)
222{
225
226 char* buf;
227 xmlNode_t* topNode = mxmlNewXML("1.0");
228 xmlNode_t* node = XML_AddNode(topNode, SAVE_TEAM_ROOTNODE);
229 OBJZERO(header);
232 Q_strncpyz(header.name, name, sizeof(header.name));
233
234 xmlNode_t* snode = XML_AddNode(node, SAVE_TEAM_NODE);
235 GAME_SaveTeamInfo(snode);
236
237 snode = XML_AddNode(node, SAVE_TEAM_EQUIPMENT);
238 for (int i = 0; i < csi.numODs; i++) {
239 const objDef_t* od = INVSH_GetItemByIDX(i);
240 if (ed->numItems[od->idx] || ed->numItemsLoose[od->idx]) {
241 xmlNode_t* ssnode = XML_AddNode(snode, SAVE_TEAM_ITEM);
242 XML_AddString(ssnode, SAVE_TEAM_ID, od->id);
243 XML_AddIntValue(ssnode, SAVE_TEAM_NUM, ed->numItems[od->idx]);
245 }
246 }
247
248 buf = mxmlSaveAllocString(topNode, nullptr);
249 mxmlDelete(topNode);
250 if (!buf) {
251 Com_Printf("Error: Could not allocate enough memory to save this game\n");
252 return false;
253 }
254 int requiredBufferLength = strlen(buf) + 1;
255 header.xmlSize = LittleLong(requiredBufferLength);
256
257 byte* const fbuf = Mem_PoolAllocTypeN(byte, requiredBufferLength + sizeof(header), cl_genericPool);
258 memcpy(fbuf, &header, sizeof(header));
259 memcpy(fbuf + sizeof(header), buf, requiredBufferLength);
260 free(buf);
261
262 /* last step - write data */
263 FS_WriteFile(fbuf, requiredBufferLength + sizeof(header), filename);
264 Mem_Free(fbuf);
265
266 return true;
267}
268
277{
278 char buf[MAX_OSPATH];
280
281 for (int num = 0; num < 100; num++) {
282 Com_sprintf(filename, size, "%s/team%02i.mpt", buf, num);
283 if (FS_CheckFile("%s", filename) == -1) {
284 return true;
285 }
286 }
287 return false;
288}
289
294{
295 if (Cmd_Argc() != 2) {
296 Com_Printf("Usage: %s <name>\n", Cmd_Argv(0));
297 return;
298 }
299
301 UI_Popup(_("Note"), _("Error saving team. Nothing to save yet."));
302 return;
303 }
304
305 const char* name = Cmd_Argv(1);
306 if (Q_strnull(name))
307 name = _("New Team");
308
309 char filename[MAX_OSPATH];
311 UI_Popup(_("Note"), _("Error saving team. Too many teams!"));
312 return;
313 }
314
316 UI_Popup(_("Note"), _("Error saving team. Check free disk space!"));
317}
318
322static bool GAME_LoadTeam (const char* filename)
323{
324 /* open file */
327 if (!f) {
328 Com_Printf("Couldn't open file '%s'\n", filename);
329 return false;
330 }
331
332 const int clen = FS_FileLength(&f);
333 byte* const cbuf = Mem_PoolAllocTypeN(byte, clen, cl_genericPool);
334 if (FS_Read(cbuf, clen, &f) != clen) {
335 Com_Printf("Warning: Could not read %i bytes from savefile\n", clen);
336 Mem_Free(cbuf);
337 return false;
338 }
339
341 memcpy(&header, cbuf, sizeof(header));
342 /* swap all int values if needed */
343 header.version = LittleLong(header.version);
344 header.xmlSize = LittleLong(header.xmlSize);
345
346 if (header.version != TEAM_SAVE_FILE_VERSION) {
347 Com_Printf("Invalid version number\n");
348 Mem_Free(cbuf);
349 return false;
350 }
351
352 Com_Printf("Loading team (size %d / %i)\n", clen, header.xmlSize);
353
354 xmlNode_t* topNode = XML_Parse((const char*)(cbuf + sizeof(header)));
355 Mem_Free(cbuf);
356 if (!topNode) {
357 Com_Printf("Error: Failure in loading the xml data!");
358 return false;
359 }
360
361 xmlNode_t* node = XML_GetNode(topNode, SAVE_TEAM_ROOTNODE);
362 if (!node) {
363 mxmlDelete(topNode);
364 Com_Printf("Error: Failure in loading the xml data! (node '" SAVE_TEAM_ROOTNODE "' not found)\n");
365 return false;
366 }
367
368 xmlNode_t* snode = XML_GetNode(node, SAVE_TEAM_NODE);
369 if (!snode) {
370 mxmlDelete(topNode);
371 Com_Printf("Error: Failure in loading the xml data! (node '" SAVE_TEAM_NODE "' not found)\n");
372 return false;
373 }
374 GAME_LoadTeamInfo(snode);
375
376 snode = XML_GetNode(node, SAVE_TEAM_EQUIPMENT);
377 if (!snode) {
378 mxmlDelete(topNode);
379 Com_Printf("Error: Failure in loading the xml data! (node '" SAVE_TEAM_EQUIPMENT "' not found)\n");
380 return false;
381 }
382
384 for (xmlNode_t* ssnode = XML_GetNode(snode, SAVE_TEAM_ITEM); ssnode; ssnode = XML_GetNextNode(ssnode, snode, SAVE_TEAM_ITEM)) {
385 const char* objID = XML_GetString(ssnode, SAVE_TEAM_ID);
386 const objDef_t* od = INVSH_GetItemByID(objID);
387
388 if (od) {
389 ed->numItems[od->idx] = XML_GetInt(snode, SAVE_TEAM_NUM, 0);
390 ed->numItemsLoose[od->idx] = XML_GetInt(snode, SAVE_TEAM_NUMLOOSE, 0);
391 }
392 }
393
394 Com_Printf("File '%s' loaded.\n", filename);
395
396 mxmlDelete(topNode);
397
398 return true;
399}
400
410bool GAME_GetTeamFileName (unsigned int index, char* filename, size_t filenameLength)
411{
412 const char* save;
413 /* we will loop the whole team save list, just because i don't want
414 * to specify the filename in the script api of this command. Otherwise
415 * one could upload everything with this command */
416 char buf[MAX_OSPATH];
418 char pattern[MAX_OSPATH];
419 Com_sprintf(pattern, sizeof(pattern), "%s*.mpt", buf);
420 const int amount = FS_BuildFileList(pattern);
421 Com_DPrintf(DEBUG_CLIENT, "found %i entries for %s\n", amount, pattern);
422 while ((save = FS_NextFileFromFileList(pattern)) != nullptr) {
423 if (index == 0)
424 break;
425 index--;
426 }
428 if (index > 0)
429 return false;
430 if (save == nullptr)
431 return false;
432 Com_sprintf(filename, filenameLength, "%s/%s", buf, save);
433 return true;
434}
435
436bool GAME_LoadDefaultTeam (bool force)
437{
438 if (cls.teamSaveSlotIndex == NO_TEAM_SLOT_LOADED) {
439 if (!force)
440 return false;
441 cls.teamSaveSlotIndex = 0;
442 }
443
444 char filename[MAX_OSPATH];
445 if (!GAME_GetTeamFileName(cls.teamSaveSlotIndex, filename, sizeof(filename)))
446 return false;
448 return true;
449 }
450
451 cls.teamSaveSlotIndex = NO_TEAM_SLOT_LOADED;
452 return false;
453}
454
459{
460 if (Cmd_Argc() != 2) {
461 Com_Printf("Usage: %s <slotindex>\n", Cmd_Argv(0));
462 return;
463 }
464
465 const int index = atoi(Cmd_Argv(1));
466
467 char filename[MAX_OSPATH];
469 Com_Printf("Could not get the file for the index: %i\n", index);
470 return;
471 }
473 cls.teamSaveSlotIndex = index;
474 } else {
475 cls.teamSaveSlotIndex = NO_TEAM_SLOT_LOADED;
476 }
477}
478
479static void GAME_UpdateInventory (Inventory* inv, const equipDef_t* ed)
480{
482 ui_inventory = &((character_t*)chrDisplayList->data)->inv;
483 else
484 ui_inventory = nullptr;
485
486 /* manage inventory */
488}
489
494static void GAME_GetEquipment (void)
495{
496 const char* equipmentName = Cvar_GetString("cl_equip");
497 /* search equipment definition */
498 const equipDef_t* edFromScript = INV_GetEquipmentDefinitionByID(equipmentName);
499
501 *ed = *edFromScript;
502
503 game_inventory.init();
505}
506
512{
513 /* reset description */
514 Cvar_Set("mn_itemname", "%s", "");
515 Cvar_Set("mn_item", "%s", "");
517
518 int i = 0;
519 UI_ExecuteConfunc("team_soldierlist_clear");
521 UI_ExecuteConfunc("team_soldierlist_add %d %d \"%s\"", chr->ucn, characterActive[i], chr->name);
522 i++;
523 }
524
526}
527
529{
530 /* check syntax */
531 if (Cmd_Argc() < 2) {
532 Com_Printf("Usage: %s <num>\n", Cmd_Argv(0));
533 return;
534 }
535
536 const int ucn = atoi(Cmd_Argv(1));
537 character_t* chr = nullptr;
539 if (ucn == chrTmp->ucn) {
540 chr = chrTmp;
541 break;
542 }
543 }
544 if (!chr)
545 return;
546
547 /* update menu inventory */
548 if (ui_inventory && ui_inventory != &chr->inv) {
549 chr->inv.setContainer(CID_EQUIP, ui_inventory->getEquipContainer());
550 /* set 'old' CID_EQUIP to nullptr */
551 ui_inventory->resetContainer(CID_EQUIP);
552 }
553 ui_inventory = &chr->inv;
554 /* set info cvars */
556}
557
566static void GAME_SaveItem (xmlNode_t* p, const Item* item, containerIndex_t container, int x, int y)
567{
568 assert(item->def() != nullptr);
569
577 if (item->getAmmoLeft() > NONE_AMMO) {
580 }
581}
582
590static void GAME_SaveInventory (xmlNode_t* p, const Inventory* inv)
591{
592 const Container* cont = nullptr;
593 while ((cont = inv->getNextCont(cont, false))) {
594 Item* item = nullptr;
595 while ((item = cont->getNextItem(item))) {
597 GAME_SaveItem(s, item, cont->id, item->getX(), item->getY());
598 }
599 }
600}
601
611static bool GAME_LoadItem (xmlNode_t* n, Item* item, containerIndex_t* container, int* x, int* y)
612{
613 const char* itemID = XML_GetString(n, SAVE_INVENTORY_WEAPONID);
614 const char* contID = XML_GetString(n, SAVE_INVENTORY_CONTAINER);
615
616 *x = XML_GetInt(n, SAVE_INVENTORY_X, 0);
617 *y = XML_GetInt(n, SAVE_INVENTORY_Y, 0);
618
619 /* reset */
620 OBJZERO(*item);
621 int i;
622 for (i = 0; i < CID_MAX; i++) {
623 if (Q_streq(csi.ids[i].name, contID))
624 break;
625 }
626 *container = i;
627 if (i >= CID_MAX) {
628 Com_Printf("Invalid container id '%s'\n", contID);
629 return false;
630 }
631
632 item->setDef(INVSH_GetItemByID(itemID));
633 if (item->def() == nullptr) {
634 return false;
635 }
639 if (item->getAmmoLeft() > NONE_AMMO) {
641 item->setAmmoDef(INVSH_GetItemByID(itemID));
642
643 /* reset ammo count if ammunition (item) not found */
644 if (!item->ammoDef())
645 item->setAmmoLeft(NONE_AMMO);
646 /* no ammo needed - fire definitions are in the item */
647 } else if (!item->isReloadable()) {
648 item->setAmmoDef(item->def());
649 }
650
651 return true;
652}
653
663static void GAME_LoadInventory (xmlNode_t* p, Inventory* inv, int maxLoad)
664{
666 Item item;
667 containerIndex_t container;
668 int x;
669 int y;
670
671 GAME_LoadItem(s, &item, &container, &x, &y);
672 if (item.def() == nullptr)
673 continue;
674
675 if (INVDEF(container)->temp)
676 Com_Error(ERR_DROP, "GAME_LoadInventory failed, tried to add '%s' to a temp container %i", item.def()->id, container);
677 /* ignore the overload for now */
678 if (!inv->canHoldItemWeight(CID_EQUIP, container, item, maxLoad))
679 Com_Printf("GAME_LoadInventory: Item %s exceeds weight capacity\n", item.def()->id);
680
681 if (!cls.i.addToInventory(inv, &item, INVDEF(container), x, y, 1))
682 Com_Printf("Could not add item '%s' to inventory\n", item.def() ? item.def()->id : "nullptr");
683 }
684}
685
692{
693 assert(chr);
695 /* Store the character data */
711
712 const int implants = lengthof(chr->implants);
714 for (int i = 0; i < implants; i++) {
715 const implant_t& implant = chr->implants[i];
716 if (implant.def == nullptr)
717 continue;
718
719 xmlNode_t* sImplant = XML_AddNode(sImplants, SAVE_CHARACTER_IMPLANT);
723 }
724
726 /* Store wounds */
727 for (int k = 0; k < chr->teamDef->bodyTemplate->numBodyParts(); ++k) {
728 if (!chr->wounds.treatmentLevel[k])
729 continue;
730 xmlNode_t* sWound = XML_AddNode(sInjuries, SAVE_CHARACTER_WOUND);
731
734 }
735
736 const chrScoreGlobal_t* score = &chr->score;
737
739 /* Store skills */
740 for (int k = 0; k <= SKILL_NUM_TYPES; k++) {
741 if (score->experience[k] || score->initialSkills[k]
742 || (k < SKILL_NUM_TYPES && score->skills[k])) {
744 const int initial = score->initialSkills[k];
745 const int experience = score->experience[k];
746
749 XML_AddIntValue(sSkill, SAVE_CHARACTER_EXPERIENCE, experience);
750 if (k < SKILL_NUM_TYPES) {
751 const int skills = *(score->skills + k);
752 const int improve = skills - initial;
754 }
755 }
756 }
757 /* Store kills */
758 for (int k = 0; k < KILLED_NUM_TYPES; k++) {
759 if (score->kills[k] || score->stuns[k]) {
764 }
765 }
768
769 /* Store inventories */
771 GAME_SaveInventory(sInventory, &chr->inv);
772
774 return true;
775}
776
783{
784 bool success = true;
785
786 /* Load the character data */
787 Q_strncpyz(chr->name, XML_GetString(p, SAVE_CHARACTER_NAME), sizeof(chr->name));
788 Q_strncpyz(chr->body, XML_GetString(p, SAVE_CHARACTER_BODY), sizeof(chr->body));
789 Q_strncpyz(chr->path, XML_GetString(p, SAVE_CHARACTER_PATH), sizeof(chr->path));
790 Q_strncpyz(chr->head, XML_GetString(p, SAVE_CHARACTER_HEAD), sizeof(chr->head));
791
792 const int maxSkins = CL_GetActorSkinCount() - 1;
793 const int bodySkin = XML_GetInt(p, SAVE_CHARACTER_BDOY_SKIN, 0);
794 chr->bodySkin = std::min(maxSkins, bodySkin);
797 chr->ucn = XML_GetInt(p, SAVE_CHARACTER_UCN, 0);
799 chr->HP = XML_GetInt(p, SAVE_CHARACTER_HP, 0);
800 chr->STUN = XML_GetInt(p, SAVE_CHARACTER_STUN, 0);
804
805 /* Team-definition */
806 const char* s = XML_GetString(p, SAVE_CHARACTER_TEAMDEF);
808 if (!chr->teamDef)
809 return false;
810
812 /* Load wounds */
813 for (xmlNode_t* sWound = XML_GetNode(sInjuries, SAVE_CHARACTER_WOUND); sWound; sWound = XML_GetNextNode(sWound, sInjuries, SAVE_CHARACTER_WOUND)) {
814 const char* bodyPartId = XML_GetString(sWound, SAVE_CHARACTER_WOUNDEDPART);
815 short bodyPart;
816
817 if (bodyPartId[0] != '\0') {
818 for (bodyPart = 0; bodyPart < chr->teamDef->bodyTemplate->numBodyParts(); ++bodyPart)
819 if (Q_streq(chr->teamDef->bodyTemplate->id(bodyPart), bodyPartId))
820 break;
821 } else {
823 Com_Printf("GAME_LoadCharacter: Body part id not found while loading character wounds, must be an old save\n");
824 bodyPart = XML_GetInt(sWound, SAVE_CHARACTER_WOUNDTYPE, NONE);
825 }
826 if (bodyPart < 0 || bodyPart >= chr->teamDef->bodyTemplate->numBodyParts()) {
827 Com_Printf("GAME_LoadCharacter: Invalid body part id '%s' for %s (ucn: %i)\n", bodyPartId, chr->name, chr->ucn);
828 return false;
829 }
831 }
832
834 /* Load implants */
835 int implantCnt = 0;
836 for (xmlNode_t* sImplant = XML_GetNode(sImplants, SAVE_CHARACTER_IMPLANT); sImplant; sImplant = XML_GetNextNode(sImplant, sImplants, SAVE_CHARACTER_IMPLANT)) {
837 implant_t& implant = chr->implants[implantCnt++];
840 const char* implantDefID = XML_GetString(sImplants, SAVE_CHARACTER_IMPLANT_IMPLANT);
841 implant.def = INVSH_GetImplantByID(implantDefID);
842 }
843
845
847 /* Load Skills */
848 for (xmlNode_t* sSkill = XML_GetNode(sScore, SAVE_CHARACTER_SKILLS); sSkill; sSkill = XML_GetNextNode(sSkill, sScore, SAVE_CHARACTER_SKILLS)) {
849 int idx;
850 const char* type = XML_GetString(sSkill, SAVE_CHARACTER_SKILLTYPE);
851
853 Com_Printf("Invalid skill type '%s' for %s (ucn: %i)\n", type, chr->name, chr->ucn);
854 success = false;
855 break;
856 }
857
860 if (idx < SKILL_NUM_TYPES) {
861 chr->score.skills[idx] = chr->score.initialSkills[idx];
862 chr->score.skills[idx] += XML_GetInt(sSkill, SAVE_CHARACTER_SKILLIMPROVE, 0);
863 }
864 }
865
866 if (!success) {
868 return false;
869 }
870
871 /* Load kills */
872 for (xmlNode_t* sKill = XML_GetNode(sScore, SAVE_CHARACTER_KILLS); sKill; sKill = XML_GetNextNode(sKill, sScore, SAVE_CHARACTER_KILLS)) {
873 int idx;
874 const char* type = XML_GetString(sKill, SAVE_CHARACTER_KILLTYPE);
875
877 Com_Printf("Invalid kill type '%s' for %s (ucn: %i)\n", type, chr->name, chr->ucn);
878 success = false;
879 break;
880 }
881 chr->score.kills[idx] = XML_GetInt(sKill, SAVE_CHARACTER_KILLED, 0);
882 chr->score.stuns[idx] = XML_GetInt(sKill, SAVE_CHARACTER_STUNNED, 0);
883 }
884
885 if (!success) {
887 return false;
888 }
889
892
893 cls.i.destroyInventory(&chr->inv);
895 GAME_LoadInventory(sInventory, &chr->inv, GAME_GetChrMaxLoad(chr));
896
898
899 const char* body = CHRSH_CharGetBody(chr);
900 const char* head = CHRSH_CharGetHead(chr);
901 if (!R_ModelExists(head) || !R_ModelExists(body)) {
902 if (!Com_GetCharacterModel(chr))
903 return false;
904 }
905
906 return true;
907}
#define LittleLong(X)
Definition byte.h:37
const char * CHRSH_CharGetBody(const character_t *const chr)
Returns the body model for the soldiers for armoured and non armoured soldiers.
const char * CHRSH_CharGetHead(const character_t *const chr)
Returns the head model for the soldiers for armoured and non armoured soldiers.
@ SKILL_NUM_TYPES
Definition chr_shared.h:51
@ KILLED_NUM_TYPES
Definition chr_shared.h:32
equipDef_t * GAME_GetEquipmentDefinition(void)
Definition cl_game.cpp:1423
bool GAME_IsTeamEmpty(void)
Definition cl_game.cpp:388
const char * GAME_GetAbsoluteSavePath(char *buf, size_t bufSize)
Definition cl_game.cpp:1417
size_t GAME_GetCharacterArraySize(void)
Definition cl_game.cpp:227
void GAME_GenerateTeam(const char *teamDefID, const equipDef_t *ed, int teamMembers)
Definition cl_game.cpp:276
character_t * GAME_GetCharacter(int index)
Returns a character that can be used to store the game type specific character values.
Definition cl_game.cpp:197
int GAME_GetChrMaxLoad(const character_t *chr)
Returns the max weight the given character can carry.
Definition cl_game.cpp:1577
const char * GAME_GetTeamDef(void)
Definition cl_game.cpp:1251
void GAME_ResetCharacters(void)
Reset all characters in the static character array.
Definition cl_game.cpp:244
const char * GAME_GetRelativeSavePath(char *buf, size_t bufSize)
Definition cl_game.cpp:1411
Shared game type headers.
bool GAME_SaveCharacter(xmlNode_t *p, const character_t *chr)
saves a character to a given xml node
static Inventory game_inventory
void GAME_SaveTeam_f(void)
Stores a team in a specified teamslot.
static void GAME_GetEquipment(void)
Get the equipment definition (from script files) for the current selected team and updates the equipm...
bool GAME_TeamGetFreeFilename(char *filename, size_t size)
Searches a free team filename.
void GAME_UpdateTeamMenuParameters_f(void)
Displays actor info and equipment and unused items in proper (filter) category.
void GAME_AutoTeam_f(void)
static bool GAME_LoadTeam(const char *filename)
Load a team from an xml file.
static void GAME_LoadInventory(xmlNode_t *p, Inventory *inv, int maxLoad)
Load callback for savegames in XML Format.
static bool GAME_SaveTeam(const char *filename, const char *name)
Saves a team in xml format.
void GAME_SaveTeamState_f(void)
Will remove those actors that should not be used in the team.
static bool characterActive[MAX_ACTIVETEAM]
void GAME_TeamDelete_f(void)
Removes a user created team.
static void GAME_SaveItem(xmlNode_t *p, const Item *item, containerIndex_t container, int x, int y)
Save one item.
void GAME_TeamSlotComments_f(void)
Reads the comments from team files.
static void GAME_SaveInventory(xmlNode_t *p, const Inventory *inv)
Save callback for savegames in XML Format.
#define TEAM_SAVE_FILE_VERSION
bool GAME_LoadDefaultTeam(bool force)
static void GAME_LoadTeamInfo(xmlNode_t *p)
Loads the wholeTeam from the xml file.
void GAME_ActorSelect_f(void)
static void GAME_SaveTeamInfo(xmlNode_t *p)
Stores the wholeTeam into a xml structure.
void GAME_AutoTeam(const char *equipmentDefinitionID, int teamMembers)
void GAME_ToggleActorForTeam_f(void)
This will activate/deactivate the actor for the team.
static bool GAME_LoadItem(xmlNode_t *n, Item *item, containerIndex_t *container, int *x, int *y)
Load one item.
void GAME_LoadTeam_f(void)
Loads the selected teamslot.
bool GAME_GetTeamFileName(unsigned int index, char *filename, size_t filenameLength)
Get the filename for the xth team in the file system.
bool GAME_LoadCharacter(xmlNode_t *p, character_t *chr)
Loads a character from a given xml node.
static void GAME_UpdateInventory(Inventory *inv, const equipDef_t *ed)
static void GAME_UpdateActiveTeamList(void)
cgame team management headers.
#define NO_TEAM_SLOT_LOADED
const equipDef_t * INV_GetEquipmentDefinitionByID(const char *name)
Gets equipment definition by id.
Header file for inventory handling and Equipment menu.
client_static_t cls
Definition cl_main.cpp:83
memPool_t * cl_genericPool
Definition cl_main.cpp:86
#define _(String)
Definition cl_shared.h:44
#define INVDEF(containerID)
Definition cl_shared.h:48
void CL_UpdateCharacterValues(const character_t *chr)
Definition cl_team.cpp:218
linkedList_t * chrDisplayList
List of currently displayed or equipable characters.
Definition cl_team.cpp:38
unsigned int CL_GetActorSkinCount(void)
Get number of registered actorskins.
Definition cl_team.cpp:63
short numBodyParts(void) const
const char * id(void) const
Item * getNextItem(const Item *prev) const
inventory definition with all its containers
Definition inv_shared.h:525
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.
void setContainer(const containerIndex_t idx, Item *cont)
Definition inv_shared.h:550
const Container * getNextCont(const Container *prev, bool inclTemp=false) const
item instance data, with linked list capability
Definition inv_shared.h:402
const objDef_t * ammoDef(void) const
Definition inv_shared.h:460
int getAmmoLeft() const
Definition inv_shared.h:466
int getX() const
Definition inv_shared.h:454
void setAmount(int value)
Definition inv_shared.h:438
void setAmmoDef(const objDef_t *od)
Definition inv_shared.h:435
int rotated
Definition inv_shared.h:412
int getAmount() const
Definition inv_shared.h:463
void setDef(const objDef_t *objDef)
Definition inv_shared.h:444
const objDef_t * def(void) const
Definition inv_shared.h:469
int getY() const
Definition inv_shared.h:457
bool isReloadable() const
Definition inv_shared.h:479
void setAmmoLeft(int value)
Definition inv_shared.h:441
Primary header for client.
const char * Cmd_Argv(int arg)
Returns a given argument.
Definition cmd.cpp:516
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
Definition cmd.cpp:505
csi_t csi
Definition common.cpp:39
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition common.cpp:440
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
#define ERR_DROP
Definition common.h:211
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition cvar.cpp:615
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
Definition cvar.cpp:210
#define DEBUG_CLIENT
Definition defines.h:59
#define NONE_AMMO
Definition defines.h:69
#define NONE
Definition defines.h:68
#define MAX_ACTIVETEAM
Definition defines.h:41
void FS_RemoveFile(const char *osPath)
Definition files.cpp:1692
int FS_CheckFile(const char *fmt,...)
Just returns the filelength and -1 if the file wasn't found.
Definition files.cpp:298
const char * FS_NextFileFromFileList(const char *files)
Returns the next file that is found in the virtual filesystem identified by the given file pattern.
Definition files.cpp:1081
int FS_WriteFile(const void *buffer, size_t len, const char *filename)
Definition files.cpp:1546
int FS_FileLength(qFILE *f)
Returns the size of a given file or -1 if no file is opened.
Definition files.cpp:91
int FS_Read(void *buffer, int len, qFILE *f)
Definition files.cpp:371
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
Definition files.cpp:162
int FS_BuildFileList(const char *fileList)
Build a filelist.
Definition files.cpp:962
bool FS_FileExists(const char *filename,...)
Checks whether a file exists (not in virtual filesystem).
Definition files.cpp:1583
#define MAX_OSPATH
Definition filesys.h:44
@ FILE_READ
Definition filesys.h:111
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
const implantDef_t * INVSH_GetImplantByID(const char *id)
Returns the implant that belongs to the given id or nullptr if it 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.
#define CID_MAX
Definition inv_shared.h:57
int32_t containerIndex_t
Definition inv_shared.h:46
#define CID_EQUIP
Definition inv_shared.h:56
voidpf void uLong size
Definition ioapi.h:42
const char * filename
Definition ioapi.h:41
voidpf void * buf
Definition ioapi.h:42
int LIST_Count(const linkedList_t *list)
Definition list.cpp:344
void LIST_AddPointer(linkedList_t **listDest, void *data)
Adds just a pointer to a new or to an already existing linked list.
Definition list.cpp:153
bool LIST_Remove(linkedList_t **list, const void *data)
Definition list.cpp:213
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
Definition list.cpp:335
#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 ...
Definition list.h:41
#define Mem_PoolAllocTypeN(type, n, pool)
Definition mem.h:42
#define Mem_Free(ptr)
Definition mem.h:35
Shared parsing functions.
QGL_EXTERN GLuint index
Definition r_gl.h:110
QGL_EXTERN GLfloat f
Definition r_gl.h:114
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
bool R_ModelExists(const char *name)
Definition r_model.cpp:177
XML tag constants for savegame.
#define SAVE_CHARACTER_SCORES
#define SAVE_CHARACTER_SCORE_ASSIGNEDMISSIONS
#define SAVE_CHARACTER_WOUNDSEVERITY
#define SAVE_CHARACTER_IMPLANT
#define SAVE_CHARACTER_KILLTYPE
#define SAVE_CHARACTER_INJURIES
#define SAVE_CHARACTER_KILLED
#define SAVE_CHARACTER_SKILLIMPROVE
#define SAVE_CHARACTER_HP
#define SAVE_CHARACTER_IMPLANT_IMPLANT
#define SAVE_CHARACTER_IMPLANT_INSTALLEDTIME
#define SAVE_CHARACTER_SKILLTYPE_NAMESPACE
#define SAVE_CHARACTER_MORALE
#define SAVE_CHARACTER_PATH
#define SAVE_CHARACTER_HEAD_SKIN
#define SAVE_CHARACTER_KILLS
#define SAVE_CHARACTER_EXPERIENCE
#define SAVE_CHARACTER_IMPLANT_REMOVETIME
#define SAVE_CHARACTER_FIELDSIZE
#define SAVE_CHARACTER_INITSKILL
#define SAVE_CHARACTER_HEAD
#define SAVE_CHARACTER_STATE
#define SAVE_CHARACTER_KILLTYPE_NAMESPACE
#define SAVE_CHARACTER_MAXHP
#define SAVE_CHARACTER_STUN
#define SAVE_CHARACTER_WOUNDTYPE
#define SAVE_CHARACTER_NAME
#define SAVE_CHARACTER_STUNNED
#define SAVE_CHARACTER_SKILLS
#define SAVE_CHARACTER_BODY
#define SAVE_CHARACTER_BDOY_SKIN
#define SAVE_CHARACTER_IMPLANTS
#define SAVE_CHARACTER_SKILLTYPE
#define SAVE_CHARACTER_UCN
#define SAVE_CHARACTER_SCORE_RANK
#define SAVE_CHARACTER_WOUNDEDPART
#define SAVE_CHARACTER_TEAMDEF
#define SAVE_CHARACTER_WOUND
static const constListEntry_t saveCharacterConstants[]
#define SAVE_CHARACTER_GENDER
XML tag constants for savegame.
#define SAVE_INVENTORY_MUNITIONID
#define SAVE_INVENTORY_AMMO
#define SAVE_INVENTORY_ITEM
#define SAVE_INVENTORY_WEAPONID
#define SAVE_INVENTORY_Y
#define SAVE_INVENTORY_ROTATED
#define SAVE_INVENTORY_AMOUNT
#define SAVE_INVENTORY_CONTAINER
#define SAVE_INVENTORY_X
#define SAVE_INVENTORY_INVENTORY
XML tag constants for team savegame.
#define SAVE_TEAM_ITEM
Definition save_team.h:33
#define SAVE_TEAM_NUM
Definition save_team.h:35
#define SAVE_TEAM_NUMLOOSE
Definition save_team.h:36
#define SAVE_TEAM_ROOTNODE
Definition save_team.h:27
#define SAVE_TEAM_EQUIPMENT
Definition save_team.h:32
#define SAVE_TEAM_ID
Definition save_team.h:34
#define SAVE_TEAM_NODE
Definition save_team.h:29
#define SAVE_TEAM_CHARACTER
Definition save_team.h:30
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.
Definition scripts.cpp:2345
bool Com_UnregisterConstList(const constListEntry_t constList[])
Unregisters a list of string aliases.
Definition scripts.cpp:237
bool Com_GetCharacterModel(character_t *chr)
Definition scripts.cpp:2358
bool Com_GetConstIntFromNamespace(const char *space, const char *variable, int *value)
Searches whether a given value was registered as a string to int mapping.
Definition scripts.cpp:103
const char * Com_GetConstVariable(const char *space, int value)
Searches the mapping variable for a given integer value and a namespace.
Definition scripts.cpp:122
void Com_RegisterConstList(const constListEntry_t constList[])
Registers a list of string aliases.
Definition scripts.cpp:253
#define Q_streq(a, b)
Definition shared.h:136
bool Q_strnull(const char *string)
Definition shared.h:138
#define OBJZERO(obj)
Definition shared.h:178
#define lengthof(x)
Definition shared.h:105
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition shared.cpp:457
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
Definition shared.cpp:475
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition shared.cpp:494
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...
Definition shared.cpp:410
Describes a character with all its attributes.
Definition chr_shared.h:388
const teamDef_t * teamDef
Definition chr_shared.h:413
char head[MAX_VAR]
Definition chr_shared.h:393
char path[MAX_VAR]
Definition chr_shared.h:391
chrScoreGlobal_t score
Definition chr_shared.h:406
actorSizeEnum_t fieldSize
Definition chr_shared.h:409
woundInfo_t wounds
Definition chr_shared.h:402
char body[MAX_VAR]
Definition chr_shared.h:392
char name[MAX_VAR]
Definition chr_shared.h:390
Inventory inv
Definition chr_shared.h:411
implant_t implants[MAX_CHARACTER_IMPLANTS]
Definition chr_shared.h:418
Structure of all stats collected for an actor over time.
Definition chr_shared.h:119
int initialSkills[SKILL_NUM_TYPES+1]
Definition chr_shared.h:123
int stuns[KILLED_NUM_TYPES]
Definition chr_shared.h:127
int kills[KILLED_NUM_TYPES]
Definition chr_shared.h:126
int skills[SKILL_NUM_TYPES]
Definition chr_shared.h:122
int experience[SKILL_NUM_TYPES+1]
Definition chr_shared.h:120
int numItems[MAX_OBJDEFS]
Definition inv_shared.h:608
byte numItemsLoose[MAX_OBJDEFS]
Definition inv_shared.h:609
int removedTime
Definition chr_shared.h:375
const implantDef_t * def
Definition chr_shared.h:373
int installedTime
Definition chr_shared.h:374
const char * id
Definition inv_shared.h:102
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
const char * id
Definition inv_shared.h:268
char id[MAX_VAR]
Definition chr_shared.h:309
const BodyData * bodyTemplate
Definition chr_shared.h:350
int treatmentLevel[BODYPART_MAXTYPE]
Definition chr_shared.h:363
void UI_ResetData(int dataId)
Reset a shared data. Type became NONE and value became nullptr.
Definition ui_data.cpp:212
@ TEXT_STANDARD
Definition ui_dataids.h:30
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
Definition ui_main.cpp:110
Inventory * ui_inventory
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 UI_Popup(const char *title, const char *text)
Popup on geoscape.
Definition ui_popup.cpp:47
xmlNode_t * XML_GetNextNode(xmlNode_t *current, xmlNode_t *parent, const char *name)
Get next Node of the XML tree by name.
Definition xml.cpp:508
void XML_AddString(xmlNode_t *parent, const char *name, const char *value)
add a String attribute to the XML Node
Definition xml.cpp:45
void XML_AddIntValue(xmlNode_t *parent, const char *name, int value)
add a non-zero Int attribute to the XML Node
Definition xml.cpp:204
int XML_GetInt(xmlNode_t *parent, const char *name, const int defaultval)
retrieve an Int attribute from an XML Node
Definition xml.cpp:317
const char * XML_GetString(xmlNode_t *parent, const char *name)
retrieve a String attribute from an XML Node
Definition xml.cpp:359
xmlNode_t * XML_Parse(const char *buffer)
Definition xml.cpp:544
xmlNode_t * XML_AddNode(xmlNode_t *parent, const char *name)
add a new node to the XML tree
Definition xml.cpp:286
void XML_AddInt(xmlNode_t *parent, const char *name, int value)
add an Int attribute to the XML Node
Definition xml.cpp:192
xmlNode_t * XML_GetNode(xmlNode_t *parent, const char *name)
Get first Node of the XML tree by name.
Definition xml.cpp:496
#define xmlNode_t
Definition xml.h:24