Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

25.1 KB
Raw Blame
/*
**	Command & Conquer Generals Zero Hour(tm)
**	Copyright 2025 Electronic Arts Inc.
**
**	This program is free software: you can redistribute it and/or modify
**	it under the terms of the GNU General Public License as published by
**	the Free Software Foundation, either version 3 of the License, or
**	(at your option) any later version.
**
**	This program is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**	GNU General Public License for more details.
**
**	You should have received a copy of the GNU General Public License
**	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
// Modified 2025-2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
// Modified 2026 by İlyas Akın for the macOS/Linux port; see NOTICE.md and the git history.

////////////////////////////////////////////////////////////////////////////////
//																																						//
//  (c) 2001-2003 Electronic Arts Inc.																				//
//																																						//
////////////////////////////////////////////////////////////////////////////////

// FILE: GameCommon.h ////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//                                                                          
//                       Westwood Studios Pacific.                          
//                                                                          
//                       Confidential Information					         
//                Copyright (C) 2001 - All Rights Reserved                  
//                                                                          
//-----------------------------------------------------------------------------
//
// Project:    RTS3
//
// File name:  GameCommon.h
//
// Created:    Steven Johnson, October 2001
//
// Desc:			 This is a catchall header for some basic types and definitions
//							needed by various bits of the GameLogic/GameClient, but that
//							we haven't found a good place for yet. Hopefully this file
//							should go away someday, but for now is a convenient spot.
//
//-----------------------------------------------------------------------------

#pragma once

#ifndef _GAMECOMMON_H_
#define _GAMECOMMON_H_



#define DONT_ALLOW_DEBUG_CHEATS_IN_RELEASE ///< Take of the DONT to get cheats back in to release

//#define _CAMPEA_DEMO

// ----------------------------------------------------------------------------------------------
#include "Lib/BaseType.h"
#include <limits.h>

// ----------------------------------------------------------------------------------------------
#if defined(_INTERNAL) || defined(_DEBUG)
	#define DUMP_PERF_STATS
#else
	#define NO_DUMP_PERF_STATS
#endif

// ----------------------------------------------------------------------------------------------
enum
{
	LOGICFRAMES_PER_SECOND = 60,
	RETAIL_LOGICFRAMES_PER_SECOND = 30,	///< the rate every hard-coded frame count and per-frame amount in EA's code and data was written for
	MSEC_PER_SECOND = 1000
};
const Real LOGICFRAMES_PER_MSEC_REAL = (((Real)LOGICFRAMES_PER_SECOND) / ((Real)MSEC_PER_SECOND));
const Real MSEC_PER_LOGICFRAME_REAL = (((Real)MSEC_PER_SECOND) / ((Real)LOGICFRAMES_PER_SECOND));
const Real LOGICFRAMES_PER_SECONDS_REAL = (Real)LOGICFRAMES_PER_SECOND;
const Real SECONDS_PER_LOGICFRAME_REAL = 1.0f / LOGICFRAMES_PER_SECONDS_REAL;

// ----------------------------------------------------------------------------------------------
// Logic runs at twice the retail rate. A frame count written for 30 Hz is doubled, an amount added
// every frame is halved, an acceleration quartered, and a factor multiplied in every frame becomes
// its square root. Every one of those is exact in IEEE arithmetic (sqrt included), so all machines
// agree; the factor conversion is only exact because the ratio is 2, hence the assert.
enum { LOGICFRAMES_PER_RETAIL_FRAME = LOGICFRAMES_PER_SECOND / RETAIL_LOGICFRAMES_PER_SECOND };
static_assert( LOGICFRAMES_PER_SECOND == 2 * RETAIL_LOGICFRAMES_PER_SECOND, "the Retail conversions assume logic runs at exactly twice the retail rate" );

// a frame count past half the type's range is a sentinel (a "never" or "forever"), and stays one
constexpr Int ConvertRetailFrames( Int frames )
{
	if( frames > INT_MAX / LOGICFRAMES_PER_RETAIL_FRAME ) return INT_MAX;
	if( frames < INT_MIN / LOGICFRAMES_PER_RETAIL_FRAME ) return INT_MIN;
	return frames * LOGICFRAMES_PER_RETAIL_FRAME;
}
constexpr UnsignedInt ConvertRetailFrames( UnsignedInt frames )
{
	if( frames > UINT_MAX / LOGICFRAMES_PER_RETAIL_FRAME ) return UINT_MAX;
	return frames * LOGICFRAMES_PER_RETAIL_FRAME;
}
constexpr Real ConvertRetailFrames( Real frames ) { return frames * (Real)LOGICFRAMES_PER_RETAIL_FRAME; }

constexpr Real ConvertRetailPerFrameRate( Real perFrame ) { return perFrame * 0.5f; }
constexpr Real ConvertRetailPerFrameSquared( Real perFrameSqr ) { return perFrameSqr * 0.25f; }
inline Real ConvertRetailPerFrameFactor( Real factor ) { return sqrtf( factor > 0.0f ? factor : 0.0f ); }

// ----------------------------------------------------------------------------------------------
// The two speeds a match someone plays runs at: normal, and turbo mode at twice that.  There is no
// slider any more.  A saved game and the console's speed land on the nearer of the two; -fps, -turbo
// and a replay's speed keys do not pass through here.
enum
{
	PLAYER_GAME_SPEED_NORMAL_FPS = LOGICFRAMES_PER_SECOND,
	PLAYER_GAME_SPEED_TURBO_FPS = LOGICFRAMES_PER_SECOND * 2
};
constexpr Int ClampPlayerGameSpeed( Int fps )
{
	return fps > PLAYER_GAME_SPEED_NORMAL_FPS ? PLAYER_GAME_SPEED_TURBO_FPS : PLAYER_GAME_SPEED_NORMAL_FPS;
}

// ----------------------------------------------------------------------------------------------
// note that this returns a REAL value, not an int... most callers will want to
// call ceil() on the result, so that partial frames get converted to full frames!
inline Real ConvertDurationFromMsecsToFrames(Real msec) 
{	
	return (msec * LOGICFRAMES_PER_MSEC_REAL); 
}

// ----------------------------------------------------------------------------------------------
inline Real ConvertVelocityInSecsToFrames(Real distPerMsec) 
{	
	// this looks wrong, but is the correct conversion factor.
	return (distPerMsec * SECONDS_PER_LOGICFRAME_REAL); 
}

// ----------------------------------------------------------------------------------------------
inline Real ConvertAccelerationInSecsToFrames(Real distPerSec2) 
{	
	// this looks wrong, but is the correct conversion factor.
	const Real SEC_PER_LOGICFRAME_SQR = (SECONDS_PER_LOGICFRAME_REAL * SECONDS_PER_LOGICFRAME_REAL);
	return (distPerSec2 * SEC_PER_LOGICFRAME_SQR); 
}

// ----------------------------------------------------------------------------------------------
inline Real ConvertAngularVelocityInDegreesPerSecToRadsPerFrame(Real degPerSec) 
{	
	const Real RADS_PER_DEGREE = PI / 180.0f;
	return (degPerSec * (SECONDS_PER_LOGICFRAME_REAL * RADS_PER_DEGREE)); 
}

// ----------------------------------------------------------------------------------------------
enum 
{ 
	MAX_PLAYER_COUNT = 16											///< max number of Players.
};

//
// A player index that arrives from outside this machine - off the wire, or out of a replay file -
// is only a number, and nothing on the way in bounds it.  Everything that turns one into a Player
// asks this first; a number that fails it names nobody and the command carrying it is dropped.
//
inline Bool isValidPlayerIndex( Int playerIndex )
{
	return playerIndex >= 0 && playerIndex < MAX_PLAYER_COUNT;
}

// ----------------------------------------------------------------------------------------------
/**
	a bitmask that can uniquely represent each player.
*/
#if MAX_PLAYER_COUNT <= 16
	typedef UnsignedShort PlayerMaskType;
	const PlayerMaskType PLAYERMASK_ALL = 0xffff;
	const PlayerMaskType PLAYERMASK_NONE = 0x0;
