janwas
c0ed950657
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.
106 lines
2.7 KiB
C++
106 lines
2.7 KiB
C++
#ifndef INCLUDED_PLAYER
|
|
#define INCLUDED_PLAYER
|
|
|
|
#include "CStr.h"
|
|
#include "scripting/SynchedJSObject.h"
|
|
#include "scripting/ScriptableObject.h"
|
|
#include "scripting/ScriptCustomTypes.h"
|
|
#include "ps/scripting/JSCollection.h"
|
|
#include "Game.h"
|
|
|
|
class CNetMessage;
|
|
class HEntity;
|
|
class CTechnology;
|
|
|
|
typedef SColour SPlayerColour;
|
|
|
|
enum EDiplomaticStance
|
|
{
|
|
DIPLOMACY_ENEMY,
|
|
DIPLOMACY_NEUTRAL,
|
|
DIPLOMACY_ALLIED
|
|
};
|
|
|
|
class CPlayer : public CSynchedJSObject<CPlayer>
|
|
{
|
|
public:
|
|
typedef void (UpdateCallback)(const CStrW& name, const CStrW& value, CPlayer *player, void *userdata);
|
|
|
|
private:
|
|
CStrW m_Name;
|
|
CStrW m_Civilization; // Note: this must be the un-internationalized name of the civ
|
|
size_t m_PlayerID;
|
|
size_t m_LOSToken;
|
|
SPlayerColour m_Colour;
|
|
int /*EDiplomaticStance*/ m_DiplomaticStance[PS_MAX_PLAYERS+1];
|
|
std::vector<CTechnology*> m_ActiveTechs;
|
|
|
|
UpdateCallback *m_UpdateCB;
|
|
void *m_UpdateCBData;
|
|
|
|
virtual void Update(const CStrW& name, ISynchedJSProperty *prop);
|
|
|
|
public:
|
|
CPlayer( size_t playerID );
|
|
~CPlayer();
|
|
|
|
bool ValidateCommand(CNetMessage *pMsg);
|
|
|
|
static const size_t invalidId = ~(size_t)0;
|
|
inline size_t GetPlayerID() const
|
|
{ return m_PlayerID; }
|
|
inline void SetPlayerID(size_t id)
|
|
{ m_PlayerID=id; }
|
|
|
|
inline size_t GetLOSToken() const
|
|
{ return m_LOSToken; }
|
|
|
|
inline const CStrW& GetName() const
|
|
{ return m_Name; }
|
|
inline void SetName(const CStrW& name)
|
|
{ m_Name = name; }
|
|
|
|
inline const SPlayerColour &GetColour() const
|
|
{ return m_Colour; }
|
|
inline void SetColour(const SPlayerColour &colour)
|
|
{ m_Colour = colour; }
|
|
|
|
inline EDiplomaticStance GetDiplomaticStance(CPlayer* other) const
|
|
{ return (EDiplomaticStance)m_DiplomaticStance[other->m_PlayerID]; }
|
|
inline void SetDiplomaticStance(CPlayer* other, EDiplomaticStance stance)
|
|
{ m_DiplomaticStance[other->m_PlayerID] = stance; }
|
|
|
|
inline void SetUpdateCallback(UpdateCallback *cb, void *userdata)
|
|
{
|
|
m_UpdateCB=cb;
|
|
m_UpdateCBData=userdata;
|
|
}
|
|
void SetValue(const CStrW& name, const CStrW& value);
|
|
|
|
inline void AddActiveTech(CTechnology* tech)
|
|
{
|
|
m_ActiveTechs.push_back(tech);
|
|
}
|
|
|
|
inline const std::vector<CTechnology*>& GetActiveTechs()
|
|
{
|
|
return m_ActiveTechs;
|
|
}
|
|
|
|
void GetControlledEntities(std::vector<HEntity>& controlled_entities);
|
|
|
|
// JS Interface Functions
|
|
CStrW JSI_ToString( JSContext* context, uintN argc, jsval* argv );
|
|
jsval JSI_GetControlledEntities( JSContext* context );
|
|
void JSI_SetColour(JSContext *context, uintN argc, jsval *argv);
|
|
jsval_t JSI_GetColour(JSContext *context, uintN argc, jsval *argv);
|
|
void JSI_SetDiplomaticStance(JSContext *context, uintN argc, jsval *argv);
|
|
jsval_t JSI_GetDiplomaticStance(JSContext *context, uintN argc, jsval *argv);
|
|
|
|
static void ScriptingInit();
|
|
};
|
|
|
|
typedef CJSCollection<CPlayer*, &CPlayer::JSI_class> PlayerCollection;
|
|
|
|
#endif
|