1 #pragma once
2 
3 //********************************************************************************************
4 //*
5 //*    This file is part of Egoboo.
6 //*
7 //*    Egoboo is free software: you can redistribute it and/or modify it
8 //*    under the terms of the GNU General Public License as published by
9 //*    the Free Software Foundation, either version 3 of the License, or
10 //*    (at your option) any later version.
11 //*
12 //*    Egoboo is distributed in the hope that it will be useful, but
13 //*    WITHOUT ANY WARRANTY; without even the implied warranty of
14 //*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //*    General Public License for more details.
16 //*
17 //*    You should have received a copy of the GNU General Public License
18 //*    along with Egoboo.  If not, see <http://www.gnu.org/licenses/>.
19 //*
20 //********************************************************************************************
21 
22 /// @file mad.h
23 
24 #include "egoboo_typedef.h"
25 
26 #include "file_formats/id_md2.h"
27 #include "md2.h"
28 
29 #include <SDL_opengl.h>
30 
31 //--------------------------------------------------------------------------------------------
32 //--------------------------------------------------------------------------------------------
33 struct Mix_Chunk;
34 
35 //--------------------------------------------------------------------------------------------
36 //--------------------------------------------------------------------------------------------
37 
38 #define MAX_MAD         MAX_PROFILE
39 
40 /// Model tags
41 enum
42 {
43     MADFX_INVICTUS       = ( 1 <<  0 ),                    ///< I  Make the character invincible
44     MADFX_ACTLEFT        = ( 1 <<  1 ),                    ///< AL Activate left item
45     MADFX_ACTRIGHT       = ( 1 <<  2 ),                    ///< AR Activate right item
46     MADFX_GRABLEFT       = ( 1 <<  3 ),                    ///< GL GO Grab left/Grab only item
47     MADFX_GRABRIGHT      = ( 1 <<  4 ),                    ///< GR Grab right item
48     MADFX_DROPLEFT       = ( 1 <<  5 ),                    ///< DL Drop the item in the left/only grip
49     MADFX_DROPRIGHT      = ( 1 <<  6 ),                    ///< DR Drop the item in the right grip
50     MADFX_STOP           = ( 1 <<  7 ),                    ///< S  Stop movement
51     MADFX_FOOTFALL       = ( 1 <<  8 ),                    ///< F  Play a footfall sound
52     MADFX_CHARLEFT       = ( 1 <<  9 ),                    ///< CL Grab a character with the left/only grip
53     MADFX_CHARRIGHT      = ( 1 << 10 ),                    ///< CR Grab a character with the right grip
54     MADFX_POOF           = ( 1 << 11 )                     ///< P  Poof the character
55 };
56 
57 /// Animation walking
58 #define LIPDA               0                       ///< For smooth transitions 'tween
59 #define LIPWA               1                       ///<  walking rates
60 #define LIPWB               2
61 #define LIPWC               3
62 
63 #define MAX_PIP_PER_PROFILE               13                                      ///< Max part*.txt per object
64 
65 /// This stuff is for actions
66 #define NOACTION            0xFFFF                     ///< Action not valid for this character
67 
68 /// The various model actions
69 enum e_action
70 {
71     ACTION_DA = 0,         ///< DA - Dance ( Typical standing )
72     ACTION_DB,             ///< DB - Dance ( Bored )
73     ACTION_DC,             ///< DC - Dance ( Bored )
74     ACTION_DD,             ///< DD - Dance ( Bored )
75     ACTION_UA,             ///< UA - Unarmed Attack ( Left )
76     ACTION_UB,             ///< UB - Unarmed Attack ( Left )
77     ACTION_UC,             ///< UC - Unarmed Attack ( Right )
78     ACTION_UD,             ///< UD - Unarmed Attack ( Right )
79     ACTION_TA,             ///< TA - Thrust Attack ( Left )
80     ACTION_TB,             ///< TB - Thrust Attack ( Left )
81     ACTION_TC,             ///< TC - Thrust Attack ( Right )
82     ACTION_TD,             ///< TD - Thrust Attack ( Right )
83     ACTION_CA,             ///< CA - Chop Attack ( Left )
84     ACTION_CB,             ///< CB - Chop Attack ( Left )
85     ACTION_CC,             ///< CC - Chop Attack ( Right )
86     ACTION_CD,             ///< CD - Chop Attack ( Right )
87     ACTION_SA,             ///< SA - Slice Attack ( Left )
88     ACTION_SB,             ///< SB - Slice Attack ( Left )
89     ACTION_SC,             ///< SC - Slice Attack ( Right )
90     ACTION_SD,             ///< SD - Slice Attack ( Right )
91     ACTION_BA,             ///< BA - Bash Attack ( Left )
92     ACTION_BB,             ///< BB - Bash Attack ( Left )
93     ACTION_BC,             ///< BC - Bash Attack ( Right )
94     ACTION_BD,             ///< BD - Bash Attack ( Right )
95     ACTION_LA,             ///< LA - Longbow Attack ( Left )
96     ACTION_LB,             ///< LB - Longbow Attack ( Left )
97     ACTION_LC,             ///< LC - Longbow Attack ( Right )
98     ACTION_LD,             ///< LD - Longbow Attack ( Right )
99     ACTION_XA,             ///< XA - Crossbow Attack ( Left )
100     ACTION_XB,             ///< XB - Crossbow Attack ( Left )
101     ACTION_XC,             ///< XC - Crossbow Attack ( Right )
102     ACTION_XD,             ///< XD - Crossbow Attack ( Right )
103     ACTION_FA,             ///< FA - Flinged Attack ( Left )
104     ACTION_FB,             ///< FB - Flinged Attack ( Left )
105     ACTION_FC,             ///< FC - Flinged Attack ( Right )
106     ACTION_FD,             ///< FD - Flinged Attack ( Right )
107     ACTION_PA,             ///< PA - Parry or Block ( Left )
108     ACTION_PB,             ///< PB - Parry or Block ( Left )
109     ACTION_PC,             ///< PC - Parry or Block ( Right )
110     ACTION_PD,             ///< PD - Parry or Block ( Right )
111     ACTION_EA,             ///< EA - Evade
112     ACTION_EB,             ///< EB - Evade
113     ACTION_RA,             ///< RA - Roll
114     ACTION_ZA,             ///< ZA - Zap Magic ( Left )
115     ACTION_ZB,             ///< ZB - Zap Magic ( Left )
116     ACTION_ZC,             ///< ZC - Zap Magic ( Right )
117     ACTION_ZD,             ///< ZD - Zap Magic ( Right )
118     ACTION_WA,             ///< WA - Sneak
119     ACTION_WB,             ///< WB - Walk
120     ACTION_WC,             ///< WC - Run
121     ACTION_WD,             ///< WD - Push
122     ACTION_JA,             ///< JA - Jump
123     ACTION_JB,             ///< JB - Falling ( End of Jump ) ( Dropped Item left )
124     ACTION_JC,             ///< JC - Falling [ Dropped item right ]
125     ACTION_HA,             ///< HA - Hit
126     ACTION_HB,             ///< HB - Hit
127     ACTION_HC,             ///< HC - Hit
128     ACTION_HD,             ///< HD - Hit
129     ACTION_KA,             ///< KA - Killed
130     ACTION_KB,             ///< KB - Killed
131     ACTION_KC,             ///< KC - Killed
132     ACTION_KD,             ///< KD - Killed
133     ACTION_MA,             ///< MA - Misc ( Drop Left Item )
134     ACTION_MB,             ///< MB - Misc ( Drop Right Item )
135     ACTION_MC,             ///< MC - Misc ( Cheer/Slam Left )
136     ACTION_MD,             ///< MD - Misc ( Show Off/Slam Right/Rise from ground )
137     ACTION_ME,             ///< ME - Misc ( Grab Item Left )
138     ACTION_MF,             ///< MF - Misc ( Grab Item Right )
139     ACTION_MG,             ///< MG - Misc ( Open Chest )
140     ACTION_MH,             ///< MH - Misc ( Sit )
141     ACTION_MI,             ///< MI - Misc ( Ride )
142     ACTION_MJ,             ///< MJ - Misc ( Object Activated )
143     ACTION_MK,             ///< MK - Misc ( Snoozing )
144     ACTION_ML,             ///< ML - Misc ( Unlock )
145     ACTION_MM,             ///< MM - Misc ( Held Left )
146     ACTION_MN,             ///< MN - Misc ( Held Right )
147     ACTION_COUNT
148 };
149 
150 #define ACTION_TYPE( CHR ) (ACTION_##CHR##A)
151 #define ACTION_IS_TYPE( VAL, CHR ) ((VAL >= ACTION_##CHR##A) && (VAL <= ACTION_##CHR##D))
152 
153 //--------------------------------------------------------------------------------------------
154 //--------------------------------------------------------------------------------------------
155 
156 /// The definition of the Egoboo model type
157 struct s_mad
158 {
159     EGO_PROFILE_STUFF
160 
161     Uint16  frameliptowalkframe[4][16];        ///< For walk animations
162 
163     int     action_map[ACTION_COUNT];          ///< actual action = action_map[requested action]
164     bool_t  action_valid[ACTION_COUNT];        ///< bfalse if not valid
165     int     action_stt[ACTION_COUNT];          ///< First frame of anim
166     int     action_end[ACTION_COUNT];          ///< One past last frame
167 
168     //---- per-object data ----
169 
170     // model data
171     MD2_Model_t * md2_ptr;                       ///< the pointer that will eventually be used
172 };
173 typedef struct s_mad mad_t;
174 
175 DECLARE_STACK_EXTERN( mad_t, MadStack, MAX_MAD );
176 
177 #define VALID_MAD_RANGE( IMAD ) ( ((IMAD) >= 0) && ((IMAD) < MAX_MAD) )
178 #define LOADED_MAD( IMAD )       ( VALID_MAD_RANGE( IMAD ) && MadStack.lst[IMAD].loaded )
179 
180 void MadList_init();
181 void MadList_dtor();
182 
183 //--------------------------------------------------------------------------------------------
184 //--------------------------------------------------------------------------------------------
185 
186 void    init_all_mad();
187 void    release_all_mad();
188 bool_t  release_one_mad( const MAD_REF imad );
189 MAD_REF load_one_model_profile_vfs( const char* tmploadname, const MAD_REF object );
190 
191 int    action_which( char cTmp );
192 void   load_action_names_vfs( const char* loadname );
193 
194 int    mad_get_action_ref( const MAD_REF imad, int action );
195 Uint32 mad_get_madfx_ref( const MAD_REF imad, int action );
196 void   mad_make_equally_lit_ref( const MAD_REF imad );
197 
198 int    mad_get_action( mad_t * pmad, int action );
199 Uint32 mad_get_madfx( mad_t * pmad, int action );
200 
201 int    randomize_action( int action, int slot );
202