Skip to content

Commit

Permalink
Add Utnapisthim and Ziusudra #712
Browse files Browse the repository at this point in the history
Show AI players momentarily at end of player selection menu
  • Loading branch information
cxong committed Jun 17, 2024
1 parent fbac574 commit 79f9eed
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 63 deletions.
49 changes: 49 additions & 0 deletions data/.wolf3d/N3Ddata.cdogscpn/characters.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,5 +597,54 @@
"probabilityToTrack": 25,
"probabilityToShoot": 2,
"actionDelay": 15
},
{
"Class": "Jones",
"PlayerTemplateName": "Utnapishtim",
"HairType": "ponytail",
"FacehairType": "dutch",
"Skin": "ffb26aff",
"Arms": "ffad4bff",
"Body": "23e0ffff",
"Legs": "9f5d2aff",
"Hair": "fff7efff",
"Feet": "faa23fff",
"Facehair": "fcfcfcff",
"Hat": "fc7e04ff",
"Glasses": "fc7e04ff",
"speed": 256,
"Gun": "Small Launcher",
"maxHealth": 40,
"excessHealth": 80,
"flags": 0,
"probabilityToMove": 50,
"probabilityToTrack": 25,
"probabilityToShoot": 2,
"actionDelay": 15
},
{
"Class": "Jones",
"PlayerTemplateName": "Ziusudra",
"HairType": "long",
"FacehairType": "beard",
"HatType": "beret",
"Skin": "ffb26aff",
"Arms": "fcfcfcff",
"Body": "ff6316ff",
"Legs": "ff6023ff",
"Hair": "fff7efff",
"Feet": "744815ff",
"Facehair": "fcfcfcff",
"Hat": "ffb96eff",
"Glasses": "fc7e04ff",
"speed": 256,
"Gun": "Small Launcher",
"maxHealth": 40,
"excessHealth": 80,
"flags": 0,
"probabilityToMove": 50,
"probabilityToTrack": 25,
"probabilityToShoot": 2,
"actionDelay": 15
}]
}
18 changes: 4 additions & 14 deletions src/mainmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ static void MainMenuTerminate(GameLoopData *data)
UnloadAllCampaigns(&mData->campaigns);
CFREE(mData);
}
static menu_t *FindSubmenuByName(menu_t *menu, const char *name);
static void MainMenuOnEnter(GameLoopData *data)
{
MainMenuData *mData = data->Data;
Expand All @@ -177,7 +176,7 @@ static void MainMenuOnEnter(GameLoopData *data)
GameEventsTerminate(&gGameEvents);

// Auto-enter the submenu corresponding to the last game mode
menu_t *startMenu = FindSubmenuByName(mData->ms.root, "Start");
menu_t *startMenu = MenuGetSubmenuByName(mData->ms.root, "Start");
if (mData->wasClient)
{
mData->ms.current = startMenu;
Expand All @@ -187,29 +186,20 @@ static void MainMenuOnEnter(GameLoopData *data)
switch (mData->lastGameMode)
{
case GAME_MODE_NORMAL:
mData->ms.current = FindSubmenuByName(startMenu, "Campaign");
mData->ms.current = MenuGetSubmenuByName(startMenu, "Campaign");
break;
case GAME_MODE_DOGFIGHT:
mData->ms.current = FindSubmenuByName(startMenu, "Dogfight");
mData->ms.current = MenuGetSubmenuByName(startMenu, "Dogfight");
break;
case GAME_MODE_DEATHMATCH:
mData->ms.current = FindSubmenuByName(startMenu, "Deathmatch");
mData->ms.current = MenuGetSubmenuByName(startMenu, "Deathmatch");
break;
default:
mData->ms.current = mData->ms.root;
break;
}
}
}
static menu_t *FindSubmenuByName(menu_t *menu, const char *name)
{
CASSERT(menu->type == MENU_TYPE_NORMAL, "invalid menu type");
CA_FOREACH(menu_t, submenu, menu->u.normal.subMenus)
if (strcmp(submenu->name, name) == 0)
return submenu;
CA_FOREACH_END()
return menu;
}
static void MainMenuOnExit(GameLoopData *data)
{
MainMenuData *mData = data->Data;
Expand Down
9 changes: 4 additions & 5 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,10 @@ void MenuSetDisabled(menu_t *menu, const bool isDisabled)

menu_t *MenuGetSubmenuByName(menu_t *menu, const char *name)
{
CA_FOREACH(menu_t, subMenu, menu->u.normal.subMenus)
if (strcmp(subMenu->name, name) == 0)
{
return subMenu;
}
CASSERT(menu->type == MENU_TYPE_NORMAL, "invalid menu type");
CA_FOREACH(menu_t, submenu, menu->u.normal.subMenus)
if (strcmp(submenu->name, name) == 0)
return submenu;
CA_FOREACH_END()
return NULL;
}
Expand Down
1 change: 0 additions & 1 deletion src/player_select_menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ static void CheckReenableLoadMenu(menu_t *menu, void *data)
{
menu_t *loadMenu = MenuGetSubmenuByName(menu, "Load");
UNUSED(data);
assert(loadMenu);
loadMenu->isDisabled = PlayerTemplateGetById(&gPlayerTemplates, 0) == NULL;
}
static menu_t *CreateCustomizeMenu(
Expand Down
101 changes: 58 additions & 43 deletions src/prep.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ typedef struct
char suffixes[CDOGS_PATH_MAX];
char suffixnames[CDOGS_PATH_MAX];
EventWaitResult waitResult;
int endCounter;
} PlayerSelectionData;
static void PlayerSelectionTerminate(GameLoopData *data);
static void PlayerSelectionOnExit(GameLoopData *data);
Expand Down Expand Up @@ -358,22 +359,6 @@ static void PlayerSelectionOnExit(GameLoopData *data)
PlayerSelectionData *pData = data->Data;
if (pData->waitResult == EVENT_WAIT_OK)
{
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)
{
PlayerTrySetInputDevice(p, INPUT_DEVICE_AI, 0);
}
}

