convert line ends
[canaan.git] / prj / cam / src / dark / drk_bind.cpp
blob396527e1f0c83b813636290c219c6339d0c108f5
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/dark/drk_bind.cpp,v 1.14 2000/02/19 13:09:06 toml Exp $
8 //dark binds processing
9 #include <stdlib.h>
10 #include <comtools.h>
11 #include <appagg.h>
13 #include <camera.h>
14 #include <command.h>
15 #include <config.h>
16 #include <contexts.h>
17 #include <gen_bind.h>
18 #include <headmove.h>
19 #include <phclimb.h>
20 #include <physapi.h>
21 #include <playtest.h>
22 #include <plyrmode.h>
23 #include <plyrspd.h>
24 #include <playrobj.h>
25 #include <weapon.h>
26 #include <drkwswd.h>
28 #include <drkmislp.h>
29 #include <drkplinv.h>
30 #include <drkwswd.h>
31 #include <memall.h>
32 #include <dbmem.h> // must be last header!
34 static BOOL g_on_ground;
35 static BOOL g_in_water;
36 static BOOL g_climbing;
37 static BOOL g_mantling;
39 EXTERN BOOL gNoMoveKeys; //shock movement lockout. here hacked in for
40 //jumpblock
42 #define MINEYEZOOM 1.0
43 #define MAXEYEZOOM 3.0
44 #define EYEZOOMFACTOR 1.1
45 #define DRUNKEYEZOOM 0.1
47 static void GetStates ()
49 g_on_ground = PhysObjOnGround (PlayerObject ());
50 g_in_water = PhysObjInWater (PlayerObject ());
51 g_climbing = PhysObjIsClimbing (PlayerObject ());
52 g_mantling = PhysObjIsMantling (PlayerObject ());
55 static BOOL disallow_action_and_unwind(void)
57 if (GetPlayerMode() == kPM_Dead)
59 UnwindToMissionLoop();
60 return TRUE;
62 return FALSE;
66 static char *BlockProc (char *, char *val, BOOL)
68 if (gNoMoveKeys)
69 return NULL;
71 if (disallow_action_and_unwind())
72 return NULL;
74 double dval = atof (val);
75 if (dval == 1.0)
76 StartWeaponBlock (PlayerObject (), OBJ_NULL);
77 else
78 FinishWeaponAction (PlayerObject (), OBJ_NULL);
79 return NULL;
83 static char *UseWeaponOrItemProc (char *cmd, char *val, BOOL)
84 { // this is NOT TOO COOL
85 if (strnicmp(cmd,"use_weapon",strlen("use_weapon"))==0)
87 if (GetPlayerMode() == kPM_Dead)
88 return NULL;
90 else
91 if (disallow_action_and_unwind())
92 return NULL;
94 //if not in FIRST_PERSON mode, frobbing should return you.
95 // and do nothing.
96 Camera* playercam = PlayerCamera();
97 if (CameraGetMode(playercam) != FIRST_PERSON)
99 CameraAttach(playercam,PlayerObject());
100 return NULL;
103 double dval = atof (val);
104 //for these, start is 0 and end is 1
105 char str[16];
106 strcpy (str, cmd);
107 strcat (str, (dval == 0.0) ? " 1" : " 0");
108 CommandExecute (str);
110 return NULL;
114 static char *InvSelectProc (char *cmd, char *val, BOOL)
116 if (disallow_action_and_unwind())
117 return NULL;
119 char str[64];
120 strcpy (str, cmd);
121 strcat (str, " ");
122 strcat (str, val);
123 *val = '\0';
125 CommandExecute (str);
126 return NULL;
129 static void
130 zoomIn( void )
132 Camera* player_cam = PlayerCamera();
134 //disallow zoom while in remote mode
135 if (CameraIsRemote(player_cam))
136 return;
138 float curzoom = player_cam->zoom;
140 curzoom *= EYEZOOMFACTOR;
142 if (curzoom > MAXEYEZOOM)
143 curzoom = MAXEYEZOOM;
145 player_cam->zoom = curzoom;
148 static void
149 zoomOut( void )
151 Camera* player_cam = PlayerCamera();
153 //disallow zoom while in remote mode
154 if (CameraIsRemote(player_cam))
155 return;
157 float curzoom = player_cam->zoom;
159 curzoom /= EYEZOOMFACTOR;
161 if (curzoom < MINEYEZOOM)
162 curzoom = MINEYEZOOM;
164 player_cam->zoom = curzoom;
167 static char *EyeZoomInProc (char *, char *val, BOOL)
169 int i, count;
170 BOOL bZoomIn;
172 if (disallow_action_and_unwind())
173 return NULL;
175 count = atoi( val );
176 if ( count == 0 ) {
177 count = 1;
179 bZoomIn = (count > 0);
180 count = abs( count );
181 for ( i = 0; i < count; i++ ) {
182 if ( bZoomIn ) {
183 zoomIn();
184 } else {
185 zoomOut();
189 return NULL;
192 static char *EyeZoomOutProc (char *, char *val, BOOL)
194 int i, count;
195 BOOL bZoomIn;
197 if (disallow_action_and_unwind())
198 return NULL;
200 count = atoi( val );
201 if ( count == 0 ) {
202 count = 1;
204 bZoomIn = (count < 0);
205 count = abs( count );
206 for ( i = 0; i < count; i++ ) {
207 if ( bZoomIn ) {
208 zoomIn();
209 } else {
210 zoomOut();
214 return NULL;
217 static char *EyeNoZoomProc (char *, char *val, BOOL)
219 if (disallow_action_and_unwind())
220 return NULL;
222 Camera* player_cam = PlayerCamera();
224 //disallow zoom while in remote mode
225 if (CameraIsRemote(player_cam))
226 return NULL;
228 float curzoom = player_cam->zoom;
230 curzoom = MINEYEZOOM;
232 player_cam->zoom = curzoom;
233 return NULL;
236 static char *EyeDrunkZoomProc (char *, char *val, BOOL)
238 if (disallow_action_and_unwind())
239 return NULL;
241 Camera* player_cam = PlayerCamera();
243 //disallow zoom while in remote mode
244 if (CameraIsRemote(player_cam))
245 return NULL;
247 float curzoom = player_cam->zoom;
249 curzoom /= EYEZOOMFACTOR;
251 if (curzoom < DRUNKEYEZOOM)
252 curzoom = DRUNKEYEZOOM;
254 player_cam->zoom = curzoom;
255 return NULL;
258 static char *JumpBlockProc (char *, char *val, BOOL)
260 if (gNoMoveKeys)
261 return NULL;
263 if (disallow_action_and_unwind())
264 return NULL;
266 GetStates();
268 double dval = atof (val);
270 AutoAppIPtr_(Inventory, pInv);
272 ObjID weapon = pInv->Selection(kCurrentWeapon);
273 ObjID owner;
275 if (weapon)
276 owner = GetWeaponOwnerObjID(weapon);
278 if (weapon && WeaponIsSword(owner, weapon))
280 if (dval == 1.0)
281 StartWeaponBlock (PlayerObject(), OBJ_NULL);
282 else
283 FinishWeaponAction (PlayerObject(), OBJ_NULL);
285 else
287 if (dval == 1.0) {
288 SetJumpState (TRUE);
289 if ((g_on_ground || g_in_water || g_climbing) && !g_mantling)
290 PhysPlayerJump (PlayerObject (), JUMP_SPEED);
292 else {
293 SetJumpState (FALSE);
294 if (g_mantling)
295 BreakMantle (PlayerObject ());
299 return NULL;
302 static char *DummyProc (char *, char *, BOOL)
304 return NULL;
307 IB_var g_drk_ib_vars[] = {
308 //{var name, starting var val, flags, game callback to be called, agg callback to resolve conflicts, always NULL},
309 {"block", "0", 0, BlockProc, NULL, NULL},
310 {"use_weapon", "0", 0, UseWeaponOrItemProc, NULL, NULL},
311 {"use_item", "0", 0, UseWeaponOrItemProc, NULL, NULL},
312 {"inv_select", "0", 0, InvSelectProc, NULL, NULL},
314 {"jumpblock", "0", 0, JumpBlockProc, NULL, NULL},
315 {"zoominsome", "0", 0, EyeZoomInProc, NULL, NULL},
316 {"zoomoutsome", "0", 0, EyeZoomOutProc, NULL, NULL},
317 {"zoomoutfull", "0", 0, EyeNoZoomProc, NULL, NULL},
318 {"drunkzoom", "0", 0, EyeDrunkZoomProc, NULL, NULL},
320 {"auto_equip", "0", 0, DummyProc, NULL, NULL},
321 {"auto_search", "0", 0, DummyProc, NULL, NULL},
322 {"goal_notify", "0", 0, DummyProc, NULL, NULL},
323 {"climb_touch", "0", 0, DummyProc, NULL, NULL},
325 NULL
330 void InitDarkIBVars ()
332 //input binding stuff
333 g_pInputBinder->VarSet (g_drk_ib_vars);