1
0
forked from 0ad/0ad

# Fix unportable code and g++ specific warnings

* Use / instead of \ in #include path names
* g++ prefers files that end in a newline

This was SVN commit r3734.
This commit is contained in:
prefect 2006-04-08 23:47:29 +00:00
parent c38a5379f6
commit 604225f971
7 changed files with 88 additions and 83 deletions

View File

@ -2,7 +2,7 @@
#include "BaseFormation.h"
#include "CLogger.h"
#include "CStr.h"
#include "maths\MathUtil.h"
#include "maths/MathUtil.h"
#define LOG_CATEGORY "Formation"
@ -13,17 +13,17 @@ CBaseFormation::CBaseFormation()
bool CBaseFormation::loadXML(CStr filename)
{
CXeromyces XeroFile;
if (XeroFile.Load(filename) != PSRETURN_OK)
return false;
#define EL(x) int el_##x = XeroFile.getElementID(#x)
#define AT(x) int at_##x = XeroFile.getAttributeID(#x)
EL(formation);
EL(fl);
EL(rk);
EL(blank);
AT(tag);
AT(bonus);
AT(bonustype);
@ -53,7 +53,7 @@ bool CBaseFormation::loadXML(CStr filename)
LOG( ERROR, LOG_CATEGORY, "CBaseFormation::LoadXML: XML root was not \"Formation\" in file %s. Load failed.", filename.c_str() );
return( false );
}
//Load in single attributes
XMBAttributeList Attributes = Root.getAttributes();
for ( int i=0; i<Attributes.Count; ++i )
@ -73,7 +73,7 @@ bool CBaseFormation::loadXML(CStr filename)
m_penaltyType = CStr(Attr.Value);
else if ( Attr.Name == at_penaltyval )
m_penaltyVal = CStr(Attr.Value).ToFloat();
else if ( Attr.Name == at_anglepenalty )
m_anglePenalty = CStr(Attr.Value);
else if ( Attr.Name == at_anglepenaltydivs )
@ -82,7 +82,7 @@ bool CBaseFormation::loadXML(CStr filename)
m_anglePenaltyType = CStr(Attr.Value);
else if ( Attr.Name == at_anglepenaltyval )
m_anglePenaltyVal = CStr(Attr.Value).ToFloat();
else if ( Attr.Name == at_required)
m_required = CStr(Attr.Value).ToInt();
else if ( Attr.Name == at_next )
@ -107,7 +107,7 @@ bool CBaseFormation::loadXML(CStr filename)
int file=0;
int rank=0;
int maxrank=0;
//Read in files and ranks
for (int i = 0; i < RootChildren.Count; ++i)
{
@ -120,7 +120,7 @@ bool CBaseFormation::loadXML(CStr filename)
XMBAttributeList FileAttribList = RootChild.getAttributes();
//Load default category
CStr FileCatValue = FileAttribList.getNamedItem(at_category);
//Specific slots in this file (row)
XMBElementList RankNodes = RootChild.getChildNodes();
for ( int r=0; r<RankNodes.Count; ++r )
@ -138,7 +138,7 @@ bool CBaseFormation::loadXML(CStr filename)
XMBAttributeList RankAttribList = Rank.getAttributes();
int order = CStr( RankAttribList.getNamedItem(at_order) ).ToInt();
CStr category = CStr( RankAttribList.getNamedItem(at_category) );
if( order <= 0 )
{
LOG( ERROR, LOG_CATEGORY, "CBaseFormation::LoadXML: Invalid (negative number or 0) order defined in formation file %s. The game will try to continue anyway.", filename.c_str() );
@ -149,7 +149,7 @@ bool CBaseFormation::loadXML(CStr filename)
//AssignCategory(order, category);
//else
AssignCategory(order, FileCatValue);
m_slots[order].fileOff = file * m_fileSpacing;
m_slots[order].rankOff = rank * m_rankSpacing;
++m_numSlots;
@ -159,16 +159,16 @@ bool CBaseFormation::loadXML(CStr filename)
maxrank = rank;
++file;
} //if el_fl
else if ( ChildName == el_blank )
++file;
}
float centerx = maxrank * m_rankSpacing / 2.0f;
float centery = file * m_fileSpacing / 2.0f;
//Here we check to make sure no order was skipped over. If so, failure, because we rely
//on a linearly accessible slots in entityformation.cpp.
//on a linearly accessible slots in entityformation.cpp.
for ( int i=0; i<m_numSlots; ++i )
{
if ( m_slots.find(i) == m_slots.end() )
@ -181,7 +181,7 @@ bool CBaseFormation::loadXML(CStr filename)
m_slots[i].rankOff = m_slots[i].rankOff - centerx;
m_slots[i].fileOff = m_slots[i].fileOff - centery;
}
}
return true;
}
@ -191,7 +191,7 @@ void CBaseFormation::AssignCategory(int order, CStr category)
category.Remove( CStr(",") );
category = category + " "; //So the final word will be pushed as well
CStr temp;
//Push categories until last space
while ( ( temp = category.BeforeFirst(" ") ) != "" )
{

View File

@ -27,7 +27,7 @@ struct FormationSlot
public:
CBaseFormation();
~CBaseFormation(){}
CStr GetBonus(){ return m_bonus; }
CStr GetBonusType(){ return m_bonusType; }
float GetBonusVal(){ return m_bonusVal; }
@ -43,7 +43,7 @@ public:
private:
CStr m_tag;
CStr m_bonus;
CStr m_bonusType;
@ -64,16 +64,16 @@ private:
CStr m_movement;
float m_fileSpacing;
float m_rankSpacing;
int m_numSlots; //how many possible slots in this formation
int m_numRanks;
int m_numFiles;
//The key is the "order" of the slot
//The key is the "order" of the slot
std::map<int, FormationSlot> m_slots;
std::vector<float> m_angleValues; //cosine of angle divisions
bool loadXML(CStr filename);
void AssignCategory(int order, CStr category); //takes care of formatting strings
};
#endif
#endif

