1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 #ifndef __PHYSICS_H
20 #define __PHYSICS_H
21 
22 /*
23  * $Source: r:/prj/cit/src/inc/RCS/physics.h $
24  * $Revision: 1.36 $
25  * $Author: mahk $
26  * $Date: 1994/09/06 08:44:53 $
27  *
28  *
29  */
30 
31 // Includes
32 #include "objects.h"
33 #include "dirac.h"
34 
35 // Defines
36 
37 typedef fix Physvec[6];
38 #define CONTROL_NO_CHANGE -127
39 
40 #define MAX_PHYS_HANDLE MAX_OBJ
41 
42 #define CHECK_OBJ_PH(oid) ((objs[oid].info.ph != -1) && (objs[oid].info.ph <= MAX_PHYS_HANDLE))
43 
44 #define CSLOPE_SET(a, b, c)    \
45     {                          \
46         terrain_info.cx = (a); \
47         terrain_info.cy = (b); \
48         terrain_info.cz = (c); \
49     }
50 #define FSLOPE_SET(a, b, c)    \
51     {                          \
52         terrain_info.fx = (a); \
53         terrain_info.fy = (b); \
54         terrain_info.fz = (c); \
55     }
56 #define WGRAD_SET(a, b, c)     \
57     {                          \
58         terrain_info.wx = (a); \
59         terrain_info.wy = (b); \
60         terrain_info.wz = (c); \
61     }
62 #define WGRAD_ADD(a, b, c)      \
63     {                           \
64         terrain_info.wx += (a); \
65         terrain_info.wy += (b); \
66         terrain_info.wz += (c); \
67     }
68 
69 #define NUM_EDMS_MODELS 5
70 #define EDMS_NONE       0
71 #define EDMS_ROBOT      1
72 #define EDMS_PELVIS     2
73 #define EDMS_JELLO      3
74 #define EDMS_DIRAC      4
75 
76 // These are the magic edms cyber_space numbers.
77 #define PELVIS_MODE_NORMAL 0
78 #define PELVIS_MODE_SKATES 1
79 #define PELVIS_MODE_CYBER  2
80 
81 #define STANDARD_MASS    fix_make(1, 0)
82 #define STANDARD_SIZE    (standard_robot.size)
83 #define STANDARD_GRAVITY fix_make(4, 0)
84 
85 // Prototypes
86 
87 #define CONTROL_BANKS 4
88 #define CONTROL_MAX_VAL 100
89 // why is this number 100? what is the point??
90 
91 // Set the player motion controls, on a scale of  -100 to +100.
92 // An arg of CONTROL_NO_CHANGE leaves the value unchanged.
93 // There are CONTROL_BANKS banks of controls, which roughly average
94 // together.
95 errtype physics_set_player_controls(int bank, byte xvel, byte yvel, byte zvel, byte xyrot, byte yzrot, byte xzrot);
96 
97 // Set a single control, using the defined control numbers
98 
99 #define CONTROL_XVEL  0 // x translation
100 #define CONTROL_YVEL  1 // y translation
101 #define CONTROL_ZVEL  2 // z translation
102 #define CONTROL_XYROT 3 // xy rotation
103 #define CONTROL_YZROT 4 // yz rotation
104 #define CONTROL_XZROT 5 // xz rotation
105 
106 #define MOUSE_CONTROL_BANK 0
107 #define KEYBD_CONTROL_BANK 1
108 #define JOYST_CONTROL_BANK 2
109 #define INP6D_CONTROL_BANK 3
110 errtype physics_set_one_control(int bank, int num, byte val);
111 errtype physics_get_one_control(int bank, int num, byte *val);
112 
113 // Run the physics system for one frame
114 errtype physics_run(void);
115 
116 // Initialize EDMS, player, etc.
117 errtype physics_init(void);
118 
119 // Set the gravity parameter of all objects to new_grav
120 errtype apply_gravity_to_objects(fix new_grav);
121 
122 // Take an object, and moves it to a position and velocity relative to the
123 // player.  returns true if it finds an appropriate place to put the object.
124 uchar player_throw_object(ObjID id, int x, int y, int lastx, int lasty, fix vel);
125 
126 // Cause the player to assume one of three postures
127 #define POSTURE_STAND 0
128 #define POSTURE_STOOP 1
129 #define POSTURE_PRONE 2
130 #define NUM_POSTURES  3
131 errtype player_set_posture(ubyte new_posture);
132 
133 // Lean the player.  Values are in a -100-+100 scale.
134 // Hey kids, this don't exist no more.  set your self an
135 // XZROT control if you want to lean sideways.
136 errtype player_set_lean(byte x, byte y);
137 
138 // Plant the player's foot, turning directional controls into
139 // translational ones.  Unplants foot IFF planted is false
140 errtype player_plant_foot(uchar planted);
141 
142 // Set the player's eye position -100 to +100
143 void player_set_eye(byte eyecntl);
144 
145 // Build the model given a state and object ID, and assign appropriate
146 // data into the object and do appropriate bookkeeping
147 errtype assemble_physics_object(ObjID id, State *pnew_state);
148 
149 // Instantiators
150 void instantiate_robot(int triple, Robot *r);
151 void instantiate_pelvis(int triple, Pelvis *r);
152 void instantiate_dirac(int triple, Dirac_frame *new_dirac);
153 
154 errtype apply_gravity_to_one_object(ObjID oid, fix new_grav);
155 
156 // Globals
157 
158 #ifdef __PHYSICS_SRC
159 TerrainData terrain_info;
160 State standard_state;
161 #else
162 extern TerrainData terrain_info;
163 extern State standard_state;
164 extern Robot standard_robot;
165 #endif
166 
167 #endif // __PHYSICS_H
168