1 /*
2 ** info.h
3 **
4 **---------------------------------------------------------------------------
5 ** Copyright 1998-2007 Randy Heit
6 ** All rights reserved.
7 **
8 ** Redistribution and use in source and binary forms, with or without
9 ** modification, are permitted provided that the following conditions
10 ** are met:
11 **
12 ** 1. Redistributions of source code must retain the above copyright
13 **    notice, this list of conditions and the following disclaimer.
14 ** 2. Redistributions in binary form must reproduce the above copyright
15 **    notice, this list of conditions and the following disclaimer in the
16 **    documentation and/or other materials provided with the distribution.
17 ** 3. The name of the author may not be used to endorse or promote products
18 **    derived from this software without specific prior written permission.
19 **
20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 **---------------------------------------------------------------------------
31 **
32 */
33 
34 #ifndef __INFO_H__
35 #define __INFO_H__
36 
37 #include <stddef.h>
38 #if !defined(_WIN32)
39 #include <inttypes.h>		// for intptr_t
40 #elif !defined(_MSC_VER)
41 #include <stdint.h>			// for mingw
42 #endif
43 
44 #include "dobject.h"
45 #include "doomdef.h"
46 
47 #include "m_fixed.h"
48 #include "m_random.h"
49 
50 struct Baggage;
51 class FScanner;
52 struct FActorInfo;
53 class FArchive;
54 
55 // Sprites that are fixed in position because they can have special meanings.
56 enum
57 {
58 	SPR_TNT1,		// The empty sprite
59 	SPR_FIXED,		// Do not change sprite or frame
60 	SPR_NOCHANGE,	// Do not change sprite (frame change is okay)
61 };
62 
63 struct FState
64 {
65 	FState		*NextState;
66 	actionf_p	ActionFunc;
67 	WORD		sprite;
68 	SWORD		Tics;
69 	WORD		TicRange;
70 	BYTE		Frame;
71 	BYTE		DefineFlags;	// Unused byte so let's use it during state creation.
72 	int			Misc1;			// Was changed to SBYTE, reverted to long for MBF compat
73 	int			Misc2;			// Was changed to BYTE, reverted to long for MBF compat
74 	short		Light;
75 	BYTE		Fullbright:1;	// State is fullbright
76 	BYTE		SameFrame:1;	// Ignore Frame (except when spawning actor)
77 	BYTE		Fast:1;
78 	BYTE		NoDelay:1;		// Spawn states executes its action normally
79 	BYTE		CanRaise:1;		// Allows a monster to be resurrected without waiting for an infinate frame
80 	BYTE		Slow:1;			// Inverse of fast
81 	int			ParameterIndex;
82 
GetFrameFState83 	inline int GetFrame() const
84 	{
85 		return Frame;
86 	}
GetSameFrameFState87 	inline bool GetSameFrame() const
88 	{
89 		return SameFrame;
90 	}
GetFullbrightFState91 	inline int GetFullbright() const
92 	{
93 		return Fullbright ? 0x10 /*RF_FULLBRIGHT*/ : 0;
94 	}
GetTicsFState95 	inline int GetTics() const
96 	{
97 		if (TicRange == 0)
98 		{
99 			return Tics;
100 		}
101 		return Tics + pr_statetics.GenRand32() % (TicRange + 1);
102 	}
GetMisc1FState103 	inline int GetMisc1() const
104 	{
105 		return Misc1;
106 	}
GetMisc2FState107 	inline int GetMisc2() const
108 	{
109 		return Misc2;
110 	}
GetNextStateFState111 	inline FState *GetNextState() const
112 	{
113 		return NextState;
114 	}
GetNoDelayFState115 	inline bool GetNoDelay() const
116 	{
117 		return NoDelay;
118 	}
GetCanRaiseFState119 	inline bool GetCanRaise() const
120 	{
121 		return CanRaise;
122 	}
SetFrameFState123 	inline void SetFrame(BYTE frame)
124 	{
125 		Frame = frame - 'A';
126 	}
127 	void SetAction(PSymbolActionFunction *func, bool setdefaultparams = true)
128 	{
129 		if (func != NULL)
130 		{
131 			ActionFunc = func->Function;
132 			if (setdefaultparams) ParameterIndex = func->defaultparameterindex+1;
133 		}
134 		else
135 		{
136 			ActionFunc = NULL;
137 			if (setdefaultparams) ParameterIndex = 0;
138 		}
139 	}
140 	inline bool CallAction(AActor *self, AActor *stateowner, StateCallData *statecall = NULL)
141 	{
142 		if (ActionFunc != NULL)
143 		{
144 			ActionFunc(self, stateowner, this, ParameterIndex-1, statecall);
145 			return true;
146 		}
147 		else
148 		{
149 			return false;
150 		}
151 	}
152 	static const PClass *StaticFindStateOwner (const FState *state);
153 	static const PClass *StaticFindStateOwner (const FState *state, const FActorInfo *info);
154 	static FRandom pr_statetics;
155 };
156 
157 struct FStateLabels;
158 struct FStateLabel
159 {
160 	FName Label;
161 	FState *State;
162 	FStateLabels *Children;
163 };
164 
165 struct FStateLabels
166 {
167 	int NumLabels;
168 	FStateLabel Labels[1];
169 
170 	FStateLabel *FindLabel (FName label);
171 
172 	void Destroy();	// intentionally not a destructor!
173 };
174 
175 
176 
177 FArchive &operator<< (FArchive &arc, FState *&state);
178 
179 #include "gametype.h"
180 
181 // Standard pre-defined skin colors
182 struct FPlayerColorSet
183 {
184 	struct ExtraRange
185 	{
186 		BYTE RangeStart, RangeEnd;	// colors to remap
187 		BYTE FirstColor, LastColor;	// colors to map to
188 	};
189 
190 	FName Name;			// Name of this color
191 
192 	int Lump;			// Lump to read the translation from, otherwise use next 2 fields
193 	BYTE FirstColor, LastColor;		// Describes the range of colors to use for the translation
194 
195 	BYTE RepresentativeColor;		// A palette entry representative of this translation,
196 									// for map arrows and status bar backgrounds and such
197 	BYTE NumExtraRanges;
198 	ExtraRange Extra[6];
199 };
200 
201 struct DmgFactors : public TMap<FName, fixed_t>
202 {
203 	fixed_t *CheckFactor(FName type);
204 };
205 typedef TMap<FName, int> PainChanceList;
206 typedef TMap<FName, PalEntry> PainFlashList;
207 typedef TMap<int, FPlayerColorSet> FPlayerColorSetMap;
208 
209 
210 
211 struct DamageTypeDefinition
212 {
213 public:
DamageTypeDefinitionDamageTypeDefinition214 	DamageTypeDefinition() { Clear(); }
215 
216 	fixed_t DefaultFactor;
217 	bool ReplaceFactor;
218 	bool NoArmor;
219 
220 	void Apply(FName type);
ClearDamageTypeDefinition221 	void Clear()
222 	{
223 		DefaultFactor = FRACUNIT;
224 		ReplaceFactor = false;
225 		NoArmor = false;
226 	}
227 
228 	static DamageTypeDefinition *Get(FName type);
229 	static bool IgnoreArmor(FName type);
230 	static int ApplyMobjDamageFactor(int damage, FName type, DmgFactors const * const factors);
231 };
232 
233 
234 struct FActorInfo
235 {
236 	static void StaticInit ();
237 	static void StaticSetActorNums ();
238 
239 	void BuildDefaults ();
240 	void ApplyDefaults (BYTE *defaults);
241 	void RegisterIDs ();
242 	void SetDamageFactor(FName type, fixed_t factor);
243 	void SetPainChance(FName type, int chance);
244 	void SetPainFlash(FName type, PalEntry color);
245 	bool GetPainFlash(FName type, PalEntry *color) const;
246 	void SetColorSet(int index, const FPlayerColorSet *set);
247 
248 	FState *FindState (int numnames, FName *names, bool exact=false) const;
249 	FState *FindStateByString(const char *name, bool exact=false);
FindStateFActorInfo250 	FState *FindState (FName name) const
251 	{
252 		return FindState(1, &name);
253 	}
254 
OwnsStateFActorInfo255 	bool OwnsState(const FState *state)
256 	{
257 		return state >= OwnedStates && state < OwnedStates + NumOwnedStates;
258 	}
259 
260 	FActorInfo *GetReplacement (bool lookskill=true);
261 	FActorInfo *GetReplacee (bool lookskill=true);
262 
263 	PClass *Class;
264 	FState *OwnedStates;
265 	FActorInfo *Replacement;
266 	FActorInfo *Replacee;
267 	int NumOwnedStates;
268 	BYTE GameFilter;
269 	WORD SpawnID;
270 	WORD ConversationID;
271 	SWORD DoomEdNum;
272 	FStateLabels *StateList;
273 	DmgFactors *DamageFactors;
274 	PainChanceList *PainChances;
275 	PainFlashList *PainFlashes;
276 	FPlayerColorSetMap *ColorSets;
277 	TArray<const PClass *> VisibleToPlayerClass;
278 	TArray<const PClass *> RestrictedToPlayerClass;
279 	TArray<const PClass *> ForbiddenToPlayerClass;
280 };
281 
282 struct FDoomEdEntry
283 {
284 	const PClass *Type;
285 	short Special;
286 	signed char ArgsDefined;
287 	int Args[5];
288 };
289 
290 enum ESpecialMapthings
291 {
292 	SMT_Player1Start = 1,
293 	SMT_Player2Start,
294 	SMT_Player3Start,
295 	SMT_Player4Start,
296 	SMT_Player5Start,
297 	SMT_Player6Start,
298 	SMT_Player7Start,
299 	SMT_Player8Start,
300 	SMT_DeathmatchStart,
301 	SMT_SSeqOverride,
302 	SMT_PolyAnchor,
303 	SMT_PolySpawn,
304 	SMT_PolySpawnCrush,
305 	SMT_PolySpawnHurt,
306 	SMT_SlopeFloorPointLine,
307 	SMT_SlopeCeilingPointLine,
308 	SMT_SetFloorSlope,
309 	SMT_SetCeilingSlope,
310 	SMT_VavoomFloor,
311 	SMT_VavoomCeiling,
312 	SMT_CopyFloorPlane,
313 	SMT_CopyCeilingPlane,
314 	SMT_VertexFloorZ,
315 	SMT_VertexCeilingZ,
316 
317 };
318 
319 
320 typedef TMap<int, FDoomEdEntry> FDoomEdMap;
321 
322 extern FDoomEdMap DoomEdMap;
323 
324 void InitActorNumsFromMapinfo();
325 
326 
327 int GetSpriteIndex(const char * spritename, bool add = true);
328 TArray<FName> &MakeStateNameList(const char * fname);
329 void AddStateLight(FState *state, const char *lname);
330 
331 #endif	// __INFO_H__
332