Ejemplo n.º 1
0
bool CampaignLoad(CampaignOptions *co, CampaignEntry *entry)
{
	CASSERT(!co->IsLoaded, "loading campaign without unloading last one");
	// Note: use the mode already set by the menus
	const GameMode mode = co->Entry.Mode;
	co->Entry = *entry;
	co->Entry.Mode = mode;
	CampaignSettingInit(&co->Setting);
	if (entry->Mode == GAME_MODE_QUICK_PLAY)
	{
		SetupQuickPlayCampaign(&co->Setting);
		co->IsLoaded = true;
	}
	else
	{
		// Normalise the path
		char buf[CDOGS_PATH_MAX];
		GetDataFilePath(buf, entry->Path);
		if (MapNewLoad(buf, &co->Setting))
		{
			LOG(LM_MAIN, LL_ERROR, "failed to load campaign %s!", buf);
			CASSERT(false, "Failed to load campaign");
		}
		else
		{
			co->IsLoaded = true;
		}
	}

	if (co->IsLoaded)
	{
		LOG(LM_MAIN, LL_INFO, "loaded campaign/dogfight");
	}
	return co->IsLoaded;
}
Ejemplo n.º 2
0
void GrafxMakeRandomBackground(
	GraphicsDevice *device,
	CampaignOptions *co, struct MissionOptions *mo, Map *map)
{
	HSV tint;
	CampaignSettingInit(&co->Setting);
	ActorsInit();
	ObjsInit();
	MobObjsInit();
	SetupQuickPlayCampaign(&co->Setting, &gConfig.QuickPlay);
	co->seed = rand();
	tint.h = rand() * 360.0 / RAND_MAX;
	tint.s = rand() * 1.0 / RAND_MAX;
	tint.v = 0.5;
	DrawBuffer buffer;
	DrawBufferInit(&buffer, Vec2iNew(X_TILES, Y_TILES), device);
	co->MissionIndex = 0;
	GrafxMakeBackground(
		device, &buffer, co, mo, map,
		tint, 0, 1, Vec2iCenterOfTile(Vec2iScaleDiv(map->Size, 2)), NULL);
	DrawBufferTerminate(&buffer);
	ActorsTerminate();
	ObjsTerminate();
	MobObjsTerminate();
	RemoveAllWatches();
	MissionOptionsTerminate(mo);
	CampaignSettingTerminate(&co->Setting);
	co->seed = gConfig.Game.RandomSeed;
}
Ejemplo n.º 3
0
void GrafxMakeRandomBackground(
	GraphicsDevice *device,
	CampaignOptions *co, struct MissionOptions *mo, Map *map)
{
	CampaignSettingInit(&co->Setting);
	SetupQuickPlayCampaign(&co->Setting);
	const HSV tint = {
		rand() * 360.0 / RAND_MAX, rand() * 1.0 / RAND_MAX, 0.5
	};
	DrawBuffer buffer;
	DrawBufferInit(&buffer, svec2i(X_TILES, Y_TILES), device);
	co->MissionIndex = 0;
	GrafxMakeBackground(
		device, &buffer, co, mo, map, tint, false, svec2_zero(), NULL);
	DrawBufferTerminate(&buffer);
	MissionOptionsTerminate(mo);
	CampaignSettingTerminate(&co->Setting);
}
Ejemplo n.º 4
0
void MenuLoadCampaign(campaign_entry_t *entry)
{
	gCampaign.Entry = *entry;
	CampaignSettingTerminate(&gCampaign.Setting);
	if (entry->isBuiltin)
	{
		if (entry->mode == CAMPAIGN_MODE_NORMAL)
		{
			SetupBuiltinCampaign(entry->builtinIndex);
		}
		else if (entry->mode == CAMPAIGN_MODE_DOGFIGHT)
		{
			SetupBuiltinDogfight(entry->builtinIndex);
		}
		else if (entry->mode == CAMPAIGN_MODE_QUICK_PLAY)
		{
			SetupQuickPlayCampaign(&gCampaign.Setting, &gConfig.QuickPlay);
		}
		else
		{
			printf("Unknown game mode!\n");
			assert(0);
		}
	}
	else
	{
		CampaignSettingNew customSetting;
		CampaignSettingInit(&customSetting);

		if (LoadCampaign(entry->path, &customSetting) != CAMPAIGN_OK)
		{
			printf("Failed to load campaign %s!\n", entry->path);
			assert(0);
		}
		memcpy(&gCampaign.Setting, &customSetting, sizeof gCampaign.Setting);
	}

	printf(">> Loading campaign/dogfight\n");
}
Ejemplo n.º 5
0
void CampaignInit(CampaignOptions *campaign)
{
	memset(campaign, 0, sizeof *campaign);
	CampaignSettingInit(&campaign->Setting);
	campaign->seed = ConfigGetInt(&gConfig, "Game.RandomSeed");
}
Ejemplo n.º 6
0
static void Open(void)
{
	char filename[CDOGS_PATH_MAX];
	strcpy(filename, lastFile);
	bool done = false;
	while (!done)
	{
		ClearScreen(&gGraphicsDevice);
		CDogsTextStringAt(125, 50, "Open file:");
		CDogsTextGoto(125, 50 + CDogsTextHeight());
		CDogsTextChar('\020');
		CDogsTextString(filename);
		CDogsTextChar('\021');
		BlitFlip(&gGraphicsDevice, &gConfig.Graphics);

		bool doOpen = false;
		int c = GetKey(&gEventHandlers);
		switch (c)
		{
			case SDLK_RETURN:
			case SDLK_KP_ENTER:
				if (!filename[0])
				{
					break;
				}
				doOpen = true;
				break;
				
			case SDLK_ESCAPE:
				done = true;
				break;
				
			case SDLK_BACKSPACE:
				if (filename[0])
					filename[strlen(filename) - 1] = 0;
				break;
				
			default:
				if (strlen(filename) == sizeof(filename) - 1)
				{
					break;
				}
				c = KeyGetTyped(&gEventHandlers.keyboard);
				if (c && c != '*' &&
					(strlen(filename) > 1 || c != '-') &&
					c != ':' && c != '<' && c != '>' && c != '?' &&
					c != '|')
				{
					size_t si = strlen(filename);
					filename[si + 1] = 0;
					filename[si] = (char)c;
				}
				break;
		}
		if (doOpen)
		{
			ClearScreen(&gGraphicsDevice);
			DrawTextStringSpecial(
				"Loading...", TEXT_XCENTER | TEXT_YCENTER,
				Vec2iZero(), gGraphicsDevice.cachedConfig.Res, Vec2iZero());
			BlitFlip(&gGraphicsDevice, &gConfig.Graphics);
			CampaignSettingTerminate(&gCampaign.Setting);
			CampaignSettingInit(&gCampaign.Setting);
			if (MapNewLoad(filename, &gCampaign.Setting))
			{
				printf("Error: cannot load %s\n", lastFile);
				continue;
			}
			fileChanged = 0;
			Setup(1);
			strcpy(lastFile, filename);
			done = true;
			sAutosaveIndex = 0;
		}
		SDL_Delay(10);
	}
}
Ejemplo n.º 7
0
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(&currentMission);

	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(&currentMission);

	DrawBufferTerminate(&sDrawBuffer);
	GraphicsTerminate(&gGraphicsDevice);
	PicManagerTerminate(&gPicManager);
	TextManagerTerminate(&gTextManager);

	UIObjectDestroy(sObjs);
	CArrayTerminate(&sDrawObjs);
	EditorBrushTerminate(&brush);

	SDL_Quit();

	exit(EXIT_SUCCESS);
}