Skip to content

Commit 07ff797

Browse files
authored
Split cheat menus and add more creature cheats (dkfans#4690)
1 parent 392aefd commit 07ff797

8 files changed

Lines changed: 318 additions & 65 deletions

File tree

src/console_cmd.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,25 +2580,47 @@ TbBool cmd_cheat_menu(PlayerNumber plyr_idx, char * args)
25802580
menu_type = 2;
25812581
else if (strcmp(pr2str, "3") == 0 || strcasecmp(pr2str, "instance") == 0)
25822582
menu_type = 3;
2583+
else if (strcmp(pr2str, "4") == 0 || strcasecmp(pr2str, "secondary") == 0)
2584+
menu_type = 4;
25832585

25842586
if (menu_type < 0) {
2585-
targeted_message_add(MsgType_Player, plyr_idx, plyr_idx, GUI_MESSAGES_DELAY, "menu type is invalid. possible values: 0/1/2/3, none/main/creature/instance");
2587+
targeted_message_add(MsgType_Player, plyr_idx, plyr_idx, GUI_MESSAGES_DELAY, "menu type is invalid. possible values: 0/1/2/3/4, none/main/creature/instance/secondary");
25862588
return false;
25872589
}
25882590

25892591
if (menu_type != 1)
2592+
{
25902593
close_main_cheat_menu();
2594+
}
25912595
if (menu_type != 2)
2596+
{
25922597
close_creature_cheat_menu();
2598+
}
25932599
if (menu_type != 3)
2600+
{
25942601
close_instance_cheat_menu();
2602+
}
2603+
if (menu_type != 4)
2604+
{
2605+
close_secondary_cheat_menu();
2606+
}
25952607

25962608
if (menu_type == 1)
2609+
{
25972610
toggle_main_cheat_menu();
2598-
if (menu_type == 2)
2611+
}
2612+
else if (menu_type == 2)
2613+
{
25992614
toggle_creature_cheat_menu();
2600-
if (menu_type == 3)
2615+
}
2616+
else if (menu_type == 3)
2617+
{
26012618
toggle_instance_cheat_menu();
2619+
}
2620+
else if (menu_type == 4)
2621+
{
2622+
toggle_secondary_cheat_menu();
2623+
}
26022624

26032625
return true;
26042626
}

src/front_input.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,13 +1200,38 @@ static TbBool get_dungeon_control_pausable_action_inputs(void)
12001200
if (is_game_key_pressed(Gkey_CheatMenu1, true, false))
12011201
{
12021202
if (!close_instance_cheat_menu())
1203+
{
12031204
toggle_main_cheat_menu();
1205+
}
12041206
}
12051207