#else
	#error "this is the wrong size"
#endif

// ----------------------------------------------------------------------------------------------
enum 
{ 
	MAX_GLOBAL_GENERAL_TYPES = 9,		///< number of playable General Types, not including the boss)
	
	/// The start of the playable global generals playertemplates
	GLOBAL_GENERAL_BEGIN = 5,
	
	/// The end of the playable global generals
	GLOBAL_GENERAL_END = (GLOBAL_GENERAL_BEGIN + MAX_GLOBAL_GENERAL_TYPES - 1)
};

//-------------------------------------------------------------------------------------------------
enum GameDifficulty
{
	DIFFICULTY_EASY,
	DIFFICULTY_NORMAL,
	DIFFICULTY_HARD,

	DIFFICULTY_COUNT
};

//-------------------------------------------------------------------------------------------------
enum PlayerType
{
	PLAYER_HUMAN,				///< player is human-controlled
	PLAYER_COMPUTER,		///< player is computer-controlled

	PLAYERTYPE_COUNT
};

//-------------------------------------------------------------------------------------------------
/// A PartitionCell can be one of three states for Shroud
enum CellShroudStatus
{
	CELLSHROUD_CLEAR,
	CELLSHROUD_FOGGED,
	CELLSHROUD_SHROUDED,

	CELLSHROUD_COUNT
};

