Debian Codegraph @

prboom2/src/dsda/excmd.c

raw
1 //
2 // Copyright(C) 2021 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Extended Cmd
16 //
17
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include "doomstat.h"
22
23 #include "dsda/configuration.h"
24 #include "dsda/mapinfo.h"
25
26 #include "excmd.h"
27
28 static dboolean excmd_enabled;
29 static dboolean casual_excmd_features;
30
31 void dsda_EnableExCmd(void) {
32 excmd_enabled = true;
33 }
34
35 void dsda_DisableExCmd(void) {
36 excmd_enabled = false;
37 }
38
39 dboolean dsda_AllowExCmd(void) {
40 return allow_incompatibility || excmd_enabled;
41 }
42
43 // If we are reading a demo header, it might not be in playback mode yet
44 dboolean dsda_ExCmdDemo(void) {
45 return excmd_enabled;
46 }
47
48 void dsda_EnableCasualExCmdFeatures(void) {
49 void dsda_ResetAirControl(void);
50
51 casual_excmd_features = true;
52
53 dsda_ResetAirControl();
54 }
55
56 dboolean dsda_AllowCasualExCmdFeatures(void) {
57 return casual_excmd_features;
58 }
59
60 dboolean dsda_AllowJumping(void) {
61 return (allow_incompatibility && dsda_IntConfig(dsda_config_allow_jumping))
62 || map_info.flags & MI_ALLOW_JUMP
63 || dsda_AllowCasualExCmdFeatures();
64 }
65
66 dboolean dsda_FreeAim(void) {
67 return ((allow_incompatibility || dsda_AllowCasualExCmdFeatures())
68 && dsda_IntConfig(dsda_config_freelook))
69 || map_info.flags & MI_ALLOW_FREE_LOOK;
70 }
71
72 void dsda_ReadExCmd(ticcmd_t* cmd, const byte** p) {
73 const byte* demo_p = *p;
74
75 if (!dsda_AllowExCmd()) return;
76
77 cmd->ex.actions = *demo_p++;
78 if (cmd->ex.actions & XC_SAVE)
79 cmd->ex.save_slot = *demo_p++;
80 if (cmd->ex.actions & XC_LOAD)
81 cmd->ex.load_slot = *demo_p++;
82
83 if (cmd->ex.actions & XC_LOOK) {
84 signed short lowbyte = *demo_p++;
85 cmd->ex.look = ((signed short) (*demo_p++) << 8) + lowbyte;
86 }
87 else
88 cmd->ex.look = 0;
89
90 *p = demo_p;
91 }
92
93 void dsda_WriteExCmd(char** p, ticcmd_t* cmd) {
94 char* demo_p = *p;
95
96 if (!dsda_AllowExCmd()) return;
97
98 *demo_p++ = cmd->ex.actions;
99 if (cmd->ex.actions & XC_SAVE)
100 *demo_p++ = cmd->ex.save_slot;
101 if (cmd->ex.actions & XC_LOAD)
102 *demo_p++ = cmd->ex.load_slot;
103
104 if (cmd->ex.actions & XC_LOOK) {
105 *demo_p++ = cmd->ex.look & 0xff;
106 *demo_p++ = (cmd->ex.look >> 8) & 0xff;
107 }
108
109 *p = demo_p;
110 }
111
112 static excmd_t excmd_queue;
113
114 void dsda_ResetExCmdQueue(void) {
115 memset(&excmd_queue, 0, sizeof(excmd_queue));
116 }
117
118 void dsda_PopExCmdQueue(ticcmd_t* cmd) {
119 cmd->ex = excmd_queue;
120 memset(&excmd_queue, 0, sizeof(excmd_queue));
121 }
122
123 void dsda_QueueExCmdJump(void) {
124 excmd_queue.actions |= XC_JUMP;
125 }
126
127 void dsda_QueueExCmdLook(short look) {
128 excmd_queue.actions |= XC_LOOK;
129 excmd_queue.look = look;
130 }
131
132 void dsda_QueueExCmdSave(int slot) {
133 excmd_queue.actions |= XC_SAVE;
134 excmd_queue.save_slot = slot;
135 }
136
137 void dsda_QueueExCmdLoad(int slot) {
138 excmd_queue.actions |= XC_LOAD;
139 excmd_queue.load_slot = slot;
140 }
141
142 void dsda_QueueExCmdGod(void) {
143 excmd_queue.actions |= XC_GOD;
144 }
145
146 void dsda_QueueExCmdNoClip(void) {
147 excmd_queue.actions |= XC_NOCLIP;
148 }