12061208
if (is_game_key_pressed(Gkey_CheatMenu2, true, false))
12071209
{
1208-
// Note that we're using "close", not "toggle". Menu can't be opened here.
1209-
close_creature_cheat_menu();
1210+
if ( (player->continue_work_state == PSt_CreatrQuery) || (player->continue_work_state == PSt_QueryAll) )
1211+
{
1212+
struct Thing *creatng = thing_get(player->controlled_thing_idx);
1213+
if (thing_is_creature(creatng))
1214+
{
1215+
if (!close_secondary_cheat_menu()) // Note that we're using "close", not "toggle". Menu can't be opened here.
1216+
{
1217+
toggle_creature_cheat_menu();
1218+
}
1219+
}
1220+
else
1221+
{
1222+
if (!close_creature_cheat_menu())
1223+
{
1224+
toggle_secondary_cheat_menu();
1225+
}
1226+
}
1227+
}
1228+
else
1229+
{
1230+
if (!close_creature_cheat_menu()) // Note that we're using "close", not "toggle". Menu can't be opened here.
1231+
{
1232+
toggle_secondary_cheat_menu();
1233+
}
1234+
}
12101235
}
12111236
if (player->view_mode == PVM_IsoWibbleView || player->view_mode == PVM_IsoStraightView)
12121237
{
@@ -1584,15 +1609,17 @@ static short get_creature_control_action_inputs(void)
15841609
get_gui_inputs(1);
15851610
if (is_game_key_pressed(Gkey_CheatMenu1, true, false))
15861611
{
1587-
// Note that we're using "close", not "toggle". Menu can't be opened here.
1588-
if (!close_main_cheat_menu())
1612+
if (!close_main_cheat_menu()) // Note that we're using "close", not "toggle". Menu can't be opened here.
15891613
{
15901614
toggle_instance_cheat_menu();
15911615
}
15921616
}
15931617
if (is_game_key_pressed(Gkey_CheatMenu2, true, false))
15941618
{
1595-
toggle_creature_cheat_menu();
1619+
if (!close_secondary_cheat_menu()) // Note that we're using "close", not "toggle". Menu can't be opened here.
1620+
{
1621+
toggle_creature_cheat_menu();
1622+
}
15961623
}
15971624
if (is_key_pressed(KC_ESCAPE, KMod_DONTCARE))
15981625
{

src/frontend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ TbBool close_instance_cheat_menu(void);
435435
TbBool open_creature_cheat_menu(void);
436436
TbBool close_creature_cheat_menu(void);
437437
TbBool toggle_creature_cheat_menu(void);
438+
TbBool open_secondary_cheat_menu(void);
439+
TbBool close_secondary_cheat_menu(void);
440+
TbBool toggle_secondary_cheat_menu(void);
438441
void initialise_tab_tags(MenuID menu_id);
439442
void initialise_tab_tags_and_menu(MenuID menu_id);
440443
void turn_off_roaming_menus(void);

src/gui_boxmenu.c

Lines changed: 178 additions & 49 deletions
Large diffs are not rendered by default.

src/gui_boxmenu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ TbBool cheat_menu_is_active();
5656
extern struct GuiBoxOption gui_main_cheat_list[];
5757
extern struct GuiBoxOption gui_creature_cheat_option_list[];
5858
extern struct GuiBoxOption gui_instance_option_list[];
59+
extern struct GuiBoxOption gui_secondary_cheat_option_list[];
5960
/******************************************************************************/
6061
#ifdef __cplusplus
6162
}

src/keeperfx.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ extern short default_loc_player;
206206
extern struct GuiBox *gui_cheat_box_1;
207207
extern struct GuiBox *gui_cheat_box_2;
208208
extern struct GuiBox *gui_cheat_box_3;
209+
extern struct GuiBox *gui_cheat_box_4;
209210
extern struct StartupParameters start_params;
210211

211212
//Functions - reworked

src/packets.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ enum TbPacketAction {
9898
PckA_UnusedSlot059,
9999
PckA_CheatEnter,//60
100100
PckA_CheatAllFree,
101-
PckA_CheatCrtSpells,
101+
PckA_CheatCrtSpells, // unused
102102
PckA_CheatRevealMap,
103-
PckA_CheatCrAllSpls,
103+
PckA_CheatCrAllSpls, // unused
104104
PckA_CheatUnusedPlaceholder065,//65
105105
PckA_CheatAllMagic,
106106
PckA_CheatAllRooms,
@@ -194,6 +194,12 @@ enum TbPacketAction {
194194
PckA_CheatGiveDoorTrap,
195195
PckA_RoomspaceHighlightToggle,
196196
PckA_UnusedSlot157,
197+
PckA_CheatWinLevel,
198+
PckA_CheatLoseLevel,
199+
PckA_CheatLevelUp,
200+
PckA_CheatLevelDown,
201+
PckA_CheatApplySpell,
202+
PckA_CheatKillCreature,
197203
};
198204

199205
/** Packet flags for non-action player operation. */

src/packets_cheats.c

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ TbBool packets_process_cheats(
767767

768768
TbBool process_players_global_cheats_packet_action(PlayerNumber plyr_idx, struct Packet* pckt)
769769
{
770+
struct PlayerInfo* player;
770771
switch (pckt->action)
771772
{
772773
case PckA_CheatEnter:
@@ -783,7 +784,7 @@ TbBool process_players_global_cheats_packet_action(PlayerNumber plyr_idx, struct
783784
return false;
784785
case PckA_CheatRevealMap:
785786
{
786-
struct PlayerInfo* player = get_player(plyr_idx);
787+
player = get_player(plyr_idx);
787788
reveal_whole_map(player);
788789
return false;
789790
}
@@ -802,7 +803,7 @@ TbBool process_players_global_cheats_packet_action(PlayerNumber plyr_idx, struct
802803
return false;
803804
case PckA_CheatSwitchTerrain:
804805
{
805-
struct PlayerInfo* player = get_player(plyr_idx);
806+
player = get_player(plyr_idx);
806807
player->cheatselection.chosen_terrain_kind = pckt->actn_par1;
807808
if (slab_kind_has_no_ownership(player->cheatselection.chosen_terrain_kind))
808809
{
@@ -813,26 +814,26 @@ TbBool process_players_global_cheats_packet_action(PlayerNumber plyr_idx, struct
813814
}
814815
case PckA_CheatSwitchPlayer:
815816
{
816-
struct PlayerInfo* player = get_player(plyr_idx);
817+
player = get_player(plyr_idx);
817818
clear_messages_from_player(MsgType_Player, player->cheatselection.chosen_player);
818819
player->cheatselection.chosen_player = pckt->actn_par1;
819820
return false;
820821
}
821822
case PckA_CheatSwitchCreature:
822823
{
823-
struct PlayerInfo* player = get_player(plyr_idx);
824+
player = get_player(plyr_idx);
824825
player->cheatselection.chosen_creature_kind = pckt->actn_par1;
825826
return false;
826827
}
827828
case PckA_CheatSwitchHero:
828829
{
829-
struct PlayerInfo* player = get_player(plyr_idx);
830+
player = get_player(plyr_idx);
830831
player->cheatselection.chosen_hero_kind = pckt->actn_par1;
831832
return false;
832833
}
833834
case PckA_CheatSwitchExperience:
834835
{
835-
struct PlayerInfo* player = get_player(plyr_idx);
836+
player = get_player(plyr_idx);
836837
player->cheatselection.chosen_experience_level = pckt->actn_par1;
837838
return false;
838839
}
@@ -866,6 +867,69 @@ TbBool process_players_global_cheats_packet_action(PlayerNumber plyr_idx, struct
866867
update_trap_tab_to_config();
867868
return false;
868869
}
870+
case PckA_CheatWinLevel:
871+
{
872+
player = get_player(plyr_idx);
873+
set_player_as_won_level(player);
874+
return false;
875+
}
876+
case PckA_CheatLoseLevel:
877+
{
878+
player = get_player(plyr_idx);
879+
set_player_as_lost_level(player);
880+
return false;
881+
}
882+
case PckA_CheatLevelUp:
883+
{
884+
player = get_player(plyr_idx);
885+
struct Thing* thing = thing_get(player->controlled_thing_idx);
886+
creature_increase_level(thing);
887+
return false;
888+
}
889+
case PckA_CheatLevelDown:
890+
{
891+
player = get_player(plyr_idx);
892+
struct Thing* thing = thing_get(player->controlled_thing_idx);
893+
struct CreatureControl* cctrl = creature_control_get_from_thing(thing);
894+
if (!creature_control_invalid(cctrl))
895+
{
896+
set_creature_level(thing, cctrl->exp_level-1);
897+
}
898+
return false;
899+
}
900+
case PckA_CheatApplySpell:
901+
{
902+
player = get_player(plyr_idx);
903+
struct Thing* thing = thing_get(player->controlled_thing_idx);
904+
struct SpellConfig* spconf = get_spell_config(pckt->actn_par1);
905+
SoundSmplTblID smptbl_idx;
906+
if (spconf->caster_affected)
907+
{
908+
if (spconf->caster_affect_sound > 0)
909+
{
910+
smptbl_idx = spconf->caster_affect_sound + SOUND_RANDOM(spconf->caster_sounds_count);
911+
}
912+
else
913+
{
914+
smptbl_idx = 0;
915+
}
916+
}
917+
else
918+
{
919+
struct PowerConfigStats *powerst = get_power_model_stats(spconf->linked_power);
920+
smptbl_idx = powerst->select_sound_idx;
921+
}
922+
thing_play_sample(thing, smptbl_idx, NORMAL_PITCH, 0, 3, 0, 4, FULL_LOUDNESS);
923+
apply_spell_effect_to_thing(thing, pckt->actn_par1, SPELL_MAX_LEVEL, plyr_idx);
924+
return false;
925+
}
926+
case PckA_CheatKillCreature:
927+
{
928+
player = get_player(plyr_idx);
929+
struct Thing* thing = thing_get(player->controlled_thing_idx);
930+
kill_creature(thing, INVALID_THING, -1, CrDed_NoUnconscious);
931+
return false;
932+
}
869933
default:
870934
return false;
871935
}

0 commit comments

Comments
 (0)