View File

@ -1,7 +1,7 @@
// Entity.h
//
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
//
//
// Entity class.
//
// Usage: Do not attempt to instantiate this class directly. (See EntityManager.h)
@ -17,7 +17,7 @@
// prior to its next update cycle.
//
// CUnit* m_actor: is the visible representation of this entity.
//
//
// snapToGround(): Called every frame, this will ensure the entity never takes flight.
// updateActorTransforms(): Must be called every time the position of this entity changes.
// Also remember to update the collision object if you alter the position directly.
@ -53,7 +53,7 @@ class CEntityFormation;
class CEntity : public CJSComplex<CEntity>, public IEventTarget
{
friend class CEntityManager;
typedef STL_HASH_MAP<CStrW, CAura*, CStrW_hash_compare> AuraTable;
typedef STL_HASH_MAP<int, SEntityAction> ActionTable;
typedef std::set<CAura*> AuraSet;
@ -64,7 +64,7 @@ public:
// Intrinsic properties
CBaseEntity* m_base;
// The entity to switch to when this dies.
CStrW m_corpse;
@ -78,7 +78,7 @@ public:
float m_turningRadius;
float m_runRegenRate;
float m_runDecayRate;
float m_healthRegenRate;
float m_healthRegenStart;
float m_healthDecayRate;
@ -90,7 +90,7 @@ public:
bool m_selected;
i32 m_grouped;
int m_formation; //Indice of which formation we're in
int m_formationSlot; //The slot of the above formation
int m_formationSlot; //The slot of the above formation
// If this unit has been removed from the gameworld but has still
// has references.
@ -103,7 +103,7 @@ public:
bool m_shouldRun; //if run was issued, it will remain true until it is stopped
bool m_triggerRun; //used in SetRun, corrects 1 frame stamina imbalance
int m_frameCheck; //counts the frame
float m_lastCombatTime;
// Building to convert to if this is a foundation, or "" otherwise
@ -130,14 +130,14 @@ public:
int m_healthBorderWidth;
int m_healthBorderHeight;
CStr m_healthBorderName;
//Rank properties
float m_rankHeight;
int m_rankWidth;
CStr m_rankName;
bool m_healthDecay;
// Minimap properties
CStrW m_minimapType;
int m_minimapR;
@ -189,7 +189,7 @@ public:
// State transition in the FSM (animations should be reset)
bool m_transition;
int m_lastState;
// Position in the current state's cycle
static const size_t NOT_IN_CYCLE = (size_t)-1;
size_t m_fsm_cyclepos; // -cycle_length....cycle_length
@ -197,19 +197,19 @@ public:
size_t m_fsm_anipos; // the time at which we should start playing it.
size_t m_fsm_anipos2; // for when there are two animation-related events we need to take care of.
std::deque<CEntityOrder> m_orderQueue;
std::deque<CEntityOrder> m_orderQueue;
std::deque<CEntityListener> m_listeners;
std::vector<CEntity*> m_notifiers;
int m_currentNotification; //Current order in the form of a notification code
int m_currentRequest; //Notification we our notifiers are sending
int m_currentRequest; //Notification we our notifiers are sending
bool m_destroyNotifiers; //True: we destroy them. False: the script does.
std::vector<bool> m_sectorValues;
std::vector<float> m_sectorAngles;
int m_sectorDivs;
float m_sectorPenalty;
private:
CEntity( CBaseEntity* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections, CStrW building = L"" );
@ -222,7 +222,7 @@ private:
bool processGenericNoPathing( CEntityOrder* current, size_t timestep_milli );
bool processProduce( CEntityOrder* order );
bool processGotoNoPathing( CEntityOrder* current, size_t timestep_milli );
bool processGoto( CEntityOrder* current, size_t timestep_milli );
@ -261,7 +261,7 @@ public:
void SetPlayer(CPlayer *pPlayer);
// Retrieve the player associated with this entity
CPlayer* GetPlayer() { return m_player; }
CPlayer* GetPlayer() { return m_player; }
// Update collision patch (move ourselves to a new one if necessary)
void updateCollisionPatch();
@ -286,7 +286,7 @@ public:
CVector2D getScreenCoords( float height );
// After a collision, recalc the path to the next fixed waypoint.
void repath();
//Calculate stamina points
void CalculateRun(float timestep);
void CalculateHealth(float timestep);
@ -304,7 +304,7 @@ public:
void clearOrders();
void popOrder(); //Use this if and order has finished instead of m_orderQueue.pop_front()
void pushOrder( CEntityOrder& order );
void DispatchNotification( CEntityOrder order, int type );
int DestroyNotifier( CEntity* target ); //Stop notifier from sending to us
void DestroyAllNotifiers();
@ -318,7 +318,7 @@ public:
jsval GetFormationBonus( JSContext* cx, uintN argc, jsval* argv );
jsval GetFormationBonusType( JSContext* cx, uintN argc, jsval* argv );
jsval GetFormationBonusVal( JSContext* cx, uintN argc, jsval* argv );
void DispatchFormationEvent( int type );
jsval RegisterDamage( JSContext* cx, uintN argc, jsval* argv );
@ -331,7 +331,7 @@ public:
// Script-bound functions
jsval ToString( JSContext* cx, uintN argc, jsval* argv );
bool Kill( JSContext* cx, uintN argc, jsval* argv );
jsval GetSpawnPoint( JSContext* cx, uintN argc, jsval* argv );
@ -353,7 +353,7 @@ public:
bool IsInFormation( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
{
return ( m_formation != NULL ? true : false );
return ( m_formation != 0 ? true : false );
}
bool Order( JSContext* cx, uintN argc, jsval* argv, bool Queued );
@ -398,7 +398,7 @@ private:
// In its current incarnation, inefficient but pretty
#define SELECTION_TERRAIN_CONFORMANCE
#define SELECTION_TERRAIN_CONFORMANCE
extern int SELECTION_CIRCLE_POINTS;
extern int SELECTION_BOX_POINTS;

View File

@ -3,9 +3,9 @@
#include "BaseFormationCollection.h"
#include "FormationManager.h"
#include "Simulation.h"
#include "ps\Game.h"
#include "ps\Interact.h"
#include "ps\Network\NetMessage.h"
#include "ps/Game.h"
#include "ps/Interact.h"
#include "ps/Network/NetMessage.h"
CEntityFormation::CEntityFormation( CBaseFormation*& base, size_t index )
{
@ -16,7 +16,7 @@ CEntityFormation::CEntityFormation( CBaseFormation*& base, size_t index )
m_numEntities=0;
m_speed=0.0f;
m_orientation = 0.0f;
m_position.x = m_position.y = -1.0f;
m_duplication=false;
m_entities.resize(m_base->m_numSlots);
@ -68,12 +68,12 @@ bool CEntityFormation::AddUnit( CEntity*& entity )
m_entities[i] = entity;
AddUnit( prev );
}
m_entities[i] = entity;
++m_numEntities;
entity->m_formation = m_index;
entity->m_formationSlot = i;
return true;
}
}
@ -87,7 +87,7 @@ void CEntityFormation::RemoveUnit( CEntity*& entity )
m_entities[entity->m_formationSlot] = NULL;
entity->m_formation = -1;
entity->m_formationSlot = -1;
--m_numEntities;
//UpdateFormation();
}
@ -96,7 +96,7 @@ bool CEntityFormation::IsSlotAppropriate( int order, CEntity* entity )
debug_assert( entity );
if ( !IsValidOrder(order) )
return false;
for ( size_t idx=0; idx < m_base->m_slots[order].category.size(); ++idx )
{
CStr tmp( m_base->m_slots[order].category[idx] );
@ -120,7 +120,7 @@ bool CEntityFormation::IsBetterUnit( int order, CEntity* entity )
CStr cat = m_base->m_slots[order].category[idx];
bool current=false;
bool newEnt=false;
current = m_entities[order]->m_classes.IsMember( cat );
newEnt = entity->m_classes.IsMember( cat );
@ -130,7 +130,7 @@ bool CEntityFormation::IsBetterUnit( int order, CEntity* entity )
return false;
}
void CEntityFormation::UpdateFormation()
void CEntityFormation::UpdateFormation()
{
//Get the entities in the right order (as in, ordered correctly and in the right order/slot)
for ( int i=1; i<m_base->m_numSlots; ++i )
@ -146,7 +146,7 @@ void CEntityFormation::UpdateFormation()
CEntity* temp = m_entities[j];
m_entities[j] = m_entities[i];
m_entities[i] = temp;
int tmpSlot = m_entities[i]->m_formationSlot;
m_entities[i]->m_formationSlot = m_entities[j]->m_formationSlot;
m_entities[j]->m_formationSlot = tmpSlot;
@ -157,7 +157,7 @@ void CEntityFormation::UpdateFormation()
CEntityList entities = GetEntityList();
CNetMessage* msg = CNetMessage::CreatePositionMessage( entities, NMT_FormationGoto, m_position );
g_Game->GetSimulation()->QueueLocalCommand(msg);
}
void CEntityFormation::ResetAllEntities()
@ -192,7 +192,7 @@ CEntityList CEntityFormation::GetEntityList()
CVector2D CEntityFormation::GetSlotPosition( int order )
{
if ( IsValidOrder(order) )
if ( IsValidOrder(order) )
return CVector2D ( m_base->m_slots[order].rankOff, m_base->m_slots[order].fileOff );
return CVector2D(-1, -1);
}
@ -209,7 +209,7 @@ void CEntityFormation::BaseToMovement()
void CEntityFormation::ResetIndex( size_t index )
{
m_index = (int)index;
for ( size_t i=0; i< m_entities.size(); ++i )
{
if ( m_entities[i] )

View File

@ -21,11 +21,11 @@ class CEntityFormation
public:
CEntityFormation( CBaseFormation*& base, size_t index );
~CEntityFormation();
int GetEntityCount() { return m_numEntities; }
float GetSpeed() { return m_speed; }
int GetSlotCount() { return m_base->m_numSlots; }
CEntityList GetEntityList();
CVector2D GetSlotPosition( int order );
CVector2D GetPosition() { return m_position; }
@ -33,7 +33,7 @@ public:
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; }
@ -49,25 +49,25 @@ private:
bool m_locked;
//Prevents other selected units from reordering the formation after one has already done it.
bool m_duplication;
bool m_duplication;
CBaseFormation* m_base;
CBaseFormation* 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( int order, CEntity* entity ); //If empty, can we use this slot?
bool IsBetterUnit( int order, CEntity* entity );
void UpdateFormation();
void SwitchBase( CBaseFormation*& base );
void ResetIndex( size_t index );
void ResetAllEntities(); //Sets all handles to invalid
void ResetAngleDivs();
};
#endif
#endif