//-------------------------------------------------------------------------------------------------
/// Since an object can take up more than a single PartitionCell, this is a status that applies to the whole Object
enum ObjectShroudStatus
{
	OBJECTSHROUD_INVALID,				///< indeterminate state, will recompute
	OBJECTSHROUD_CLEAR,					///< object is not shrouded at all (ie, completely visible)
	OBJECTSHROUD_PARTIAL_CLEAR,	///< object is partly clear (rest is shroud or fog)
	OBJECTSHROUD_FOGGED,				///< object is completely fogged
	OBJECTSHROUD_SHROUDED,			///< object is completely shrouded
	OBJECTSHROUD_INVALID_BUT_PREVIOUS_VALID,			///< indeterminate state, will recompute, BUT previous status is valid, don't reset (used for save/load)

	OBJECTSHROUD_COUNT
};

//-------------------------------------------------------------------------------------------------
enum GuardMode
{
	GUARDMODE_NORMAL,
	GUARDMODE_GUARD_WITHOUT_PURSUIT,	// no pursuit out of guard area
	GUARDMODE_GUARD_FLYING_UNITS_ONLY	// ignore nonflyers
};

// ---------------------------------------------------
enum 
{ 
	NEVER				= 0,
	FOREVER			= 0x3fffffff			// (we use 0x3fffffff so that we can add offsets and not overflow...
																//		at 30fps we're still pretty safe!)
};

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------

/// Veterancy level define needed by several files that don't need the full Experience code.
// NOTE NOTE NOTE: Keep TheVeterencyNames in sync with these.
enum VeterancyLevel
{
	LEVEL_REGULAR = 0,
	LEVEL_VETERAN,
	LEVEL_ELITE,
	LEVEL_HEROIC,

	LEVEL_COUNT,
	LEVEL_INVALID,

	LEVEL_FIRST = LEVEL_REGULAR,
	LEVEL_LAST = LEVEL_HEROIC
};

// TheVeterancyNames is defined in GameCommon.cpp
extern const char *TheVeterancyNames[]; 

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
enum CommandSourceType : Int 
{ 

	CMD_FROM_PLAYER = 0, 
	CMD_FROM_SCRIPT, 
	CMD_FROM_AI,
	CMD_FROM_DOZER,							// Special rare command when the dozer originates a command to attack a mine. Mines are not ai-attackable, and it seems deceitful for the dozer to generate a player or script command. jba.
	CMD_DEFAULT_SWITCH_WEAPON,	// Special case: A weapon that can be chosen -- this is the default case (machine gun vs flashbang).

};		///< the source of a command

