Skip to content

Commit

Permalink
Pre-populate guns from mission
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Nov 8, 2018
1 parent a8a5a22 commit e6977ac
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 194 deletions.
4 changes: 4 additions & 0 deletions missions/devhell.cdogscpn/bullets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"Bullets": [
{
"Name": "air",
"Pic": {
"Type": "Normal",
"Pic": ""
},
"Power": 0
}
]
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set(CDOGS_SDL_SOURCES
password.c
player_select_menus.c
prep.c
prep_equip.c
screens_end.c
weapon_menu.c
XGetopt.c)
Expand All @@ -48,6 +49,7 @@ set(CDOGS_SDL_HEADERS
password.h
player_select_menus.h
prep.h
prep_equip.h
screens_end.h
weapon_menu.h
XGetopt.h)
Expand Down
1 change: 1 addition & 0 deletions src/briefing_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "menu_utils.h"
#include "password.h"
#include "prep.h"
#include "prep_equip.h"
#include "screens_end.h"


Expand Down
31 changes: 0 additions & 31 deletions src/cdogs/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,37 +198,6 @@ NPlayerData PlayerDataDefault(const int idx)
}
}

// weapons
switch (idx)
{
case 0:
strcpy(pd.Weapons[0], "Shotgun");
strcpy(pd.Weapons[1], "Machine gun");
strcpy(pd.Weapons[2], "Shrapnel bombs");
break;
case 1:
strcpy(pd.Weapons[0], "Powergun");
strcpy(pd.Weapons[1], "Flamer");
strcpy(pd.Weapons[2], "Grenades");
break;
case 2:
strcpy(pd.Weapons[0], "Sniper rifle");
strcpy(pd.Weapons[1], "Knife");
strcpy(pd.Weapons[2], "Molotovs");
break;
case 3:
strcpy(pd.Weapons[0], "Machine gun");
strcpy(pd.Weapons[1], "Flamer");
strcpy(pd.Weapons[2], "Dynamite");
break;
default:
strcpy(pd.Weapons[0], "Shotgun");
strcpy(pd.Weapons[1], "Machine gun");
strcpy(pd.Weapons[2], "Shrapnel bombs");
break;
}
pd.Weapons_count = 3;

pd.MaxHealth = 200;

return pd;
Expand Down
161 changes: 0 additions & 161 deletions src/prep.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
#include "password.h"
#include "player_select_menus.h"
#include "namegen.h"
#include "weapon_menu.h"


typedef struct
Expand Down Expand Up @@ -741,166 +740,6 @@ static menu_t *MenuCreateAllowedWeapons(
return m;
}

static void RemoveUnavailableWeapons(PlayerData *data, const CArray *weapons);
typedef struct
{
WeaponMenu menus[MAX_LOCAL_PLAYERS];
EventWaitResult waitResult;
} PlayerEquipData;
static void PlayerEquipTerminate(GameLoopData *data);
static void PlayerEquipOnExit(GameLoopData *data);
static GameLoopResult PlayerEquipUpdate(GameLoopData *data, LoopRunner *l);
static void PlayerEquipDraw(GameLoopData *data);
GameLoopData *PlayerEquip(void)
{
PlayerEquipData *data;
CCALLOC(data, sizeof *data);
data->waitResult = EVENT_WAIT_CONTINUE;
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(PLAYER_ANY, false, true),
idx, p->UID,
&gEventHandlers, &gGraphicsDevice);
}

return GameLoopDataNew(
data, PlayerEquipTerminate, NULL, PlayerEquipOnExit,
NULL, PlayerEquipUpdate, PlayerEquipDraw);
}
static bool HasWeapon(const CArray *weapons, const WeaponClass *wc);
static void RemoveUnavailableWeapons(PlayerData *data, const CArray *weapons)
{
for (int i = 0; i < MAX_WEAPONS; i++)
{
if (!HasWeapon(weapons, data->guns[i]))
{
data->guns[i] = NULL;
}
}
}
static bool HasWeapon(const CArray *weapons, const WeaponClass *wc)
{
for (int i = 0; i < (int)weapons->size; i++)
{
const WeaponClass **wc2 = CArrayGet(weapons, i);
if (wc == *wc2)
{
return true;
}
}
return false;
}
static void PlayerEquipTerminate(GameLoopData *data)
{
PlayerEquipData *pData = data->Data;

for (int i = 0; i < GetNumPlayers(PLAYER_ANY, false, true); i++)
{
WeaponMenuTerminate(&pData->menus[i]);
}
CFREE(pData);
}
static void PlayerEquipOnExit(GameLoopData *data)
{
PlayerEquipData *pData = data->Data;

if (pData->waitResult == EVENT_WAIT_OK)
{
for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++)
{
const PlayerData *p = CArrayGet(&gPlayerDatas, i);
if (!p->IsLocal)
{
idx--;
continue;
}
NPlayerData pd = NMakePlayerData(p);
// Update player definitions
if (gCampaign.IsClient)
{
NetClientSendMsg(&gNetClient, GAME_EVENT_PLAYER_DATA, &pd);
}
else
{
NetServerSendMsg(
&gNetServer, NET_SERVER_BCAST, GAME_EVENT_PLAYER_DATA, &pd);
}
}
}
else
{
CampaignUnload(&gCampaign);
}
}
static GameLoopResult PlayerEquipUpdate(GameLoopData *data, LoopRunner *l)
{
PlayerEquipData *pData = data->Data;

// If no human players, don't show equip screen
if (GetNumPlayers(PLAYER_ANY, false, true) == 0)
{
pData->waitResult = EVENT_WAIT_OK;
goto bail;
}

// Check if anyone pressed escape
int cmds[MAX_LOCAL_PLAYERS];
memset(cmds, 0, sizeof cmds);
GetPlayerCmds(&gEventHandlers, &cmds);
if (EventIsEscape(&gEventHandlers, cmds, GetMenuCmd(&gEventHandlers)))
{
pData->waitResult = EVENT_WAIT_CANCEL;
goto bail;
}

// Update menus
bool isDone = true;
for (int i = 0; i < GetNumPlayers(PLAYER_ANY, false, true); i++)
{
WeaponMenuUpdate(&pData->menus[i], cmds[i]);
isDone = isDone && WeaponMenuIsDone(&pData->menus[i]);
}
if (isDone)
{
pData->waitResult = EVENT_WAIT_OK;
goto bail;
}

return UPDATE_RESULT_DRAW;

bail:
if (pData->waitResult == EVENT_WAIT_OK)
{
LoopRunnerChange(l, ScreenWaitForGameStart());
}
else
{
LoopRunnerPop(l);
}
return UPDATE_RESULT_OK;
}
static void PlayerEquipDraw(GameLoopData *data)
{
const PlayerEquipData *pData = data->Data;
BlitClearBuf(&gGraphicsDevice);
for (int i = 0; i < GetNumPlayers(PLAYER_ANY, false, true); i++)
{
WeaponMenuDraw(&pData->menus[i]);
}
BlitUpdateFromBuf(&gGraphicsDevice, gGraphicsDevice.screen);
}

static GameLoopResult CheckGameStart(void *data, LoopRunner *l);
GameLoopData *ScreenWaitForGameStart(void)
{
Expand Down
2 changes: 0 additions & 2 deletions src/prep.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,5 @@ GameLoopData *PlayerSelection(void);
// Choose game-mode-specific options
GameLoopData *GameOptions(const GameMode gm);

GameLoopData *PlayerEquip(void);

// Wait for the game to start
GameLoopData *ScreenWaitForGameStart(void);
Loading

0 comments on commit e6977ac

Please sign in to comment.