static void CampaignListTerminate(campaign_list_t *list) { CFREE(list->Name); CA_FOREACH(campaign_list_t, sublist, list->subFolders) CampaignListTerminate(sublist); CA_FOREACH_END() CArrayTerminate(&list->subFolders); CA_FOREACH(CampaignEntry, e, list->list) CampaignEntryTerminate(e); CA_FOREACH_END() CArrayTerminate(&list->list); }
void ConfigResetDefault(Config *c) { switch (c->Type) { case CONFIG_TYPE_STRING: CFREE(c->u.String.Value); if (c->u.String.Default != NULL) { CSTRDUP(c->u.String.Value, c->u.String.Default); } break; case CONFIG_TYPE_INT: c->u.Int.Value = c->u.Int.Default; break; case CONFIG_TYPE_FLOAT: c->u.Float.Value = c->u.Float.Default; break; case CONFIG_TYPE_BOOL: c->u.Bool.Value = c->u.Bool.Default; break; case CONFIG_TYPE_ENUM: c->u.Enum.Value = c->u.Enum.Default; break; case CONFIG_TYPE_GROUP: CA_FOREACH(Config, child, c->u.Group) ConfigResetDefault(child); CA_FOREACH_END() break; default: CASSERT(false, "Unknown config type"); break; } }
void JoyTerminate(CArray *joys) { CA_FOREACH(Joystick, j, *joys) JoyTerminateOne(j); CA_FOREACH_END() CArrayTerminate(joys); }
void AutosaveTerminate(Autosave *autosave) { CA_FOREACH(MissionSave, m, autosave->Missions) CampaignEntryTerminate(&m->Campaign); CA_FOREACH_END() CArrayTerminate(&autosave->Missions); }
static void AddMissionNodes(Autosave *a, json_t *root, const char *nodeName) { json_t *missions = json_new_array(); CA_FOREACH(MissionSave, m, a->Missions) json_insert_child(missions, CreateMissionNode(m)); CA_FOREACH_END() json_insert_pair_into_object(root, nodeName, missions); }
void AmmoClassesClear(CArray *ammo) { CA_FOREACH(Ammo, a, *ammo) CFREE(a->Name); CFREE(a->Sound); CFREE(a->DefaultGun); CA_FOREACH_END() CArrayClear(ammo); }
void ConfigDestroy(Config *c) { CFREE(c->Name); if (c->Type == CONFIG_TYPE_GROUP) { CA_FOREACH(Config, child, c->u.Group) ConfigDestroy(child); CA_FOREACH_END() CArrayTerminate(&c->u.Group); } }
void HUDPopupsUpdate(HUDNumPopups *popups, const int ms) { for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { NumPopupUpdate(&popups->score[i], ms); NumPopupUpdate(&popups->health[i], ms); NumPopupUpdate(&popups->ammo[i], ms); } CA_FOREACH(HUDNumPopup, p, popups->objective) NumPopupUpdate(p, ms); CA_FOREACH_END() }
void CampaignSettingTerminate(CampaignSetting *setting) { CFREE(setting->Title); CFREE(setting->Author); CFREE(setting->Description); CA_FOREACH(Mission, m, setting->Missions) MissionTerminate(m); CA_FOREACH_END() CArrayTerminate(&setting->Missions); CharacterStoreTerminate(&setting->characters); memset(setting, 0, sizeof *setting); }
static void DrawObjectiveHighlights(DrawBuffer *b, Vec2i offset) { Tile *tile = &b->tiles[0][0]; for (int y = 0; y < Y_TILES; y++) { for (int x = 0; x < b->Size.x; x++, tile++) { // Draw the items that are in LOS CA_FOREACH(ThingId, tid, tile->things) TTileItem *ti = ThingIdGetTileItem(tid); DrawObjectiveHighlight(ti, tile, b, offset); CA_FOREACH_END() } tile += X_TILES - b->Size.x; } }
void MissionOptionsTerminate(struct MissionOptions *mo) { ActorsTerminate(); ObjsTerminate(); MobObjsTerminate(); PickupsTerminate(); ParticlesTerminate(&gParticles); WatchesTerminate(); CA_FOREACH(PlayerData, p, gPlayerDatas) p->ActorUID = -1; CA_FOREACH_END() gMission.HasStarted = false; gMission.HasBegun = false; CArrayTerminate(&mo->Weapons); memset(mo, 0, sizeof *mo); }
static void ConfigSaveVisit(const Config *c, json_t *node) { switch (c->Type) { case CONFIG_TYPE_STRING: CASSERT(false, "not implemented"); break; case CONFIG_TYPE_INT: AddIntPair(node, c->Name, c->u.Int.Value); break; case CONFIG_TYPE_FLOAT: CASSERT(false, "not implemented"); break; case CONFIG_TYPE_BOOL: json_insert_pair_into_object( node, c->Name, json_new_bool(c->u.Bool.Value)); break; case CONFIG_TYPE_ENUM: JSON_UTILS_ADD_ENUM_PAIR( node, c->Name, c->u.Enum.Value, c->u.Enum.EnumToStr); break; case CONFIG_TYPE_GROUP: { json_t *child = node; // If the config has no name, then it is the root element // Add children directly to the node // Otherwise, create a new child if (c->Name != NULL) { child = json_new_object(); } CA_FOREACH(Config, cg, c->u.Group) ConfigSaveVisit(cg, child); CA_FOREACH_END() if (c->Name != NULL) { json_insert_pair_into_object(node, c->Name, child); } } break; default: CASSERT(false, "Unknown config type"); break; } }
static json_t *SaveStaticKeys(Mission *m) { json_t *keys = json_new_array(); CA_FOREACH(KeyPositions, kp, m->u.Static.Keys) json_t *keyNode = json_new_object(); AddIntPair(keyNode, "Index", kp->Index); json_t *positions = json_new_array(); for (int j = 0; j < (int)kp->Positions.size; j++) { Vec2i *pos = CArrayGet(&kp->Positions, j); json_insert_child(positions, SaveVec2i(*pos)); } json_insert_pair_into_object( keyNode, "Positions", positions); json_insert_child(keys, keyNode); CA_FOREACH_END() return keys; }
static json_t *SaveStaticCharacters(Mission *m) { json_t *chars = json_new_array(); CA_FOREACH(CharacterPositions, cp, m->u.Static.Characters) json_t *charNode = json_new_object(); AddIntPair(charNode, "Index", cp->Index); json_t *positions = json_new_array(); for (int j = 0; j < (int)cp->Positions.size; j++) { Vec2i *pos = CArrayGet(&cp->Positions, j); json_insert_child(positions, SaveVec2i(*pos)); } json_insert_pair_into_object( charNode, "Positions", positions); json_insert_child(chars, charNode); CA_FOREACH_END() return chars; }
static json_t *SaveStaticWrecks(Mission *m) { json_t *wrecks = json_new_array(); CA_FOREACH(MapObjectPositions, mop, m->u.Static.Wrecks) json_t *wreckNode = json_new_object(); AddStringPair(wreckNode, "MapObject", mop->M->Name); json_t *positions = json_new_array(); for (int j = 0; j < (int)mop->Positions.size; j++) { Vec2i *pos = CArrayGet(&mop->Positions, j); json_insert_child(positions, SaveVec2i(*pos)); } json_insert_pair_into_object( wreckNode, "Positions", positions); json_insert_child(wrecks, wreckNode); CA_FOREACH_END() return wrecks; }
static json_t *SaveStaticObjectives(Mission *m) { json_t *objs = json_new_array(); CA_FOREACH(ObjectivePositions, op, m->u.Static.Objectives) json_t *objNode = json_new_object(); AddIntPair(objNode, "Index", op->Index); json_t *positions = json_new_array(); for (int j = 0; j < (int)op->Positions.size; j++) { Vec2i *pos = CArrayGet(&op->Positions, j); json_insert_child(positions, SaveVec2i(*pos)); } json_insert_pair_into_object( objNode, "Positions", positions); json_insert_pair_into_object( objNode, "Indices", SaveIntArray(&op->Indices)); json_insert_child(objs, objNode); CA_FOREACH_END() return objs; }
Mix_Chunk *StrSound(const char *s) { if (s == NULL || strlen(s) == 0) { return NULL; } CA_FOREACH(SoundData, sound, gSoundDevice.customSounds) if (strcmp(sound->Name, s) == 0) { return sound->data; } CA_FOREACH_END() CA_FOREACH(SoundData, sound, gSoundDevice.sounds) if (strcmp(sound->Name, s) == 0) { return sound->data; } CA_FOREACH_END() return NULL; }
MapObject *StrMapObject(const char *s) { if (s == NULL || strlen(s) == 0) { return NULL; } CA_FOREACH(MapObject, c, gMapObjects.CustomClasses) if (strcmp(s, c->Name) == 0) { return c; } CA_FOREACH_END() CA_FOREACH(MapObject, c, gMapObjects.Classes) if (strcmp(s, c->Name) == 0) { return c; } CA_FOREACH_END() return NULL; }
void DrawObjectiveHighlights(DrawBuffer *b, const Vec2i offset) { if (!ConfigGetBool(&gConfig, "Graphics.ShowHUD")) { return; } Tile *tile = &b->tiles[0][0]; for (int y = 0; y < Y_TILES; y++) { for (int x = 0; x < b->Size.x; x++, tile++) { // Draw the items that are in LOS CA_FOREACH(ThingId, tid, tile->things) TTileItem *ti = ThingIdGetTileItem(tid); DrawObjectiveHighlight(ti, tile, b, offset); CA_FOREACH_END() } tile += X_TILES - b->Size.x; } }
int StrAmmoId(const char *s) { if (s == NULL || strlen(s) == 0) { return 0; } CA_FOREACH(Ammo, a, gAmmo.CustomAmmo) if (strcmp(s, a->Name) == 0) { return _ca_index + (int)gAmmo.Ammo.size; } CA_FOREACH_END() CA_FOREACH(Ammo, a, gAmmo.Ammo) if (strcmp(s, a->Name) == 0) { return _ca_index; } CA_FOREACH_END() CASSERT(false, "cannot parse ammo name"); return 0; }
// TODO: use map structure? BulletClass *StrBulletClass(const char *s) { if (s == NULL || strlen(s) == 0) { return NULL; } CA_FOREACH(BulletClass, b, gBulletClasses.CustomClasses) if (strcmp(s, b->Name) == 0) { return b; } CA_FOREACH_END() CA_FOREACH(BulletClass, b, gBulletClasses.Classes) if (strcmp(s, b->Name) == 0) { return b; } CA_FOREACH_END() CASSERT(false, "cannot parse bullet name"); return NULL; }
static json_t *SaveCharacters(CharacterStore *s) { json_t *charNode = json_new_array(); CA_FOREACH(Character, c, s->OtherChars) json_t *node = json_new_object(); AddStringPair(node, "Class", c->Class->Name); AddColorPair(node, "Skin", c->Colors.Skin); AddColorPair(node, "Arms", c->Colors.Arms); AddColorPair(node, "Body", c->Colors.Body); AddColorPair(node, "Legs", c->Colors.Legs); AddColorPair(node, "Hair", c->Colors.Hair); AddIntPair(node, "speed", c->speed); json_insert_pair_into_object( node, "Gun", json_new_string(c->Gun->name)); AddIntPair(node, "maxHealth", c->maxHealth); AddIntPair(node, "flags", c->flags); AddIntPair(node, "probabilityToMove", c->bot->probabilityToMove); AddIntPair(node, "probabilityToTrack", c->bot->probabilityToTrack); AddIntPair(node, "probabilityToShoot", c->bot->probabilityToShoot); AddIntPair(node, "actionDelay", c->bot->actionDelay); json_insert_child(charNode, node); CA_FOREACH_END() return charNode; }
static void ConfigLoadVisit(Config *c, json_t *node) { if (node == NULL) { fprintf(stderr, "Error loading config: node %s not found\n", c->Name); return; } switch (c->Type) { case CONFIG_TYPE_STRING: CASSERT(false, "not implemented"); break; case CONFIG_TYPE_INT: LoadInt(&c->u.Int.Value, node, c->Name); if (c->u.Int.Min > 0) c->u.Int.Value = MAX(c->u.Int.Value, c->u.Int.Min); if (c->u.Int.Max > 0) c->u.Int.Value = MIN(c->u.Int.Value, c->u.Int.Max); break; case CONFIG_TYPE_FLOAT: LoadDouble(&c->u.Float.Value, node, c->Name); if (c->u.Float.Min > 0) c->u.Float.Value = MAX(c->u.Float.Value, c->u.Float.Min); if (c->u.Float.Max > 0) c->u.Float.Value = MIN(c->u.Float.Value, c->u.Float.Max); break; case CONFIG_TYPE_BOOL: LoadBool(&c->u.Bool.Value, node, c->Name); break; case CONFIG_TYPE_ENUM: JSON_UTILS_LOAD_ENUM( c->u.Enum.Value, node, c->Name, c->u.Enum.StrToEnum); if (c->u.Enum.Min > 0) c->u.Enum.Value = MAX(c->u.Enum.Value, c->u.Enum.Min); if (c->u.Enum.Max > 0) c->u.Enum.Value = MIN(c->u.Enum.Value, c->u.Enum.Max); break; case CONFIG_TYPE_GROUP: { // If the config has no name, then it is the root element // Load children directly to the node // Otherwise, find the named child if (c->Name != NULL) { node = json_find_first_label(node, c->Name); if (node == NULL) { fprintf(stderr, "Error loading config: node %s not found\n", c->Name); return; } node = node->child; } CA_FOREACH(Config, child, c->u.Group) ConfigLoadVisit(child, node); CA_FOREACH_END() } break; default: CASSERT(false, "Unknown config type"); break; } }
void JoyReset(CArray *joys) { CA_FOREACH(Joystick, j, *joys) j->currentCmd = j->pressedCmd = j->previousCmd = 0; CA_FOREACH_END() }