//-------------------------------------------------------------------------------------------------
enum AbleToAttackType
{
	_ATTACK_FORCED			= 0x01,
	_ATTACK_CONTINUED		= 0x02,
	_ATTACK_TUNNELNETWORK_GUARD = 0x04,

	/**
		can we attack if this is a new target?
	*/
	ATTACK_NEW_TARGET = (0),

	/**
		can we attack if this is a new target, via force-fire?
		(The only current difference between this and ATTACK_NEW_TARGET is that disguised units
		are force-attackable even when stealthed.)
	*/
	ATTACK_NEW_TARGET_FORCED= (_ATTACK_FORCED),	

	/**
		can we attack if this is continuation of an existing attack?
		(The only current difference between this and ATTACK_NEW_TARGET is you are allowed to follow
		immobile shrouded units into the fog)
	*/
	ATTACK_CONTINUED_TARGET = (_ATTACK_CONTINUED),

	/**
		can we attack if this is continuation of an existing attack?
		(The only current difference between this and ATTACK_NEW_TARGET is you are allowed to follow
		immobile shrouded units into the fog)
	*/
	ATTACK_CONTINUED_TARGET_FORCED = (_ATTACK_FORCED | _ATTACK_CONTINUED),

	/**
		Special case that bypasses some of the checks for units guarding from within tunnel networks!
		For example, a unit inside couldn't normally see outside and would fail.
	*/
	ATTACK_TUNNEL_NETWORK_GUARD = (_ATTACK_TUNNELNETWORK_GUARD)
	
};

//-------------------------------------------------------------------------------------------------
inline Bool isForcedAttack(AbleToAttackType t)
{
	return (((Int)t) & _ATTACK_FORCED) != 0;
}

//-------------------------------------------------------------------------------------------------
inline Bool isContinuedAttack(AbleToAttackType t)
{
	return (((Int)t) & _ATTACK_CONTINUED) != 0;
}

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------

typedef UnsignedInt VeterancyLevelFlags;

const VeterancyLevelFlags VETERANCY_LEVEL_FLAGS_ALL = 0xffffffff;
const VeterancyLevelFlags VETERANCY_LEVEL_FLAGS_NONE = 0x00000000;

/* A level's bit in VeterancyLevelFlags: bit (level - 1), as EA wrote it, the shift count taken modulo 32.
	 LEVEL_REGULAR is 0, so EA's `1UL << (dt - 1)` shifted by -1.  Built as it shipped, with a 32-bit
	 unsigned long and x86's shl reading the count's low five bits, that is bit 31, which ALL includes and
	 "+REGULAR" sets.  With a 64-bit unsigned long (macOS, Linux) it was bit 63, outside the flags, so no
	 die module with default flags ever ran for a regular unit.  The mask gives Windows' bit everywhere. */
inline VeterancyLevelFlags veterancyLevelFlagBit(VeterancyLevel dt)
{
	return (VeterancyLevelFlags)1 << (((Int)dt - 1) & 31);
}

inline Bool getVeterancyLevelFlag(VeterancyLevelFlags flags, VeterancyLevel dt)
{
	return (flags & veterancyLevelFlagBit(dt)) != 0;
}

inline VeterancyLevelFlags setVeterancyLevelFlag(VeterancyLevelFlags flags, VeterancyLevel dt)
{
	return (flags | veterancyLevelFlagBit(dt));
}

inline VeterancyLevelFlags clearVeterancyLevelFlag(VeterancyLevelFlags flags, VeterancyLevel dt)
{
	return (flags & ~veterancyLevelFlagBit(dt));
}

// ----------------------------------------------------------------------------------------------
#define BOGUSPTR(p) ((((unsigned int)(p)) & 1) != 0)

