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; }
bool NumPlayersSelection( GameMode mode, GraphicsDevice *graphics, EventHandlers *handlers) { MenuSystem ms; MenuSystemInit( &ms, handlers, graphics, Vec2iZero(), graphics->cachedConfig.Res); ms.allowAborts = true; ms.root = ms.current = MenuCreateNormal( "", "Select number of players", MENU_TYPE_NORMAL, 0); for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { char buf[2]; if (IsMultiplayer(mode) && i == 0) { // At least two players for dogfights continue; } sprintf(buf, "%d", i + 1); MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1)); } MenuAddExitType(&ms, MENU_TYPE_RETURN); MenuLoop(&ms); const bool ok = !ms.hasAbort; if (ok) { const int numPlayers = ms.current->u.returnCode; for (int i = 0; i < (int)gPlayerDatas.size; i++) { const PlayerData *p = CArrayGet(&gPlayerDatas, i); CASSERT(!p->IsLocal, "unexpected local player"); } if (NetClientIsConnected(&gNetClient)) { // Tell the server that we want to add new players NetMsgNewPlayers np; np.ClientId = gNetClient.ClientId; np.NumPlayers = numPlayers; NetClientSendMsg(&gNetClient, MSG_NEW_PLAYERS, &np); } else { // We are the server, just add the players for (int i = 0; i < numPlayers; i++) { PlayerData *p = PlayerDataAdd(&gPlayerDatas); PlayerDataSetLocalDefaults(p, i); p->inputDevice = INPUT_DEVICE_UNSET; } } } MenuSystemTerminate(&ms); return ok; }
int NumPlayersSelection( int *numPlayers, campaign_mode_e mode, GraphicsDevice *graphics, InputDevices *input) { MenuSystem ms; int i; int res = 0; MenuSystemInit( &ms, input, graphics, Vec2iZero(), Vec2iNew( graphics->cachedConfig.ResolutionWidth, graphics->cachedConfig.ResolutionHeight)); ms.root = ms.current = MenuCreateNormal( "", "Select number of players", MENU_TYPE_NORMAL, 0); for (i = 0; i < MAX_PLAYERS; i++) { if (mode == CAMPAIGN_MODE_DOGFIGHT && i == 0) { // At least two players for dogfights continue; } char buf[2]; sprintf(buf, "%d", i + 1); MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1)); } MenuAddExitType(&ms, MENU_TYPE_RETURN); for (;;) { int cmd; InputPoll(&gInputDevices, SDL_GetTicks()); if (KeyIsPressed(&gInputDevices.keyboard, SDLK_ESCAPE)) { res = 0; break; // hack to allow exit } cmd = GetMenuCmd(gPlayerDatas); MenuProcessCmd(&ms, cmd); if (MenuIsExit(&ms)) { *numPlayers = ms.current->u.returnCode; res = 1; break; } GraphicsBlitBkg(graphics); MenuDisplay(&ms); BlitFlip(graphics, &gConfig.Graphics); SDL_Delay(10); } MenuSystemTerminate(&ms); return res; }
void MenuDestroy(MenuSystem *menu) { if (menu == NULL || menu->root == NULL) { return; } MenuSystemTerminate(menu); CFREE(menu); }
static void PlayerListTerminate(GameLoopData *data) { PlayerList *pl = data->Data; CArrayTerminate(&pl->playerUIDs); MenuSystemTerminate(&pl->ms); CFREE(pl->data); CFREE(pl); }
bool NumPlayersSelection(GraphicsDevice *graphics, EventHandlers *handlers) { MenuSystem ms; MenuSystemInit( &ms, handlers, graphics, Vec2iZero(), graphics->cachedConfig.Res); ms.allowAborts = true; ms.root = ms.current = MenuCreateNormal( "", "Select number of players", MENU_TYPE_NORMAL, 0); MenuAddSubmenu(ms.current, MenuCreateReturn("(No local players)", 0)); for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { char buf[2]; sprintf(buf, "%d", i + 1); MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1)); } MenuAddExitType(&ms, MENU_TYPE_RETURN); // Select 1 player default ms.current->u.normal.index = 1; MenuLoop(&ms); const bool ok = !ms.hasAbort; if (ok) { const int numPlayers = ms.current->u.returnCode; CA_FOREACH(const PlayerData, p, gPlayerDatas) CASSERT(!p->IsLocal, "unexpected local player"); CA_FOREACH_END() // Add the players for (int i = 0; i < numPlayers; i++) { GameEvent e = GameEventNew(GAME_EVENT_PLAYER_DATA); e.u.PlayerData = PlayerDataDefault(i); e.u.PlayerData.UID = gNetClient.FirstPlayerUID + i; GameEventsEnqueue(&gGameEvents, e); } // Process the events to force add the players HandleGameEvents(&gGameEvents, NULL, NULL, NULL); // This also causes the client to send player data to the server } MenuSystemTerminate(&ms); return ok; }
bool ScreenWait(const char *message, void (*checkFunc)(menu_t *, void *)) { MenuSystem ms; MenuSystemInit( &ms, &gEventHandlers, &gGraphicsDevice, Vec2iZero(), gGraphicsDevice.cachedConfig.Res); ms.allowAborts = true; ms.root = ms.current = MenuCreateNormal("", message, MENU_TYPE_NORMAL, 0); MenuAddExitType(&ms, MENU_TYPE_RETURN); MenuSetPostUpdateFunc(ms.root, checkFunc, &ms); MenuLoop(&ms); const bool ok = !ms.hasAbort; MenuSystemTerminate(&ms); return ok; }
int PlayerEquip(int numPlayers, GraphicsDevice *graphics) { int i; WeaponMenu menus[MAX_PLAYERS]; for (i = 0; i < numPlayers; i++) { WeaponMenuCreate( &menus[i], numPlayers, i, &gCampaign.Setting.characters.players[i], &gPlayerDatas[i], &gInputDevices, graphics, &gConfig.Input); } debug(D_NORMAL, "\n"); for (;;) { int cmds[MAX_PLAYERS]; int isDone = 1; InputPoll(&gInputDevices, SDL_GetTicks()); if (KeyIsPressed(&gInputDevices.keyboard, SDLK_ESCAPE)) { return 0; // hack to exit from menu } GetPlayerCmds(&cmds, gPlayerDatas); for (i = 0; i < numPlayers; i++) { if (!MenuIsExit(&menus[i].ms)) { MenuProcessCmd(&menus[i].ms, cmds[i]); } else if (gPlayerDatas[i].weaponCount == 0) { // Check exit condition; must have selected at least one weapon // Otherwise reset the current menu menus[i].ms.current = menus[i].ms.root; } } for (i = 0; i < numPlayers; i++) { if (!MenuIsExit(&menus[i].ms)) { isDone = 0; } } if (isDone) { break; } GraphicsBlitBkg(graphics); for (i = 0; i < numPlayers; i++) { MenuDisplay(&menus[i].ms); } BlitFlip(graphics, &gConfig.Graphics); SDL_Delay(10); } for (i = 0; i < numPlayers; i++) { MenuSystemTerminate(&menus[i].ms); } return 1; }
int PlayerSelection(int numPlayers, GraphicsDevice *graphics) { int i; int hasInputDevice[MAX_PLAYERS]; PlayerSelectMenu menus[MAX_PLAYERS]; for (i = 0; i < numPlayers; i++) { PlayerSelectMenusCreate( &menus[i], numPlayers, i, &gCampaign.Setting.characters.players[i], &gPlayerDatas[i], &gInputDevices, graphics, &gConfig.Input); hasInputDevice[i] = 0; } KeyInit(&gInputDevices.keyboard); for (;;) { int cmds[MAX_PLAYERS]; int isDone = 1; InputPoll(&gInputDevices, SDL_GetTicks()); if (KeyIsPressed(&gInputDevices.keyboard, SDLK_ESCAPE)) { // TODO: destroy menus return 0; // hack to allow exit } GetPlayerCmds(&cmds, gPlayerDatas); for (i = 0; i < numPlayers; i++) { if (hasInputDevice[i] && !MenuIsExit(&menus[i].ms)) { MenuProcessCmd(&menus[i].ms, cmds[i]); } } for (i = 0; i < numPlayers; i++) { if (!MenuIsExit(&menus[i].ms)) { isDone = 0; } } if (isDone) { break; } AssignPlayerInputDevices( hasInputDevice, numPlayers, gPlayerDatas, &gInputDevices, &gConfig.Input); GraphicsBlitBkg(graphics); for (i = 0; i < numPlayers; i++) { if (hasInputDevice[i]) { MenuDisplay(&menus[i].ms); } else { Vec2i center; const char *prompt = "Press Fire to join..."; Vec2i offset = Vec2iScaleDiv(TextGetSize(prompt), -2); int w = graphics->cachedConfig.ResolutionWidth; int h = graphics->cachedConfig.ResolutionHeight; switch (numPlayers) { case 1: // Center of screen center = Vec2iNew(w / 2, h / 2); break; case 2: // Side by side center = Vec2iNew(i * w / 2 + w / 4, h / 2); break; case 3: case 4: // Four corners center = Vec2iNew( (i & 1) * w / 2 + w / 4, (i / 2) * h / 2 + h / 4); break; default: assert(0 && "not implemented"); break; } DrawTextString(prompt, graphics, Vec2iAdd(center, offset)); } } BlitFlip(graphics, &gConfig.Graphics); SDL_Delay(10); } for (i = 0; i < numPlayers; i++) { MenuSystemTerminate(&menus[i].ms); } return 1; }
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; }
bool GameOptions(const GameMode gm) { // Create selection menus const int w = gGraphicsDevice.cachedConfig.Res.x; const int h = gGraphicsDevice.cachedConfig.Res.y; MenuSystem ms; MenuSystemInit( &ms, &gEventHandlers, &gGraphicsDevice, Vec2iZero(), Vec2iNew(w, h)); ms.align = MENU_ALIGN_CENTER; ms.allowAborts = true; AllowedWeaponsData awData; AllowedWeaponsDataInit(&awData, &gMission.Weapons); switch (gm) { case GAME_MODE_DEATHMATCH: ms.root = ms.current = MenuCreateNormal( "", "", MENU_TYPE_OPTIONS, 0); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Game.PlayerHP")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Deathmatch.Lives")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Game.HealthPickups")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Game.Ammo")); MenuAddSubmenu(ms.current, MenuCreateAllowedWeapons("Weapons...", &awData)); MenuAddSubmenu(ms.current, MenuCreateSeparator("")); MenuAddSubmenu(ms.current, MenuCreateReturn("Done", 0)); break; case GAME_MODE_DOGFIGHT: ms.root = ms.current = MenuCreateNormal( "", "", MENU_TYPE_OPTIONS, 0); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Dogfight.PlayerHP")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Dogfight.FirstTo")); MenuAddSubmenu(ms.current, MenuCreateAllowedWeapons("Weapons...", &awData)); MenuAddSubmenu(ms.current, MenuCreateSeparator("")); MenuAddSubmenu(ms.current, MenuCreateReturn("Done", 0)); break; default: CASSERT(false, "unknown game mode"); break; } MenuAddExitType(&ms, MENU_TYPE_RETURN); MenuLoop(&ms); const bool ok = !ms.hasAbort; if (ok) { ConfigApply(&gConfig); // Save options for later ConfigSave(&gConfig, GetConfigFilePath(CONFIG_FILE)); // Set allowed weapons // First check if the player has unwittingly disabled all weapons // if so, enable all weapons bool allDisabled = true; for (int i = 0, j = 0; i < (int)awData.allowed.size; i++, j++) { const bool *allowed = CArrayGet(&awData.allowed, i); if (*allowed) { allDisabled = false; break; } } if (!allDisabled) { for (int i = 0, j = 0; i < (int)awData.allowed.size; i++, j++) { const bool *allowed = CArrayGet(&awData.allowed, i); if (!*allowed) { CArrayDelete(&gMission.Weapons, j); j--; } } } } AllowedWeaponsDataTerminate(&awData); MenuSystemTerminate(&ms); return ok; }