void ConvertCampaignSetting(CampaignSetting *dest, CampaignSettingOld *src) { int i; CFREE(dest->Title); CSTRDUP(dest->Title, src->title); CFREE(dest->Author); CSTRDUP(dest->Author, src->author); CFREE(dest->Description); CSTRDUP(dest->Description, src->description); for (i = 0; i < src->missionCount; i++) { Mission m; MissionInit(&m); ConvertMission(&m, &src->missions[i]); CArrayPushBack(&dest->Missions, &m); } CharacterStoreTerminate(&dest->characters); CharacterStoreInit(&dest->characters); for (i = 0; i < src->characterCount; i++) { Character *ch = CharacterStoreAddOther(&dest->characters); ConvertCharacter(ch, &src->characters[i]); CharacterSetLooks(ch, &ch->looks); } }
void InsertMission(CampaignOptions *co, Mission *mission, int idx) { if (mission == NULL) { Mission defaultMission; MissionInit(&defaultMission); defaultMission.Size = Vec2iNew(48, 48); mission = &defaultMission; } CArrayInsert(&co->Setting.Missions, idx, mission); }
void InsertMission(CampaignOptions *co, Mission *mission, int idx) { Mission defaultMission; if (mission == NULL) { MissionInit(&defaultMission); defaultMission.Size = Vec2iNew(48, 48); // Set some default values for the mission defaultMission.u.Classic.CorridorWidth = 1; defaultMission.u.Classic.Rooms.Min = defaultMission.u.Classic.Rooms.Max = 5; defaultMission.u.Classic.Rooms.WallLength = 1; defaultMission.u.Classic.Rooms.WallPad = 1; defaultMission.u.Classic.Doors.Min = defaultMission.u.Classic.Doors.Max = 1; defaultMission.u.Classic.Pillars.Min = defaultMission.u.Classic.Pillars.Max = 1; mission = &defaultMission; } CArrayInsert(&co->Setting.Missions, idx, mission); }
void InsertMission(CampaignOptions *co, Mission *mission, int idx) { Mission m; if (mission == NULL) { MissionInit(&m); m.Size = svec2i(48, 48); // Set some default values for the mission m.u.Classic.CorridorWidth = 1; m.u.Classic.Rooms.Min = m.u.Classic.Rooms.Max = 5; m.u.Classic.Rooms.WallLength = 1; m.u.Classic.Rooms.WallPad = 1; m.u.Classic.Doors.Min = m.u.Classic.Doors.Max = 1; m.u.Classic.Pillars.Min = m.u.Classic.Pillars.Max = 1; } else { memset(&m, 0, sizeof m); MissionCopy(&m, mission); } CArrayInsert(&co->Setting.Missions, idx, &m); }
int main(int argc, char *argv[]) { int i; int loaded = 0; printf("C-Dogs SDL Editor\n"); debug(D_NORMAL, "Initialising SDL...\n"); if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO) != 0) { printf("Failed to start SDL!\n"); return -1; } SDL_EnableUNICODE(SDL_ENABLE); printf("Data directory:\t\t%s\n", GetDataFilePath("")); printf("Config directory:\t%s\n\n", GetConfigFilePath("")); EditorBrushInit(&brush); ConfigLoadDefault(&gConfig); ConfigLoad(&gConfig, GetConfigFilePath(CONFIG_FILE)); gConfig.Graphics.IsEditor = 1; if (!PicManagerTryInit( &gPicManager, "graphics/cdogs.px", "graphics/cdogs2.px")) { exit(0); } memcpy(origPalette, gPicManager.palette, sizeof origPalette); BuildTranslationTables(gPicManager.palette); TextManagerInit(&gTextManager, GetDataFilePath("graphics/font.px")); GraphicsInit(&gGraphicsDevice); // Hardcode config settings gConfig.Graphics.ScaleMode = SCALE_MODE_NN; gConfig.Graphics.ScaleFactor = 2; gConfig.Graphics.Res.x = 400; gConfig.Graphics.Res.y = 300; GraphicsInitialize( &gGraphicsDevice, &gConfig.Graphics, gPicManager.palette, 0); if (!gGraphicsDevice.IsInitialized) { printf("Video didn't init!\n"); exit(EXIT_FAILURE); } TextManagerGenerateOldPics(&gTextManager, &gGraphicsDevice); PicManagerLoadDir(&gPicManager, GetDataFilePath("graphics")); BulletInitialize(); WeaponInitialize(&gGunDescriptions, GetDataFilePath("guns.json")); CampaignInit(&gCampaign); MissionInit(&lastMission); MissionInit(¤tMission); PlayerDataInitialize(); MapInit(&gMap); // initialise UI collections // Note: must do this after text init since positions depend on text height sObjs = CreateMainObjs(&gCampaign, &brush, Vec2iNew(320, 240)); memset(&sDrawObjs, 0, sizeof sDrawObjs); DrawBufferInit(&sDrawBuffer, Vec2iNew(X_TILES, Y_TILES), &gGraphicsDevice); // Reset campaign (graphics init may have created dummy campaigns) CampaignSettingTerminate(&gCampaign.Setting); CampaignSettingInit(&gCampaign.Setting); EventInit(&gEventHandlers, NULL, false); for (i = 1; i < argc; i++) { if (!loaded) { debug(D_NORMAL, "Loading map %s\n", argv[i]); memset(lastFile, 0, sizeof(lastFile)); strncpy(lastFile, argv[i], sizeof(lastFile) - 1); if (strchr(lastFile, '.') == NULL && sizeof lastFile - strlen(lastFile) > 3) { strcat(lastFile, ".CPN"); } if (MapNewLoad(lastFile, &gCampaign.Setting) == 0) { loaded = 1; } debug(D_NORMAL, "Loaded map %s\n", argv[i]); } } debug(D_NORMAL, "Starting editor\n"); EditCampaign(); MapTerminate(&gMap); WeaponTerminate(&gGunDescriptions); CampaignTerminate(&gCampaign); MissionTerminate(&lastMission); MissionTerminate(¤tMission); DrawBufferTerminate(&sDrawBuffer); GraphicsTerminate(&gGraphicsDevice); PicManagerTerminate(&gPicManager); TextManagerTerminate(&gTextManager); UIObjectDestroy(sObjs); CArrayTerminate(&sDrawObjs); EditorBrushTerminate(&brush); SDL_Quit(); exit(EXIT_SUCCESS); }
void SetupQuickPlayCampaign(CampaignSetting *setting) { Mission *m; CMALLOC(m, sizeof *m); MissionInit(m); m->WallStyle = rand() % WALL_STYLE_COUNT; m->FloorStyle = rand() % FLOOR_STYLE_COUNT; m->RoomStyle = rand() % FLOOR_STYLE_COUNT; m->ExitStyle = rand() % GetExitCount(); m->KeyStyle = rand() % KEYSTYLE_COUNT; strcpy( m->DoorStyle, DoorStyleStr(rand() % gPicManager.doorStyleNames.size)); m->Size = GenerateQuickPlayMapSize( ConfigGetEnum(&gConfig, "QuickPlay.MapSize")); m->Type = MAPTYPE_CLASSIC; // TODO: generate different map types switch (m->Type) { case MAPTYPE_CLASSIC: m->u.Classic.Walls = GenerateQuickPlayParam( ConfigGetEnum(&gConfig, "QuickPlay.WallCount"), 0, 5, 15, 30); m->u.Classic.WallLength = GenerateQuickPlayParam( ConfigGetEnum(&gConfig, "QuickPlay.WallLength"), 1, 3, 6, 12); m->u.Classic.CorridorWidth = rand() % 3 + 1; m->u.Classic.Rooms.Count = GenerateQuickPlayParam( ConfigGetEnum(&gConfig, "QuickPlay.RoomCount"), 0, 2, 5, 12); m->u.Classic.Rooms.Min = rand() % 10 + 5; m->u.Classic.Rooms.Max = rand() % 10 + m->u.Classic.Rooms.Min; m->u.Classic.Rooms.Edge = 1; m->u.Classic.Rooms.Overlap = 1; m->u.Classic.Rooms.Walls = rand() % 5; m->u.Classic.Rooms.WallLength = rand() % 6 + 1; m->u.Classic.Rooms.WallPad = rand() % 4 + 1; m->u.Classic.Squares = GenerateQuickPlayParam( ConfigGetEnum(&gConfig, "QuickPlay.SquareCount"), 0, 1, 3, 6); m->u.Classic.Doors.Enabled = rand() % 2; m->u.Classic.Doors.Min = 1; m->u.Classic.Doors.Max = 6; m->u.Classic.Pillars.Count = rand() % 5; m->u.Classic.Pillars.Min = rand() % 3 + 1; m->u.Classic.Pillars.Max = rand() % 3 + m->u.Classic.Pillars.Min; break; default: assert(0 && "unknown map type"); break; } CharacterStoreTerminate(&setting->characters); CharacterStoreInit(&setting->characters); int c = GenerateQuickPlayParam( ConfigGetEnum(&gConfig, "QuickPlay.EnemyCount"), 3, 5, 8, 12); SetupQuickPlayEnemies(m, c, &setting->characters); c = GenerateQuickPlayParam( ConfigGetEnum(&gConfig, "QuickPlay.ItemCount"), 0, 2, 5, 10); for (int i = 0; i < c; i++) { MapObjectDensity mop; mop.M = IndexMapObject(rand() % MapObjectsCount(&gMapObjects)); mop.Density = GenerateQuickPlayParam( ConfigGetEnum(&gConfig, "QuickPlay.ItemCount"), 0, 5, 10, 20); CArrayPushBack(&m->MapObjectDensities, &mop); } m->EnemyDensity = (40 + (rand() % 20)) / m->Enemies.size; CA_FOREACH(const GunDescription, g, gGunDescriptions.Guns) if (g->IsRealGun) { CArrayPushBack(&m->Weapons, &g); } CA_FOREACH_END() m->WallMask = RandomBGColor(); m->FloorMask = RandomBGColor(); m->RoomMask = RandomBGColor(); m->AltMask = RandomBGColor(); CFREE(setting->Title); CSTRDUP(setting->Title, "Quick play"); CFREE(setting->Author); CSTRDUP(setting->Author, ""); CFREE(setting->Description); CSTRDUP(setting->Description, ""); CArrayPushBack(&setting->Missions, m); CFREE(m); }
void LoadMissions(CArray *missions, json_t *missionsNode, int version) { json_t *child; for (child = missionsNode->child; child; child = child->next) { Mission m; MissionInit(&m); m.Title = GetString(child, "Title"); m.Description = GetString(child, "Description"); JSON_UTILS_LOAD_ENUM(m.Type, child, "Type", StrMapType); LoadInt(&m.Size.x, child, "Width"); LoadInt(&m.Size.y, child, "Height"); if (version <= 10) { int style; LoadInt(&style, child, "WallStyle"); strcpy(m.WallStyle, IntWallStyle(style)); LoadInt(&style, child, "FloorStyle"); strcpy(m.FloorStyle, IntFloorStyle(style)); LoadInt(&style, child, "RoomStyle"); strcpy(m.RoomStyle, IntRoomStyle(style)); } else { char *tmp = GetString(child, "WallStyle"); strcpy(m.WallStyle, tmp); CFREE(tmp); tmp = GetString(child, "FloorStyle"); strcpy(m.FloorStyle, tmp); CFREE(tmp); tmp = GetString(child, "RoomStyle"); strcpy(m.RoomStyle, tmp); CFREE(tmp); } if (version <= 9) { int style; LoadInt(&style, child, "ExitStyle"); strcpy(m.ExitStyle, IntExitStyle(style)); } else { char *tmp = GetString(child, "ExitStyle"); strcpy(m.ExitStyle, tmp); CFREE(tmp); } if (version <= 8) { int keyStyle; LoadInt(&keyStyle, child, "KeyStyle"); strcpy(m.KeyStyle, IntKeyStyle(keyStyle)); } else { char *tmp = GetString(child, "KeyStyle"); strcpy(m.KeyStyle, tmp); CFREE(tmp); } if (version <= 5) { int doorStyle; LoadInt(&doorStyle, child, "DoorStyle"); strcpy(m.DoorStyle, IntDoorStyle(doorStyle)); } else { char *tmp = GetString(child, "DoorStyle"); strcpy(m.DoorStyle, tmp); CFREE(tmp); } LoadMissionObjectives( &m.Objectives, json_find_first_label(child, "Objectives")->child, version); LoadIntArray(&m.Enemies, child, "Enemies"); LoadIntArray(&m.SpecialChars, child, "SpecialChars"); if (version <= 3) { CArray items; CArrayInit(&items, sizeof(int)); LoadIntArray(&items, child, "Items"); CArray densities; CArrayInit(&densities, sizeof(int)); LoadIntArray(&densities, child, "ItemDensities"); for (int i = 0; i < (int)items.size; i++) { MapObjectDensity mod; mod.M = IntMapObject(*(int *)CArrayGet(&items, i)); mod.Density = *(int *)CArrayGet(&densities, i); CArrayPushBack(&m.MapObjectDensities, &mod); } } else { json_t *modsNode = json_find_first_label(child, "MapObjectDensities"); if (modsNode && modsNode->child) { modsNode = modsNode->child; for (json_t *modNode = modsNode->child; modNode; modNode = modNode->next) { MapObjectDensity mod; mod.M = StrMapObject( json_find_first_label(modNode, "MapObject")->child->text); LoadInt(&mod.Density, modNode, "Density"); CArrayPushBack(&m.MapObjectDensities, &mod); } } } LoadInt(&m.EnemyDensity, child, "EnemyDensity"); LoadWeapons( &m.Weapons, json_find_first_label(child, "Weapons")->child); strcpy(m.Song, json_find_first_label(child, "Song")->child->text); if (version <= 4) { // Load colour indices int wc, fc, rc, ac; LoadInt(&wc, child, "WallColor"); LoadInt(&fc, child, "FloorColor"); LoadInt(&rc, child, "RoomColor"); LoadInt(&ac, child, "AltColor"); m.WallMask = RangeToColor(wc); m.FloorMask = RangeToColor(fc); m.RoomMask = RangeToColor(rc); m.AltMask = RangeToColor(ac); } else { LoadColor(&m.WallMask, child, "WallMask"); LoadColor(&m.FloorMask, child, "FloorMask"); LoadColor(&m.RoomMask, child, "RoomMask"); LoadColor(&m.AltMask, child, "AltMask"); } switch (m.Type) { case MAPTYPE_CLASSIC: LoadInt(&m.u.Classic.Walls, child, "Walls"); LoadInt(&m.u.Classic.WallLength, child, "WallLength"); LoadInt(&m.u.Classic.CorridorWidth, child, "CorridorWidth"); LoadClassicRooms( &m, json_find_first_label(child, "Rooms")->child); LoadInt(&m.u.Classic.Squares, child, "Squares"); LoadClassicDoors(&m, child, "Doors"); LoadClassicPillars(&m, child, "Pillars"); break; case MAPTYPE_STATIC: if (!TryLoadStaticMap(&m, child, version)) { continue; } break; case MAPTYPE_CAVE: LoadInt(&m.u.Cave.FillPercent, child, "FillPercent"); LoadInt(&m.u.Cave.Repeat, child, "Repeat"); LoadInt(&m.u.Cave.R1, child, "R1"); LoadInt(&m.u.Cave.R2, child, "R2"); break; default: assert(0 && "unknown map type"); continue; } CArrayPushBack(missions, &m); } }
void MissionCopy(Mission *dst, Mission *src) { MissionTerminate(dst); MissionInit(dst); if (src->Title) { CSTRDUP(dst->Title, src->Title); } if (src->Description) { CSTRDUP(dst->Description, src->Description); } dst->Type = src->Type; dst->Size = src->Size; dst->WallStyle = src->WallStyle; dst->FloorStyle = src->FloorStyle; dst->RoomStyle = src->RoomStyle; dst->ExitStyle = src->ExitStyle; dst->KeyStyle = src->KeyStyle; dst->DoorStyle = src->DoorStyle; CArrayCopy(&dst->Objectives, &src->Objectives); for (int i = 0; i < (int)src->Objectives.size; i++) { MissionObjective *smo = CArrayGet(&src->Objectives, i); MissionObjective *dmo = CArrayGet(&dst->Objectives, i); if (smo->Description) { CSTRDUP(dmo->Description, smo->Description); } } CArrayCopy(&dst->Enemies, &src->Enemies); CArrayCopy(&dst->SpecialChars, &src->SpecialChars); CArrayCopy(&dst->Items, &src->Items); CArrayCopy(&dst->ItemDensities, &src->ItemDensities); dst->EnemyDensity = src->EnemyDensity; CArrayCopy(&dst->Weapons, &src->Weapons); memcpy(dst->Song, src->Song, sizeof dst->Song); dst->WallColor = src->WallColor; dst->FloorColor = src->FloorColor; dst->RoomColor = src->RoomColor; dst->AltColor = src->AltColor; switch (dst->Type) { case MAPTYPE_STATIC: CArrayCopy(&dst->u.Static.Tiles, &src->u.Static.Tiles); CArrayCopy(&dst->u.Static.Items, &src->u.Static.Items); CArrayCopy(&dst->u.Static.Wrecks, &src->u.Static.Wrecks); CArrayCopy(&dst->u.Static.Characters, &src->u.Static.Characters); CArrayCopy(&dst->u.Static.Objectives, &src->u.Static.Objectives); CArrayCopy(&dst->u.Static.Keys, &src->u.Static.Keys); dst->u.Static.Start = src->u.Static.Start; dst->u.Static.Exit = src->u.Static.Exit; break; default: memcpy(&dst->u, &src->u, sizeof dst->u); break; } }