static void LoadGunSpawners(CArray *classes, const CArray *guns) { for (int i = 0; i < (int)guns->size; i++) { const GunDescription *g = CArrayGet(guns, i); if (!g->IsRealGun) { continue; } MapObject m; memset(&m, 0, sizeof m); char buf[256]; sprintf(buf, "%s spawner", g->name); CSTRDUP(m.Name, buf); m.Normal.Pic = PicManagerGetPic(&gPicManager, "spawn_pad"); m.Normal.Offset = Vec2iNew( -m.Normal.Pic->size.x / 2, TILE_HEIGHT / 2 - m.Normal.Pic->size.y); m.Size = Vec2iNew(TILE_WIDTH, TILE_HEIGHT); m.Health = 0; m.Type = MAP_OBJECT_TYPE_PICKUP_SPAWNER; sprintf(buf, "gun_%s", g->name); m.u.PickupClass = StrPickupClass(buf); CArrayPushBack(classes, &m); } }
static void LoadMapObject(MapObject *m, json_t *node) { memset(m, 0, sizeof *m); m->Idx = -1; LoadInt(&m->Idx, node, "Index"); m->Name = GetString(node, "Name"); LoadPic(&m->Normal.Pic, node, "Pic", "OldPic"); LoadPic(&m->Wreck.Pic, node, "WreckPic", "OldWreckPic"); if (m->Normal.Pic) { // Default offset: centered X, align bottom of tile and sprite m->Normal.Offset = Vec2iNew( -m->Normal.Pic->size.x / 2, TILE_HEIGHT / 2 - m->Normal.Pic->size.y); LoadVec2i(&m->Normal.Offset, node, "Offset"); } if (m->Wreck.Pic) { m->Wreck.Offset = Vec2iScaleDiv(m->Wreck.Pic->size, -2); LoadVec2i(&m->Wreck.Offset, node, "WreckOffset"); } // Default tile size m->Size = Vec2iNew(TILE_WIDTH, TILE_HEIGHT); LoadVec2i(&m->Size, node, "Size"); LoadInt(&m->Health, node, "Health"); LoadBulletGuns(&m->DestroyGuns, node, "DestroyGuns"); json_t *flagsNode = json_find_first_label(node, "Flags"); if (flagsNode != NULL && flagsNode->child != NULL) { for (json_t *flagNode = flagsNode->child->child; flagNode; flagNode = flagNode->next) { m->Flags |= 1 << StrPlacementFlag(flagNode->text); } } // Special types JSON_UTILS_LOAD_ENUM(m->Type, node, "Type", StrMapObjectType); switch (m->Type) { case MAP_OBJECT_TYPE_NORMAL: // Do nothing break; case MAP_OBJECT_TYPE_PICKUP_SPAWNER: { char *tmp = GetString(node, "Pickup"); m->u.PickupClass = StrPickupClass(tmp); CFREE(tmp); } break; default: CASSERT(false, "unknown error"); break; } }
void ObjectiveLoadJSON(Objective *o, json_t *node, const int version) { memset(o, 0, sizeof *o); o->Description = GetString(node, "Description"); JSON_UTILS_LOAD_ENUM(o->Type, node, "Type", StrObjectiveType); // Set objective colours based on type o->color = ObjectiveTypeColor(o->Type); if (version < 8) { // Index numbers used for all objective classes; convert them // to their class handles LoadInt(&o->u.Index, node, "Index"); switch (o->Type) { case OBJECTIVE_COLLECT: o->u.Pickup = IntPickupClass(o->u.Index); break; case OBJECTIVE_DESTROY: o->u.MapObject = IntMapObject(o->u.Index); break; default: // do nothing break; } } else { char *tmp; switch (o->Type) { case OBJECTIVE_COLLECT: tmp = GetString(node, "Pickup"); o->u.Pickup = StrPickupClass(tmp); CFREE(tmp); break; case OBJECTIVE_DESTROY: tmp = GetString(node, "MapObject"); o->u.MapObject = StrMapObject(tmp); CFREE(tmp); break; default: LoadInt(&o->u.Index, node, "Index"); break; } } LoadInt(&o->Count, node, "Count"); LoadInt(&o->Required, node, "Required"); LoadInt(&o->Flags, node, "Flags"); }
static void SetupSpawner( MapObject *m, const char *spawnerName, const char *pickupClassName) { memset(m, 0, sizeof *m); CSTRDUP(m->Name, spawnerName); m->Pic.Type = PICTYPE_NORMAL; m->Pic.u.Pic = PicManagerGetPic(&gPicManager, "spawn_pad"); m->Pic.UseMask = true; m->Pic.u1.Mask = colorWhite; const Vec2i size = CPicGetSize(&m->Pic); m->Offset = Vec2iNew(-size.x / 2, TILE_HEIGHT / 2 - size.y); m->Size = TILE_SIZE; m->Health = 0; m->DrawLast = true; m->Type = MAP_OBJECT_TYPE_PICKUP_SPAWNER; m->u.PickupClass = StrPickupClass(pickupClassName); }
static void LoadAmmoSpawners(CArray *classes, const CArray *ammo) { for (int i = 0; i < (int)ammo->size; i++) { const Ammo *a = CArrayGet(ammo, i); MapObject m; memset(&m, 0, sizeof m); char buf[256]; sprintf(buf, "%s spawner", a->Name); CSTRDUP(m.Name, buf); m.Normal.Pic = PicManagerGetPic(&gPicManager, "spawn_pad"); m.Normal.Offset = Vec2iNew( -m.Normal.Pic->size.x / 2, TILE_HEIGHT / 2 - m.Normal.Pic->size.y); m.Size = Vec2iNew(TILE_WIDTH, TILE_HEIGHT); m.Health = 0; m.Type = MAP_OBJECT_TYPE_PICKUP_SPAWNER; sprintf(buf, "ammo_%s", a->Name); m.u.PickupClass = StrPickupClass(buf); CArrayPushBack(classes, &m); } }
static bool TryLoadMapObject(MapObject *m, json_t *node, const int version) { memset(m, 0, sizeof *m); m->Name = GetString(node, "Name"); // Pic json_t *normalNode = json_find_first_label(node, "Pic"); if (normalNode != NULL && normalNode->child != NULL) { if (version < 2) { CPicLoadNormal(&m->Pic, normalNode->child); } else { CPicLoadJSON(&m->Pic, normalNode->child); } // Pic required for map object if (!CPicIsLoaded(&m->Pic)) { LOG(LM_MAIN, LL_ERROR, "pic not found for map object(%s)", m->Name); goto bail; } } if (CPicIsLoaded(&m->Pic)) { // Default offset: centered X, align bottom of tile and sprite const Vec2i size = CPicGetSize(&m->Pic); m->Offset = Vec2iNew(-size.x / 2, TILE_HEIGHT / 2 - size.y); LoadVec2i(&m->Offset, node, "Offset"); } // Wreck if (version < 3) { // Assume old wreck pic is wreck json_t *wreckNode = json_find_first_label(node, "WreckPic"); if (wreckNode != NULL && wreckNode->child != NULL) { if (version < 2) { LoadStr(&m->Wreck, node, "WreckPic"); } else { LoadStr(&m->Wreck, wreckNode, "Pic"); } } } else { LoadStr(&m->Wreck, node, "Wreck"); } // Default tile size m->Size = TILE_SIZE; LoadVec2i(&m->Size, node, "Size"); LoadVec2i(&m->PosOffset, node, "PosOffset"); LoadInt(&m->Health, node, "Health"); LoadBulletGuns(&m->DestroyGuns, node, "DestroyGuns"); // Flags json_t *flagsNode = json_find_first_label(node, "Flags"); if (flagsNode != NULL && flagsNode->child != NULL) { for (json_t *flagNode = flagsNode->child->child; flagNode; flagNode = flagNode->next) { m->Flags |= 1 << StrPlacementFlag(flagNode->text); } } LoadBool(&m->DrawLast, node, "DrawLast"); // Special types JSON_UTILS_LOAD_ENUM(m->Type, node, "Type", StrMapObjectType); switch (m->Type) { case MAP_OBJECT_TYPE_NORMAL: // Do nothing break; case MAP_OBJECT_TYPE_PICKUP_SPAWNER: { char *tmp = GetString(node, "Pickup"); m->u.PickupClass = StrPickupClass(tmp); CFREE(tmp); } break; default: CASSERT(false, "unknown error"); break; } // DestroySpawn - pickups to spawn on destruction json_t *destroySpawnNode = json_find_first_label(node, "DestroySpawn"); if (destroySpawnNode != NULL && destroySpawnNode->child != NULL) { CArrayInit(&m->DestroySpawn, sizeof(MapObjectDestroySpawn)); for (json_t *dsNode = destroySpawnNode->child->child; dsNode; dsNode = dsNode->next) { MapObjectDestroySpawn mods; memset(&mods, 0, sizeof mods); JSON_UTILS_LOAD_ENUM(mods.Type, dsNode, "Type", StrPickupType); LoadDouble(&mods.SpawnChance, dsNode, "SpawnChance"); CArrayPushBack(&m->DestroySpawn, &mods); } } return true; bail: return false; }