#ifndef BASE_TYPES_H #define BASE_TYPES_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "aditem.h" const float cellSize = 20.f; struct srcAlienType; struct srcTowerType; struct srcSplashType; struct srcTriggerType; struct srcAlienType { QString name; float speed; float health; float armor; float regeneration; bool isFlying; unsigned int score; int imgType; QList * images; unsigned int prise; }; struct AlienType { AlienType () { id = -1; src = 0; pos = QPointF(); wave = -1; item = 0; } int id; // uses for QHash int wave; srcAlienType * src; QPointF pos; float angle; // -180 .. 180 float speed; // cells per tick (speed=1 is 60cells by 1 sec for 60fps e.g.) float health; QPoint finish; QVector path; int pathIndex; ADItem * item; }; struct srcTriggerType { enum triggerType { onDestination, onTimer, onAlienInRadius }; enum aimType { noAim, parentAim, allSide, nearestAlien }; int childId; // =-1 for none birth splash (e.q. only damage) aimType childAim; bool delParent; float damage; float radius; triggerType type; unsigned int timer; int count; float randomPosRadius; }; struct TriggerOnDest { srcTriggerType * src; }; struct TriggerOnTimer { srcTriggerType * src; unsigned int timer; }; struct TriggerOnAlien { srcTriggerType * src; QList triggerAliens; }; struct MorphType { srcTowerType * morph; float expRequired; unsigned int cost; }; struct srcTowerType { QString name; QImage * image; int imgType; //int PlayerId; // tower's owner unsigned int cost; unsigned int reload; unsigned int buildTime; float radius; // in cells float expByShot; float expByKill; float expByDamage; bool isRoot; QList triggers; QList splashes; QList morphs; }; struct TowerType { srcTowerType * src; int aim; // aim alien Id int PlayerId; // tower's owner QPoint pos; // same as Id; not QPointF because tower fixed on grid float angle; // -180 .. 180 unsigned int reload; // time for reload in ticks unsigned int build; float experience; ADItem * item; bool isBilding; }; struct srcSplashType { QString name; int imgType; float speed; // in cells int lifetime; bool autoControl; bool keepOnAlien; float animSpeed; float ZValue; QPainter::CompositionMode compositionMode; QList triggerIndexes; QList * images; }; struct SplashType { int id; srcSplashType * src; srcTowerType * srcTow; QPoint towerId; // parent tower, (0,0) or null for non parent int PlayerId; int AlienId; // aim alien (different from tower.AlienId) QPointF destination; int life; // in ticks float angle; // -180 .. 180 QPointF pos; QList trigsOnAlien; QList trigsOnDest; QList trigsOnTimer; ADItem * item; }; struct AnimationType { QList * images; }; struct WaveType { QList types; // some types of aliens (e.g. 2 fly and 3 grount in one wave) QList counts; // count aliens of each type unsigned int timeout; // time in ticks unsigned int prise; }; inline uint qHash(const QPoint &pos) { return qHash(pos.x() + (pos.y() << 16)); } inline float distance2(const QPointF &p1, const QPointF &p2) { return (p1.x()-p2.x())*(p1.x()-p2.x())+(p1.y()-p2.y())*(p1.y()-p2.y()); } template class _PIForeachC { public: _PIForeachC(const Type & t): _t(t) {_it = _t.begin(); _break = false;} typename Type::value_type _var; typename Type::const_iterator _it; const Type & _t; bool _break, _inv; inline bool isEnd() {return _it == _t.end();} inline void operator ++() {_it++; _break = false;} }; template class _PIForeach { public: _PIForeach(Type & t): _t(t) {_it = _t.begin(); _break = false;} typename Type::value_type _var; typename Type::iterator _it; Type & _t; bool _break, _inv; inline bool isEnd() {return _it == _t.end();} inline void operator ++() {_it++; _break = false;} }; #define piForTimes(c) for(int i = 0; i < c; ++i) #define piForeach(i,c) for(_PIForeach _for(c); !_for.isEnd(); ++_for) for(i = *_for._it; !_for._break; _for._break = true) #define piForeachA(i,c) for(_PIForeach _for(c); !_for.isEnd(); ++_for) for(typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true) #define piForeachC(i,c) for(_PIForeachC _for(c); !_for.isEnd(); ++_for) for(const i = *_for._it; !_for._break; _for._break = true) #define piForeachCA(i,c) for(_PIForeachC _for(c); !_for.isEnd(); ++_for) for(const typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true) #define piForeachAC piForeachCA #endif // BASE_TYPES_H