if (!gCampaign.IsClient)
{
gCampaign.MissionIndex = 0;
Expand Down Expand Up @@ -406,35 +391,38 @@ static GameLoopResult PlayerSelectionUpdate(GameLoopData *data, LoopRunner *l)
LoopRunnerPop(l);
return UPDATE_RESULT_OK;
}

// Menu input

int idx = 0;
const bool useMenuCmd = GetNumPlayers(PLAYER_ANY, true, true);
for (int i = 0; i < (int)gPlayerDatas.size; i++, idx++)
if (pData->endCounter == 0)
{
const PlayerData *p = CArrayGet(&gPlayerDatas, i);
if (!p->IsLocal)
// Menu input
const bool useMenuCmd = GetNumPlayers(PLAYER_ANY, true, true);
for (int i = 0; i < (int)gPlayerDatas.size; i++, idx++)
{
idx--;
continue;
}
if (p->inputDevice != INPUT_DEVICE_UNSET)
{
MenuSystem *ms = &pData->menus[idx].ms;
if (ms->current->customPostUpdateFunc)
const PlayerData *p = CArrayGet(&gPlayerDatas, i);
if (!p->IsLocal)
{
ms->current->customPostUpdateFunc(
ms->current, ms->current->customPostUpdateData);
idx--;
continue;
}
MenuUpdateMouse(ms);
if (useMenuCmd)
if (p->inputDevice != INPUT_DEVICE_UNSET)
{
cmds[idx] |=
MenuSystem *ms = &pData->menus[idx].ms;
if (ms->current->customPostUpdateFunc)
{
ms->current->customPostUpdateFunc(
ms->current, ms->current->customPostUpdateData);
}
MenuUpdateMouse(ms);
if (useMenuCmd)
{
cmds[idx] |=
GetMenuCmd(&gEventHandlers, ms->current->mouseHover);
}
if (!MenuIsExit(ms) && cmds[idx])
{
MenuProcessCmd(ms, cmds[idx]);
}
if (!MenuIsExit(ms) && cmds[idx])
{
MenuProcessCmd(ms, cmds[idx]);
}
}
}
}
Expand Down Expand Up @@ -465,16 +453,43 @@ static GameLoopResult PlayerSelectionUpdate(GameLoopData *data, LoopRunner *l)
}
if (isDone && hasAtLeastOneInput)
{
pData->waitResult = EVENT_WAIT_OK;
if (!gCampaign.IsClient && CanLevelSelect(gCampaign.Entry.Mode))
// For any player slots not picked, turn them into AIs
bool hasAIPlayers = false;
idx = 0;
for (int i = 0; i < (int)gPlayerDatas.size; i++, idx++)
{
LoopRunnerChange(l, LevelSelection(&gGraphicsDevice));
PlayerData *p = CArrayGet(&gPlayerDatas, i);
if (!p->IsLocal)
{
idx--;
continue;
}
if (p->inputDevice == INPUT_DEVICE_UNSET || p->inputDevice == INPUT_DEVICE_AI)
{
hasAIPlayers = true;
PlayerTrySetInputDevice(p, INPUT_DEVICE_AI, 0);
pData->menus[idx].ms.current = MenuGetSubmenuByName(pData->menus[idx].ms.root, "Done");
}
}
if (hasAIPlayers && pData->endCounter < 70)
{
// If we have AI players, wait a bit before continuing
pData->endCounter++;
return UPDATE_RESULT_DRAW;
}
else
{
LoopRunnerChange(l, GameOptions(gCampaign.Entry.Mode));
pData->waitResult = EVENT_WAIT_OK;
if (!gCampaign.IsClient && CanLevelSelect(gCampaign.Entry.Mode))
{
LoopRunnerChange(l, LevelSelection(&gGraphicsDevice));
}
else
{
LoopRunnerChange(l, GameOptions(gCampaign.Entry.Mode));
}
return UPDATE_RESULT_OK;
}
return UPDATE_RESULT_OK;
}

AssignPlayerInputDevices(&gEventHandlers);
Expand Down

0 comments on commit 79f9eed

Please sign in to comment.