Esempio n. 1
0
void ScreenDogfightScores(void)
{
	GameLoopData gData = GameLoopDataNew(
		NULL, GameLoopWaitForAnyKeyOrButtonFunc, NULL, DogfightScoresDraw);
	GameLoop(&gData);
	SoundPlay(&gSoundDevice, StrSound("mg"));
}
Esempio n. 2
0
bool ScreenMissionBriefing(const struct MissionOptions *m)
{
	const int w = gGraphicsDevice.cachedConfig.Res.x;
	const int h = gGraphicsDevice.cachedConfig.Res.y;
	const int y = h / 4;
	MissionBriefingData mData;
	memset(&mData, 0, sizeof mData);
	mData.IsOK = true;

	// Title
	CMALLOC(mData.Title, strlen(m->missionData->Title) + 32);
	sprintf(mData.Title, "Mission %d: %s",
		m->index + 1, m->missionData->Title);
	mData.TitleOpts = FontOptsNew();
	mData.TitleOpts.HAlign = ALIGN_CENTER;
	mData.TitleOpts.Area = gGraphicsDevice.cachedConfig.Res;
	mData.TitleOpts.Pad.y = y - 25;

	// Password
	if (m->index > 0)
	{
		sprintf(
			mData.Password, "Password: %s", gAutosave.LastMission.Password);
		mData.PasswordOpts = FontOptsNew();
		mData.PasswordOpts.HAlign = ALIGN_CENTER;
		mData.PasswordOpts.Area = gGraphicsDevice.cachedConfig.Res;
		mData.PasswordOpts.Pad.y = y - 15;
	}

	// Split the description, and prepare it for typewriter effect
	mData.TypewriterCount = 0;
	// allow some slack for newlines
	CMALLOC(mData.Description, strlen(m->missionData->Description) * 2 + 1);
	CCALLOC(mData.TypewriterBuf, strlen(m->missionData->Description) * 2 + 1);
	// Pad about 1/6th of the screen width total (1/12th left and right)
	FontSplitLines(m->missionData->Description, mData.Description, w * 5 / 6);
	mData.DescriptionPos = Vec2iNew(w / 12, y);

	// Objectives
	mData.ObjectiveDescPos =
		Vec2iNew(w / 6, y + FontStrH(mData.Description) + h / 10);
	mData.ObjectiveInfoPos =
		Vec2iNew(w - (w / 6), mData.ObjectiveDescPos.y + FontH());
	mData.ObjectiveHeight = h / 12;
	mData.MissionOptions = m;

	GameLoopData gData = GameLoopDataNew(
		&mData, MissionBriefingUpdate,
		&mData, MissionBriefingDraw);
	GameLoop(&gData);
	if (mData.IsOK)
	{
		SoundPlay(&gSoundDevice, StrSound("mg"));
	}

	CFREE(mData.Title);
	CFREE(mData.Description);
	CFREE(mData.TypewriterBuf);
	return mData.IsOK;
}
Esempio n. 3
0
void MenuLoop(MenuSystem *menu)
{
	CASSERT(menu->exitTypes.size > 0, "menu has no exit types");
	GameLoopData gData = GameLoopDataNew(
		menu, MenuUpdate, menu, MenuDraw);
	GameLoop(&gData);
}
Esempio n. 4
0
void DisplayTodaysHighScores(GraphicsDevice *graphics)
{
	int highlights[MAX_LOCAL_PLAYERS];
	int idx = 0;
	for (int i = 0; i < (int)gPlayerDatas.size; i++, idx++)
	{
		const PlayerData *p = CArrayGet(&gPlayerDatas, i);
		if (!p->IsLocal)
		{
			idx--;
			continue;
		}
		highlights[idx] = p->today;
	}
	idx = 0;
	while (idx < MAX_ENTRY && todaysHigh[idx].score > 0)
	{
		GraphicsClear(graphics);
		idx = DisplayPage(
			"Today's highest score:", idx, todaysHigh, highlights);
		GameLoopData gData = GameLoopDataNew(
			NULL, GameLoopWaitForAnyKeyOrButtonFunc, NULL, NULL);
		GameLoop(&gData);
	}
}
Esempio n. 5
0
bool PlayerSelection(void)
{
	PlayerSelectionData data;
	memset(&data, 0, sizeof data);
	data.IsOK = true;
	GetDataFilePath(data.prefixes, "data/prefixes.txt");
	GetDataFilePath(data.suffixes, "data/suffixes.txt");
	GetDataFilePath(data.suffixnames, "data/suffixnames.txt");
	NameGenInit(&data.g, data.prefixes, data.suffixes, data.suffixnames);

	// Create selection menus for each local player
	for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++)
	{
		PlayerData *p = CArrayGet(&gPlayerDatas, i);
		if (!p->IsLocal)
		{
			idx--;
			continue;
		}
		PlayerSelectMenusCreate(
			&data.menus[idx], GetNumPlayers(false, false, true), idx, i,
			&gEventHandlers, &gGraphicsDevice, &data.g);
	}

	if (!gCampaign.IsClient)
	{
		NetServerOpen(&gNetServer);
	}
	GameLoopData gData = GameLoopDataNew(
		&data, PlayerSelectionUpdate,
		&data, PlayerSelectionDraw);
	GameLoop(&gData);

	if (data.IsOK)
	{
		for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++)
		{
			PlayerData *p = CArrayGet(&gPlayerDatas, i);
			if (!p->IsLocal)
			{
				idx--;
				continue;
			}

			// For any player slots not picked, turn them into AIs
			if (p->inputDevice == INPUT_DEVICE_UNSET)
			{
				PlayerSetInputDevice(p, INPUT_DEVICE_AI, 0);
			}
		}
	}

	for (int i = 0; i < GetNumPlayers(false, false, true); i++)
	{
		MenuSystemTerminate(&data.menus[i].ms);
	}
	NameGenTerminate(&data.g);
	return data.IsOK;
}
Esempio n. 6
0
void ScreenDeathmatchFinalScores(void)
{
	SoundPlay(&gSoundDevice, StrSound("victory"));
	GameLoopData gData = GameLoopDataNew(
		NULL, GameLoopWaitForAnyKeyOrButtonFunc,
		NULL, DeathmatchFinalScoresDraw);
	GameLoop(&gData);
	SoundPlay(&gSoundDevice, StrSound("mg"));
}
Esempio n. 7
0
void ScreenVictory(CampaignOptions *c)
{
	SoundPlay(&gSoundDevice, StrSound("victory"));
	GameLoopData gData = GameLoopDataNew(
		NULL, GameLoopWaitForAnyKeyOrButtonFunc,
		c, VictoryDraw);
	GameLoop(&gData);
	SoundPlay(&gSoundDevice, StrSound("hahaha"));
}
Esempio n. 8
0
bool ScreenMissionSummary(CampaignOptions *c, struct MissionOptions *m)
{
	// Save password
	MissionSave ms;
	MissionSaveInit(&ms);
	ms.Campaign = c->Entry;
	// Don't make password for next level if there is none
	int passwordIndex = m->index + 1;
	if (passwordIndex == c->Entry.NumMissions)
	{
		passwordIndex--;
	}
	strcpy(ms.Password, MakePassword(passwordIndex, 0));
	ms.MissionsCompleted = m->index + 1;
	AutosaveAddMission(&gAutosave, &ms, ms.Campaign.BuiltinIndex);
	AutosaveSave(&gAutosave, GetConfigFilePath(AUTOSAVE_FILE));

	// Calculate bonus scores
	// Bonuses only apply if at least one player has lived
	if (AreAnySurvived())
	{
		int bonus = 0;
		// Objective bonuses
		for (int i = 0; i < (int)m->missionData->Objectives.size; i++)
		{
			const struct Objective *o = CArrayGet(&m->Objectives, i);
			const MissionObjective *mo = CArrayGet(&m->missionData->Objectives, i);
			if (o->done == mo->Count && o->done > mo->Required)
			{
				// Perfect
				bonus += PERFECT_BONUS;
			}
		}
		bonus += GetAccessBonus(m);
		bonus += GetTimeBonus(m, NULL);

		for (int i = 0; i < (int)gPlayerDatas.size; i++)
		{
			PlayerData *p = CArrayGet(&gPlayerDatas, i);
			ApplyBonuses(p, bonus);
		}
	}
	GameLoopWaitForAnyKeyOrButtonData wData;
	GameLoopData gData = GameLoopDataNew(
		&wData, GameLoopWaitForAnyKeyOrButtonFunc,
		m, MissionSummaryDraw);
	GameLoop(&gData);
	if (wData.IsOK)
	{
		SoundPlay(&gSoundDevice, StrSound("mg"));
	}
	return wData.IsOK;
}
Esempio n. 9
0
bool ScreenCampaignIntro(CampaignSetting *c)
{
	GameLoopWaitForAnyKeyOrButtonData wData;
	GameLoopData gData = GameLoopDataNew(
		&wData, GameLoopWaitForAnyKeyOrButtonFunc,
		c, CampaignIntroDraw);
	GameLoop(&gData);
	if (wData.IsOK)
	{
		SoundPlay(&gSoundDevice, StrSound("mg"));
	}
	return wData.IsOK;
}
Esempio n. 10
0
static GameLoopData *PlayerListLoop(PlayerList *pl)
{
	MenuSystemInit(&pl->ms, &gEventHandlers, &gGraphicsDevice, pl->pos, pl->size);
	menu_t *menuScores = MenuCreateCustom(
		"View Scores", PlayerListCustomDraw, PlayerListInput, pl);
	if (pl->hasMenu)
	{
		pl->ms.root = MenuCreateNormal("", "", MENU_TYPE_NORMAL, 0);
		MenuAddSubmenu(pl->ms.root, menuScores);
		MenuAddSubmenu(pl->ms.root, MenuCreateReturn("Finish", 0));
	}
	else
	{
		pl->ms.root = menuScores;
	}
	pl->ms.allowAborts = true;
	MenuAddExitType(&pl->ms, MENU_TYPE_RETURN);
	return GameLoopDataNew(
		pl, PlayerListTerminate, PlayerListOnEnter, PlayerListOnExit,
		NULL, pl->updateFunc, PlayerListDraw);
}
Esempio n. 11
0
bool PlayerEquip(void)
{
	PlayerEquipData data;
	memset(&data, 0, sizeof data);
	data.IsOK = true;
	for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++)
	{
		PlayerData *p = CArrayGet(&gPlayerDatas, i);
		if (!p->IsLocal)
		{
			idx--;
			continue;
		}

		// Remove unavailable weapons from players inventories
		RemoveUnavailableWeapons(p, &gMission.Weapons);

		WeaponMenuCreate(
			&data.menus[idx], GetNumPlayers(false, false, true), idx, i,
			&gEventHandlers, &gGraphicsDevice);
		// For AI players, pre-pick their weapons and go straight to menu end
		if (p->inputDevice == INPUT_DEVICE_AI)
		{
			const int lastMenuIndex =
				(int)data.menus[idx].ms.root->u.normal.subMenus.size - 1;
			data.menus[idx].ms.current = CArrayGet(
				&data.menus[idx].ms.root->u.normal.subMenus, lastMenuIndex);
			AICoopSelectWeapons(p, idx, &gMission.Weapons);
		}
	}

	GameLoopData gData = GameLoopDataNew(
		&data, PlayerEquipUpdate, &data, PlayerEquipDraw);
	GameLoop(&gData);

	for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++)
	{
		PlayerData *p = CArrayGet(&gPlayerDatas, i);
		if (!p->IsLocal)
		{
			idx--;
			continue;
		}
		const NetMsgPlayerData d = NetMsgMakePlayerData(p);
		// Ready player definitions
		p->IsUsed = true;
		if (gCampaign.IsClient)
		{
			NetClientSendMsg(&gNetClient, MSG_PLAYER_DATA, &d);
		}
		else
		{
			NetServerBroadcastMsg(&gNetServer, MSG_PLAYER_DATA, &d);
		}
	}

	for (int i = 0; i < GetNumPlayers(false, false, true); i++)
	{
		MenuSystemTerminate(&data.menus[i].ms);
	}

	return data.IsOK;
}