0ad/source/simulation/Technology.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

99 lines
2.4 KiB
C++

// Holds effects of a technology (research item), as well as its status
// (unavailable, researched, in progress, etc).
//
// There is a separate CTechnology object for each tech for each player,
// because the status can be different for different players.
#ifndef INCLUDED_TECHNOLOGY
#define INCLUDED_TECHNOLOGY
#include <vector>
#include "scripting/ScriptableComplex.h"
#include "simulation/ScriptObject.h"
#include "ps/Game.h"
class XMBElement;
class CXeromyces;
class CEntity;
class CTechnology : public CJSComplex<CTechnology>
{
friend class CTechnologyCollection;
struct Modifier
{
CStr attribute;
float value;
bool isPercent;
Modifier(): value(0), isPercent(false) {}
};
static STL_HASH_SET<CStr, CStr_hash_compare> m_scriptsLoaded;
public:
CTechnology(const CStrW& name, CPlayer* player);
~CTechnology() {}
// noncopyable (avoid VC7.1 warning); don't derive from
// boost::noncopyable, so that multiple inheritance is avoided
private:
CTechnology(const CTechnology&);
const CTechnology& operator=(const CTechnology&);
public:
//JS functions
static void ScriptingInit();
bool ApplyEffects( JSContext* cx, uintN argc, jsval* argv );
bool IsValid( JSContext* cx, uintN argc, jsval* argv );
bool IsResearched( JSContext* cx, uintN argc, jsval* argv );
bool IsExcluded( JSContext* cx, uintN argc, jsval* argv );
size_t GetPlayerID( JSContext* cx, uintN argc, jsval* argv );
void Apply( CEntity* entity );
bool IsTechValid();
inline bool IsResearched() { return m_researched; }
void SetExclusion( bool exclude ) { m_excluded=exclude; }
bool LoadXml( const CStr& filename );
bool LoadElId( XMBElement ID, CXeromyces& XeroFile );
bool LoadElReq( XMBElement Req, CXeromyces& XeroFile );
bool LoadElEffect( XMBElement Effect, CXeromyces& XeroFile, const CStr& filename );
private:
CStrW m_Name; // name of the tech file
CStrW m_Generic;
CStrW m_Specific;
CStrW m_Icon;
int m_IconCell;
CStrW m_Classes;
CStrW m_History;
float m_ReqTime;
std::vector<CStr> m_ReqEntities;
std::vector<CStr> m_ReqTechs;
std::vector<CStr> m_Pairs;
std::vector<CStr> m_Targets;
std::vector<Modifier> m_Modifiers;
std::vector<Modifier> m_Sets;
CPlayer* m_player; //Which player this tech object belongs to
CScriptObject m_effectFunction;
bool m_excluded;
bool m_researched;
bool m_inProgress;
bool HasReqEntities();
bool HasReqTechs();
// Hack: shouldn't be part of CJSComplex
void RebuildClassSet() {};
};
#endif