// ----------------------------------------------------------------------------------------------
#define MAKE_DLINK_HEAD(OBJCLASS, LISTNAME)																						\
public:																																								\
	inline DLINK_ITERATOR<OBJCLASS> iterate_##LISTNAME() const													\
	{																																										\
		DEBUG_ASSERTCRASH(!BOGUSPTR(m_dlinkhead_##LISTNAME.m_head), ("bogus head ptr"));	\
		return DLINK_ITERATOR<OBJCLASS>(m_dlinkhead_##LISTNAME.m_head, &OBJCLASS::dlink_next_##LISTNAME);	\
	}																																										\
	inline OBJCLASS *getFirstItemIn_##LISTNAME() const																	\
	{																																										\
		DEBUG_ASSERTCRASH(!BOGUSPTR(m_dlinkhead_##LISTNAME.m_head), ("bogus head ptr"));	\
		return m_dlinkhead_##LISTNAME.m_head;																							\
	}																																										\
	inline Bool isInList_##LISTNAME(OBJCLASS* o) const																	\
	{																																										\
		DEBUG_ASSERTCRASH(!BOGUSPTR(m_dlinkhead_##LISTNAME.m_head), ("bogus head ptr"));	\
		return o->dlink_isInList_##LISTNAME(&m_dlinkhead_##LISTNAME.m_head);							\
	}																																										\
	inline void prependTo_##LISTNAME(OBJCLASS* o)																				\
	{																																										\
		DEBUG_ASSERTCRASH(!BOGUSPTR(m_dlinkhead_##LISTNAME.m_head), ("bogus head ptr"));	\
		if (!isInList_##LISTNAME(o))																											\
			o->dlink_prependTo_##LISTNAME(&m_dlinkhead_##LISTNAME.m_head);									\
	}																																										\
	inline void removeFrom_##LISTNAME(OBJCLASS* o)																			\
	{																																										\
		DEBUG_ASSERTCRASH(!BOGUSPTR(m_dlinkhead_##LISTNAME.m_head), ("bogus head ptr"));	\
		if (isInList_##LISTNAME(o))																												\
			o->dlink_removeFrom_##LISTNAME(&m_dlinkhead_##LISTNAME.m_head);									\
	}																																										\
	typedef void (*RemoveAllProc_##LISTNAME)(OBJCLASS* o);															\
	inline void removeAll_##LISTNAME(RemoveAllProc_##LISTNAME p = NULL)									\
	{																																										\
		while (m_dlinkhead_##LISTNAME.m_head)																							\
		{																																									\
			DEBUG_ASSERTCRASH(!BOGUSPTR(m_dlinkhead_##LISTNAME.m_head), ("bogus head ptr"));\
			OBJCLASS *tmp = m_dlinkhead_##LISTNAME.m_head;																	\
			removeFrom_##LISTNAME(tmp);																											\
			if (p) (*p)(tmp);																																\
		}																																									\
	}																																										\
	inline void reverse_##LISTNAME()																										\
	{																																										\
		OBJCLASS* cur = m_dlinkhead_##LISTNAME.m_head;																		\
		OBJCLASS* prev = NULL;																														\
		while (cur)																																				\
		{																																									\
			OBJCLASS* originalNext = cur->dlink_next_##LISTNAME();													\
			cur->dlink_swapLinks_##LISTNAME();																							\
			prev = cur;																																			\
			cur = originalNext;																															\
		}																																									\
		m_dlinkhead_##LISTNAME.m_head = prev;																							\
	}																																										\
private:																																							\
	/* a trick: init head to zero */																										\
	struct DLINKHEAD_##LISTNAME																													\
	{																																										\
	public:																																							\
		OBJCLASS* m_head;																																	\
		inline DLINKHEAD_##LISTNAME() :																										\
			m_head(0) { }																																		\
		inline ~DLINKHEAD_##LISTNAME()																										\
			{ DEBUG_ASSERTCRASH(!m_head,("destroying dlinkhead still in a list " #LISTNAME)); }				\
	};																																									\
	DLINKHEAD_##LISTNAME m_dlinkhead_##LISTNAME;	

// ----------------------------------------------------------------------------------------------
#define MAKE_DLINK(OBJCLASS, LISTNAME)	\
public:																	\
	OBJCLASS* dlink_prev_##LISTNAME() const { return m_dlink_##LISTNAME.m_prev; }										\
	OBJCLASS* dlink_next_##LISTNAME() const	{ return m_dlink_##LISTNAME.m_next; }										\
	void dlink_swapLinks_##LISTNAME()																									\
	{																																													\
		OBJCLASS* originalNext = m_dlink_##LISTNAME.m_next;																			\
		m_dlink_##LISTNAME.m_next = m_dlink_##LISTNAME.m_prev;																	\
		m_dlink_##LISTNAME.m_prev = originalNext;																								\
	}																																													\
	Bool dlink_isInList_##LISTNAME(OBJCLASS* const* pListHead) const										\
	{																																													\
		DEBUG_ASSERTCRASH(!BOGUSPTR(*pListHead) && !BOGUSPTR(m_dlink_##LISTNAME.m_next) && !BOGUSPTR(m_dlink_##LISTNAME.m_prev), ("bogus ptrs")); \
		return *pListHead == this || m_dlink_##LISTNAME.m_prev || m_dlink_##LISTNAME.m_next;		\
	}																																													\
	void dlink_prependTo_##LISTNAME(OBJCLASS** pListHead)															\
	{																																													\
		DEBUG_ASSERTCRASH(!dlink_isInList_##LISTNAME(pListHead), ("already in list " #LISTNAME));					\
		DEBUG_ASSERTCRASH(!BOGUSPTR(*pListHead) && !BOGUSPTR(m_dlink_##LISTNAME.m_next) && !BOGUSPTR(m_dlink_##LISTNAME.m_prev), ("bogus ptrs")); \
		m_dlink_##LISTNAME.m_next = *pListHead;																									\
		if (*pListHead)																																					\
			(*pListHead)->m_dlink_##LISTNAME.m_prev = this;																				\
		*pListHead = this;																																			\
		DEBUG_ASSERTCRASH(!BOGUSPTR(*pListHead) && !BOGUSPTR(m_dlink_##LISTNAME.m_next) && !BOGUSPTR(m_dlink_##LISTNAME.m_prev), ("bogus ptrs")); \
	}																																													\
	void dlink_removeFrom_##LISTNAME(OBJCLASS** pListHead)															\
	{																																													\
		DEBUG_ASSERTCRASH(dlink_isInList_##LISTNAME(pListHead), ("not in list" #LISTNAME));			\
		DEBUG_ASSERTCRASH(!BOGUSPTR(*pListHead) && !BOGUSPTR(m_dlink_##LISTNAME.m_next) && !BOGUSPTR(m_dlink_##LISTNAME.m_prev), ("bogus ptrs")); \
		if (m_dlink_##LISTNAME.m_next)																													\
			m_dlink_##LISTNAME.m_next->m_dlink_##LISTNAME.m_prev = m_dlink_##LISTNAME.m_prev;			\
		if (m_dlink_##LISTNAME.m_prev)																													\
			m_dlink_##LISTNAME.m_prev->m_dlink_##LISTNAME.m_next = m_dlink_##LISTNAME.m_next;			\
		else																																										\
			*pListHead = m_dlink_##LISTNAME.m_next;																								\
		m_dlink_##LISTNAME.m_prev = 0;																													\
		m_dlink_##LISTNAME.m_next = 0;																													\
		DEBUG_ASSERTCRASH(!BOGUSPTR(*pListHead) && !BOGUSPTR(m_dlink_##LISTNAME.m_next) && !BOGUSPTR(m_dlink_##LISTNAME.m_prev), ("bogus ptrs")); \
	}																																													\
private:																\
	/* a trick: init links to zero */			\
	struct DLINK_##LISTNAME								\
	{																			\
	public:																\
		OBJCLASS* m_prev;										\
		OBJCLASS* m_next;										\
		inline DLINK_##LISTNAME() :					\
			m_prev(0), m_next(0) { }					\
		inline ~DLINK_##LISTNAME()					\
			{ DEBUG_ASSERTCRASH(!m_prev && !m_next,("destroying dlink still in a list "  #LISTNAME)); } \
	};																		\
	DLINK_##LISTNAME m_dlink_##LISTNAME;	

// ------------------------------------------------------------------------
// this is the weird C++ syntax for "call pointer-to-member-function"... see C++ FAQ LITE for details.
#define callMemberFunction(object,ptrToMember)  ((object).*(ptrToMember)) 

// ------------------------------------------------------------------------
template<class OBJCLASS>
class DLINK_ITERATOR
{
public:
	// this is the weird C++ syntax for "pointer-to-member-function"
	typedef OBJCLASS* (OBJCLASS::*GetNextFunc)() const;	
private:
	OBJCLASS* m_cur;
	GetNextFunc m_getNextFunc;	// this is the weird C++ syntax for "pointer-to-member-function"
public:
	DLINK_ITERATOR(OBJCLASS* cur, GetNextFunc getNextFunc) : m_cur(cur), m_getNextFunc(getNextFunc) 
	{ 
	}
	
	void advance()
	{ 
		if (m_cur)
			m_cur = callMemberFunction(*m_cur, m_getNextFunc)();
	}
	
	Bool done() const
	{ 
		return m_cur == NULL; 
	}

	OBJCLASS* cur() const 
	{ 
		return m_cur; 
	}

};

// ------------------------------------------------------------------------

enum WhichTurretType
{
	TURRET_INVALID = -1,

	TURRET_MAIN = 0,
	TURRET_ALT,

	MAX_TURRETS
};

// ------------------------------------------------------------------------
// this normalizes an angle to the range -PI...PI.
extern Real normalizeAngle(Real angle);

// ------------------------------------------------------------------------
// this returns the difference between a1 and a2, normalized.
inline Real stdAngleDiff(Real a1, Real a2)
{
	return normalizeAngle(a1 - a2);
}

// ------------------------------------------------------------------------
// NOTE NOTE NOTE: Keep TheRelationShipNames in sync with this enum
enum Relationship
{
	ENEMIES = 0,
	NEUTRAL,
	ALLIES
};


// TheRelationShipNames is defined in Common/GameCommon.cpp
extern const char *TheRelationshipNames[];

// ------------------------------------------------------------------------
/** strtoul( text, NULL, 10 ) as Windows answers it, where unsigned long is 32 bits: a number past
	* 0xFFFFFFFF is 0xFFFFFFFF, and a negative one is its magnitude negated modulo 2^32.  A 64-bit
	* unsigned long keeps the low 32 bits of a big number instead, so text from the network, a replay
	* or a preferences file ("SC=4294967296") would give another amount off Windows. */
#if defined(_WIN32)
inline UnsignedInt strtoulAsWindows( const char *text )
{
	return strtoul( text, NULL, 10 );
}
#else
inline UnsignedInt strtoulAsWindows( const char *text )
{
	while (*text == ' ' || (*text >= '\t' && *text <= '\r'))
		++text;
	Bool negative = FALSE;
	if (*text == '+' || *text == '-')
		negative = (*text++ == '-');
	unsigned long long magnitude = 0;
	for (; *text >= '0' && *text <= '9'; ++text)
	{
		magnitude = magnitude * 10 + (unsigned long long)(*text - '0');
		if (magnitude > 0xFFFFFFFFull)
			return 0xFFFFFFFFu;			// out of range, whatever the sign: ULONG_MAX
	}
	return negative ? 0u - (UnsignedInt)magnitude : (UnsignedInt)magnitude;
}
#endif

#endif // _GAMECOMMON_H_