View File

@ -9,9 +9,9 @@
#include "ps/Vector2D.h"
CFormationManager::~CFormationManager()
{
{
for ( size_t i=0; i<m_formations.size(); i++ )
delete m_formations[i];
delete m_formations[i];
}
void CFormationManager::CreateFormation( CEntityList& entities, CStrW& name )
{
@ -25,18 +25,18 @@ void CFormationManager::CreateFormation( CEntityList& entities, CStrW& name )
return;
if ( entities.size() < (size_t)base->m_required )
return;
CEntityFormation* tmp = new CEntityFormation( base, m_formations.size() );
m_formations.push_back( tmp );
CEntityList accepted = AddUnitList( entities, (int)m_formations.size()-1 );
//Find average position
CVector3D average( 0.0f, 0.0f, 0.0f );
for ( CEntityList::iterator it=accepted.begin(); it != accepted.end(); it++ )
average += (*it)->m_position;
average = average * ( 1.0f / (float)entities.size() );
CVector2D average2D(average.X, average.Z);
m_formations.back()->m_position = average2D;
m_formations.back()->UpdateFormation();
@ -63,14 +63,14 @@ void CFormationManager::DestroyFormation( size_t form )
*it = NULL;
m_formations.erase( it );
UpdateIndexes( form );
}
}
bool CFormationManager::AddUnit( CEntity*& entity, int& form )
{
if ( !IsValidFormation(form) )
return false;
if ( entity->m_formation > -1 )
{
{
if ( !RemoveUnit( entity ) )
--form;
}
@ -104,7 +104,7 @@ bool CFormationManager::RemoveUnit( CEntity*& entity )
{
if ( !IsValidFormation(entity->m_formation) )
return true;
FormIterator it = m_formations.begin() + entity->m_formation;
if ( (*it)->m_numEntities == (*it)->m_base->m_required )
{
@ -130,8 +130,8 @@ bool CFormationManager::RemoveUnitList( CEntityList& entities )
}
return true;
}
CEntityFormation* CFormationManager::GetFormation(int form)
{
CEntityFormation* CFormationManager::GetFormation(int form)
{
if ( IsValidFormation(form) )
return m_formations[form];
return NULL;
@ -140,4 +140,4 @@ void CFormationManager::UpdateIndexes( size_t update )
{
for ( ; update < m_formations.size(); update++ )
m_formations[update]->ResetIndex( update );
}
}

View File

@ -2,6 +2,9 @@
//ajdecker1022@msn.com
//This keeps track of all the formations exisisting in the game.
#ifndef FORMATIONMANAGER_INCLUDED
#define FORMATIONMANAGER_INCLUDED
#include "ps/Singleton.h"
#include "BaseFormationCollection.h"
#include "scripting/DOMEvent.h"
@ -32,7 +35,7 @@ public:
}
bool AddUnit( CEntity*& entity, int& form );
CEntityList AddUnitList( CEntityList& entities, int form );
//Returns false if the formation is destroyed
bool RemoveUnit( CEntity*& entity );
bool RemoveUnitList( CEntityList& entities );
@ -41,4 +44,6 @@ public:
private:
std::vector<CEntityFormation*> m_formations;
};
};
#endif // FORMATIONMANAGER_INCLUDED