/** * @brief Display the popup_homebase * @param[in] aircraft Pointer to aircraft we want to change homebase. * @param[in] alwaysDisplay False if popup should be displayed only if at least one base is available. * @return true if popup is displayed. */ qboolean CL_DisplayHomebasePopup (aircraft_t *aircraft, qboolean alwaysDisplay) { int homebase; int numAvailableBases = 0; baseCapacities_t capacity; linkedList_t* popupListText = NULL; base_t *base; assert(aircraft); capacity = AIR_GetCapacityByAircraftWeight(aircraft); LIST_Delete(&popupListData); popupNum = 0; homebase = -1; base = NULL; while ((base = B_GetNext(base)) != NULL) { char text[MAX_VAR]; char const* msg; if (base == aircraft->homebase) { msg = _("current homebase of aircraft"); LIST_Add(&popupListData, (byte *)&INVALID_BASE, sizeof(int)); homebase = popupNum; } else { msg = AIR_CheckMoveIntoNewHomebase(aircraft, base, capacity); if (!msg) { msg = _("base can hold aircraft"); LIST_Add(&popupListData, (byte *)&base->idx, sizeof(int)); numAvailableBases++; } else { LIST_Add(&popupListData, (byte *)&INVALID_BASE, sizeof(int)); } } Com_sprintf(text, sizeof(text), "%s\t%s", base->name, msg); LIST_AddString(&popupListText, text); popupNum++; } if (alwaysDisplay || numAvailableBases > 0) { CL_GameTimeStop(); popupListNode = UI_PopupList(_("Change homebase of aircraft"), _("Base\tStatus"), popupListText, "change_homebase <lineselected>;"); VectorSet(popupListNode->selectedColor, 0.0, 0.78, 0.0); /**< Set color for selected entry. */ popupListNode->selectedColor[3] = 1.0; UI_TextNodeSelectLine(popupListNode, homebase); MAP_SelectAircraft(aircraft); return qtrue; } return qfalse; }
/** * @brief Build a new installation * @param[in] installationTemplate Template pointer * @param[in] pos Position on Globe to build at * @param[in] name The name of the installation - might already be in utf-8 */ installation_t* INS_Build (const installationTemplate_t *installationTemplate, const vec2_t pos, const char *name) { installation_t installation; const int newInstallationAlienInterest = 1.0f; OBJZERO(installation); Vector2Copy(pos, installation.pos); Q_strncpyz(installation.name, name, sizeof(installation.name)); installation.idx = ccs.campaignStats.installationsBuilt; installation.installationStatus = INSTALLATION_UNDER_CONSTRUCTION; installation.installationTemplate = installationTemplate; installation.buildStart = ccs.date.day; /* a new installation is not discovered (yet) */ installation.alienInterest = newInstallationAlienInterest; /* intialise hit points */ installation.installationDamage = installation.installationTemplate->maxDamage; /* Reset Radar */ RADAR_Initialise(&(installation.radar), 0.0f, 0.0f, 0.0f, qfalse); ccs.campaignStats.installationsBuilt++; return (installation_t*)(LIST_Add(&ccs.installations, (void*)&installation, sizeof(installation)))->data; }
/** * @brief Creates an entry of a new employee in the global list and assignes it to no building/base. * @param[in] type What type of employee to create. * @param[in] nation What nation the employee (mainly used for soldiers in singleplayer) comes from. * @param[in] ugvType What type of ugv this employee is. * @return Pointer to the newly created employee in the global list. NULL if something goes wrong. * @sa E_DeleteEmployee */ employee_t* E_CreateEmployee (employeeType_t type, const nation_t *nation, const ugv_t *ugvType) { employee_t employee; const char *teamID; char teamDefName[MAX_VAR]; const char* rank; if (type >= MAX_EMPL) return NULL; OBJZERO(employee); employee.baseHired = NULL; employee.assigned = qfalse; employee.type = type; employee.nation = nation; employee.ugv = ugvType; teamID = GAME_GetTeamDef(); /* Generate character stats, models & names. */ switch (type) { case EMPL_SOLDIER: rank = "rifleman"; Q_strncpyz(teamDefName, teamID, sizeof(teamDefName)); break; case EMPL_SCIENTIST: rank = "scientist"; Com_sprintf(teamDefName, sizeof(teamDefName), "%s_scientist", teamID); break; case EMPL_PILOT: rank = "pilot"; Com_sprintf(teamDefName, sizeof(teamDefName), "%s_pilot", teamID); break; case EMPL_WORKER: rank = "worker"; Com_sprintf(teamDefName, sizeof(teamDefName), "%s_worker", teamID); break; case EMPL_ROBOT: if (!ugvType) Com_Error(ERR_DROP, "CL_GenerateCharacter: no type given for generation of EMPL_ROBOT employee."); rank = "ugv"; Com_sprintf(teamDefName, sizeof(teamDefName), "%s%s", teamID, ugvType->actors); break; default: Com_Error(ERR_DROP, "Unknown employee type\n"); } CL_GenerateCharacter(&employee.chr, teamDefName); employee.chr.score.rank = CL_GetRankIdx(rank); Com_DPrintf(DEBUG_CLIENT, "Generate character for type: %i\n", type); return (employee_t*) LIST_Add(&ccs.employees[type], (void*) &employee, sizeof(employee))->data; }
struct World * Server_LoadWorld(struct Server * server, char * filePath) { printf("Attempting to read world file at %s\n", filePath); struct World * world; World_Construct(filePath, &world); printf("Loading...\n"); World_Load(world); LIST_Add(server->worlds, world); // World_Destroy(world); //add to list return NULL; }
static void testLinkedList (void) { linkedList_t *list = NULL; const char* data = "SomeDataForTheLinkedList"; const size_t length = strlen(data); linkedList_t *entry; const linkedList_t *entry2; const char *returnedData; entry = LIST_Add(&list, (const byte*)data, length); CU_ASSERT_EQUAL(LIST_Count(list), 1); CU_ASSERT_TRUE(entry != NULL); returnedData = (const char *)LIST_GetByIdx(list, 0); CU_ASSERT_TRUE(returnedData != NULL); entry2 = LIST_ContainsString(list, returnedData); CU_ASSERT_TRUE(entry2 != NULL); CU_ASSERT_EQUAL((const void*)entry2->data, (const void*)returnedData); CU_ASSERT_STRING_EQUAL(entry2->data, returnedData); LIST_RemoveEntry(&list, entry); CU_ASSERT_EQUAL(LIST_Count(list), 0); }
/** * @brief Load callback for savegames * @param[in] p XML Node structure, where we get the information from * @sa INS_SaveXML * @sa SAV_GameLoadXML * @sa INS_LoadItemSlots */ qboolean INS_LoadXML (xmlNode_t *p) { xmlNode_t *n = XML_GetNode(p, SAVE_INSTALLATION_INSTALLATIONS); xmlNode_t *s; int i = 0; qboolean success = qtrue; if (!n) return qfalse; Com_RegisterConstList(saveInstallationConstants); for (s = XML_GetNode(n, SAVE_INSTALLATION_INSTALLATION); s; s = XML_GetNextNode(s,n, SAVE_INSTALLATION_INSTALLATION), i++) { xmlNode_t *ss; installation_t inst; installation_t *instp; const char *instID = XML_GetString(s, SAVE_INSTALLATION_TEMPLATEID); const char *instStat = XML_GetString(s, SAVE_INSTALLATION_STATUS); inst.idx = XML_GetInt(s, SAVE_INSTALLATION_IDX, -1); if (inst.idx < 0) { /** @todo fallback code for compatibility */ inst.idx = i; } inst.installationTemplate = INS_GetInstallationTemplateFromInstallationID(instID); if (!inst.installationTemplate) { Com_Printf("Could not find installation template '%s'\n", instID); success = qfalse; break; } if (!Com_GetConstIntFromNamespace(SAVE_INSTALLATIONSTATUS_NAMESPACE, instStat, (int*) &inst.installationStatus)) { Com_Printf("Invalid installation status '%s'\n", instStat); success = qfalse; break; } Q_strncpyz(inst.name, XML_GetString(s, SAVE_INSTALLATION_NAME), sizeof(inst.name)); XML_GetPos3(s, SAVE_INSTALLATION_POS, inst.pos); inst.installationDamage = XML_GetInt(s, SAVE_INSTALLATION_DAMAGE, 0); inst.alienInterest = XML_GetFloat(s, SAVE_INSTALLATION_ALIENINTEREST, 0.0); inst.buildStart = XML_GetInt(s, SAVE_INSTALLATION_BUILDSTART, 0); /* Radar */ RADAR_InitialiseUFOs(&inst.radar); RADAR_Initialise(&(inst.radar), 0.0f, 0.0f, 1.0f, qtrue); if (inst.installationStatus == INSTALLATION_WORKING) { RADAR_UpdateInstallationRadarCoverage(&inst, inst.installationTemplate->radarRange, inst.installationTemplate->trackingRange); /* UFO Yard */ inst.ufoCapacity.max = inst.installationTemplate->maxUFOsStored; } else { inst.ufoCapacity.max = 0; } inst.ufoCapacity.cur = 0; /* read battery slots */ ss = XML_GetNode(s, SAVE_INSTALLATION_BATTERIES); if (!ss) { Com_Printf("INS_LoadXML: Batteries not defined!\n"); success = qfalse; break; } inst.numBatteries = XML_GetInt(ss, SAVE_INSTALLATION_NUM, 0); if (inst.numBatteries > inst.installationTemplate->maxBatteries) { Com_Printf("Installation has more batteries than possible, using upper bound\n"); inst.numBatteries = inst.installationTemplate->maxBatteries; } instp = (installation_t*)(LIST_Add(&ccs.installations, (void*)&inst, sizeof(inst)))->data; BDEF_InitialiseInstallationSlots(instp); B_LoadBaseSlotsXML(instp->batteries, instp->numBatteries, ss); } Com_UnregisterConstList(saveInstallationConstants); Cvar_Set("mn_installation_count", va("%i", INS_GetCount())); return success; }
void Connection_AddToServer(struct Connection * connection, struct Server * server) { connection->id = LIST_Add(server->connections, connection); connection->server = server; }