0ad/source/simulation/EntityFormation.h
janwas c0ed950657 had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).

it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.

after several hours, the code now requires fewer casts and less
guesswork.

other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.

This was SVN commit r5942.
2008-05-11 18:48:32 +00:00

72 lines
2.2 KiB
C++

//Instances of this class contain the actual information about in-game formations.
//It is based off of Formation.cpp and uses it as a reference as to what can and cannot
//be done in this formation. This is represented as m_base.
#ifndef INCLUDED_ENTITYFORMATION
#define INCLUDED_ENTITYFORMATION
#include "ps/Vector2D.h"
class CVector2D;
class CEntity;
struct CEntityList;
class CClassSet;
class CFormation;
class CEntityFormation
{
friend class CFormationManager;
public:
CEntityFormation( CFormation*& base, size_t index );
~CEntityFormation();
size_t GetEntityCount() { return m_numEntities; }
float GetSpeed() { return m_speed; }
size_t GetSlotCount();
CEntityList GetEntityList();
CVector2D GetSlotPosition( size_t order );
CVector2D GetPosition() { return m_position; }
CFormation* GetBase() { return m_base; }
void BaseToMovement();
void SelectAllUnits();
inline void SetDuplication( bool duplicate ) { m_duplication=duplicate; }
inline bool IsDuplication() { return m_duplication; }
inline void SetLock( bool lock ){ m_locked=lock; }
inline bool IsLocked() { return m_locked; }
inline bool IsValidOrder(size_t order) { return ( order < GetSlotCount() ); }
private:
size_t m_numEntities;
size_t m_index;
float m_speed; //speed of slowest unit
float m_orientation; //Our orientation angle. Used for rotation.
CVector2D m_position;
bool m_locked;
//Prevents other selected units from reordering the formation after one has already done it.
bool m_duplication;
CFormation* m_base;
CFormation* m_self; //Keeps track of base (referred to during movement switching)
std::vector<CEntity*> m_entities; //number of units currently in this formation
std::vector<bool> m_angleDivs; //attack direction penalty-true=being attacked from sector
std::vector<float> m_angleVals;
bool AddUnit( CEntity* entity );
void RemoveUnit( CEntity* entity );
bool IsSlotAppropriate( size_t order, CEntity* entity ); //If empty, can we use this slot?
bool IsBetterUnit( size_t order, CEntity* entity );
void UpdateFormation();
void SwitchBase( CFormation*& base );
void ResetIndex( size_t index );
void ResetAllEntities(); //Sets all handles to invalid
void ResetAngleDivs();
};
#endif