This commit is contained in:
joris 2014-01-06 22:49:57 +01:00
parent 19176cbe1d
commit f7ef97a7df
81 changed files with 486 additions and 294 deletions

View file

@ -251,7 +251,7 @@ static void EnterTransporter(CUnit &unit, COrder_Board &order)
/* virtual */ void COrder_Board::Execute(CUnit &unit)
{
switch (this->State) {
// Wait for transporter
// Wait for transporter
case State_WaitForTransporter:
if (this->WaitForTransporter(unit)) {
this->State = State_EnterTransporter;
@ -271,7 +271,7 @@ static void EnterTransporter(CUnit &unit, COrder_Board &order)
return;
}
this->State = 1;
// FALL THROUGH
// FALL THROUGH
default: { // Move to transporter
if (this->State <= State_MoveToTransporterMax) {
const int pathRet = MoveToTransporter(unit);

View file

@ -248,11 +248,13 @@ class AlreadyBuildingFinder
public:
AlreadyBuildingFinder(const CUnit &unit, const CUnitType &t) :
worker(&unit), type(&t) {}
bool operator()(const CUnit *const unit) const {
bool operator()(const CUnit *const unit) const
{
return (!unit->Destroyed && unit->Type == type
&& (worker->Player == unit->Player || worker->IsAllied(*unit)));
}
CUnit *Find(const CMapField *const mf) const {
CUnit *Find(const CMapField *const mf) const
{
return mf->UnitCache.find(*this);
}
private:

View file

@ -123,7 +123,7 @@ extern void AiReduceMadeInBuilt(PlayerAi &pai, const CUnitType &type);
return true;
}
/* virtual */ PixelPos COrder_Built::Show(const CViewport & , const PixelPos &lastScreenPos) const
/* virtual */ PixelPos COrder_Built::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
return lastScreenPos;
}

View file

@ -70,7 +70,7 @@
return true;
}
/* virtual */ PixelPos COrder_Die::Show(const CViewport & , const PixelPos &lastScreenPos) const
/* virtual */ PixelPos COrder_Die::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
return lastScreenPos;
}

View file

@ -242,7 +242,7 @@ static void AnimateActionRepair(CUnit &unit)
switch (this->State) {
case 0:
this->State = 1;
// FALL THROUGH
// FALL THROUGH
case 1: { // Move near to target.
// FIXME: RESET FIRST!! Why? We move first and than check if
// something is in sight.

View file

@ -98,7 +98,7 @@
return true;
}
/* virtual */ PixelPos COrder_Research::Show(const CViewport & , const PixelPos &lastScreenPos) const
/* virtual */ PixelPos COrder_Research::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
return lastScreenPos;
}

View file

@ -339,7 +339,7 @@ bool COrder_SpellCast::SpellMoveToTarget(CUnit &unit)
// FIXME FIXME FIXME: Check if already in range and skip straight to 2(casting)
unit.ReCast = 0; // repeat spell on next pass? (defaults to `no')
this->State = 1;
// FALL THROUGH
// FALL THROUGH
case 1: // Move to the target.
if (spell.Range && spell.Range != INFINITE_RANGE) {
if (SpellMoveToTarget(unit) == true) {
@ -352,7 +352,7 @@ bool COrder_SpellCast::SpellMoveToTarget(CUnit &unit)
} else {
this->State = 2;
}
// FALL THROUGH
// FALL THROUGH
case 2: // Cast spell on the target.
if (!spell.IsCasterOnly() || spell.ForceUseAnimation) {
AnimateActionSpellCast(unit, *this);

View file

@ -98,7 +98,7 @@ enum {
return true;
}
/* virtual */ PixelPos COrder_Still::Show(const CViewport & , const PixelPos &lastScreenPos) const
/* virtual */ PixelPos COrder_Still::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
if (this->Action == UnitActionStandGround) {
Video.FillCircleClip(ColorBlack, lastScreenPos, 2);
@ -113,12 +113,14 @@ class IsTargetInRange
public:
explicit IsTargetInRange(const CUnit &_attacker) : attacker(&_attacker) {}
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return unit->IsVisibleAsGoal(*attacker->Player)
&& IsDistanceCorrect(attacker->MapDistanceTo(*unit));
}
private:
bool IsDistanceCorrect(int distance) const {
bool IsDistanceCorrect(int distance) const
{
return attacker->Type->MinAttackRange < distance
&& distance <= attacker->Stats->Variables[ATTACKRANGE_INDEX].Max;
}
@ -218,7 +220,8 @@ class IsAReparableUnitBy
{
public:
explicit IsAReparableUnitBy(const CUnit &_worker) : worker(&_worker) {}
bool operator()(CUnit *unit) const {
bool operator()(CUnit *unit) const
{
return (unit->IsTeamed(*worker)
&& unit->Type->RepairHP
&& unit->Variable[HP_INDEX].Value < unit->Variable[HP_INDEX].Max

View file

@ -96,7 +96,7 @@
return true;
}
/* virtual */ PixelPos COrder_Train::Show(const CViewport & , const PixelPos &lastScreenPos) const
/* virtual */ PixelPos COrder_Train::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
return lastScreenPos;
}

View file

@ -409,7 +409,7 @@ bool COrder_Unload::LeaveTransporter(CUnit &transporter)
}
this->State = 1;
// follow on next case
// follow on next case
case 1: // Move unit to destination
// The Goal is the unit that we have to unload.
if (!this->HasGoal()) {

View file

@ -192,7 +192,7 @@ static int TransformUnitIntoType(CUnit &unit, const CUnitType &newtype)
}
/* virtual */ PixelPos COrder_TransformInto::Show(const CViewport & , const PixelPos &lastScreenPos) const
/* virtual */ PixelPos COrder_TransformInto::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
return lastScreenPos;
}
@ -238,7 +238,7 @@ static int TransformUnitIntoType(CUnit &unit, const CUnitType &newtype)
return true;
}
/* virtual */ PixelPos COrder_UpgradeTo::Show(const CViewport & , const PixelPos &lastScreenPos) const
/* virtual */ PixelPos COrder_UpgradeTo::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
return lastScreenPos;
}

View file

@ -148,7 +148,8 @@ public:
worker(worker), type(type),
movemask(worker.Type->MovementMask & ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit)),
checkSurround(checkSurround),
resultPos(resultPos) {
resultPos(resultPos)
{
resultPos->x = -1;
resultPos->y = -1;
}

View file

@ -60,13 +60,15 @@ template <const int FIND_TYPE>
class AiForceEnemyFinder
{
public:
AiForceEnemyFinder(int force, const CUnit **enemy) : enemy(enemy) {
AiForceEnemyFinder(int force, const CUnit **enemy) : enemy(enemy)
{
Assert(enemy != NULL);
*enemy = NULL;
AiPlayer->Force[force].Units.for_each_if(*this);
}
AiForceEnemyFinder(AiForce &force, const CUnit **enemy) : enemy(enemy) {
AiForceEnemyFinder(AiForce &force, const CUnit **enemy) : enemy(enemy)
{
Assert(enemy != NULL);
*enemy = NULL;
force.Units.for_each_if(*this);
@ -74,7 +76,8 @@ public:
bool found() const { return *enemy != NULL; }
bool operator()(const CUnit *const unit) const {
bool operator()(const CUnit *const unit) const
{
if (unit->Type->CanAttack == false) {
return *enemy == NULL;
}
@ -99,7 +102,8 @@ class IsAnAlliedUnitOf
{
public:
explicit IsAnAlliedUnitOf(const CPlayer &_player) : player(&_player) {}
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return unit->IsVisibleAsGoal(*player) && (unit->Player->Index == player->Index
|| unit->IsAllied(*player));
}
@ -178,7 +182,8 @@ int AiFindUnitTypeEquiv(const CUnitType &unittype, int *result)
class UnitTypePrioritySorter_Decreasing
{
public:
bool operator()(int lhs, int rhs) const {
bool operator()(int lhs, int rhs) const
{
return UnitTypes[lhs]->Priority > UnitTypes[rhs]->Priority;
}
};
@ -216,11 +221,13 @@ int AiFindAvailableUnitTypeEquiv(const CUnitType &unittype, int *usableTypes)
class AiForceCounter
{
public:
AiForceCounter(CUnitCache &units, unsigned int *d, const size_t len) : data(d) {
AiForceCounter(CUnitCache &units, unsigned int *d, const size_t len) : data(d)
{
memset(data, 0, len);
units.for_each(*this);
}
inline void operator()(const CUnit *const unit) const {
inline void operator()(const CUnit *const unit) const
{
data[UnitTypeEquivs[unit->Type->Slot]]++;
}
private:

View file

@ -121,11 +121,13 @@ public:
AiForce() :
Completed(false), Defending(false), Attacking(false),
Role(AiForceRoleDefault), State(AiForceAttackingState_Free),
WaitOnRallyPoint(AI_WAIT_ON_RALLY_POINT) {
WaitOnRallyPoint(AI_WAIT_ON_RALLY_POINT)
{
HomePos.x = HomePos.y = GoalPos.x = GoalPos.y = -1;
}
void Remove(CUnit &unit) {
void Remove(CUnit &unit)
{
if (Units.Remove(&unit)) {
InternalRemoveUnit(&unit);
}
@ -134,7 +136,8 @@ public:
/**
** Reset the force. But don't change its role and its demand.
*/
void Reset(bool types = false) {
void Reset(bool types = false)
{
Completed = false;
Defending = false;
Attacking = false;
@ -204,7 +207,8 @@ public:
const AiForce &operator[](unsigned int index) const { return forces[index]; }
AiForce &operator[](unsigned int index) { return forces[index]; }
int getIndex(AiForce *force) const {
int getIndex(AiForce *force) const
{
for (unsigned int i = 0; i < forces.size(); ++i) {
if (force == &forces[i]) {
return i;
@ -213,7 +217,8 @@ public:
return -1;
}
unsigned int getScriptForce(unsigned int index) {
unsigned int getScriptForce(unsigned int index)
{
if (script[index] == -1) {
script[index] = FindFreeForce();
}
@ -239,7 +244,8 @@ private:
class AiBuildQueue
{
public:
AiBuildQueue() : Want(0), Made(0), Type(NULL), Wait(0) {
AiBuildQueue() : Want(0), Made(0), Type(NULL), Wait(0)
{
Pos.x = Pos.y = -1;
}
@ -273,7 +279,8 @@ public:
PlayerAi() : Player(NULL), AiType(NULL),
SleepCycles(0), NeededMask(0), NeedSupply(false),
ScriptDebug(false), LastExplorationGameCycle(0),
LastCanNotMoveGameCycle(0), LastRepairBuilding(0) {
LastCanNotMoveGameCycle(0), LastRepairBuilding(0)
{
memset(Reserve, 0, sizeof(Reserve));
memset(Used, 0, sizeof(Used));
memset(Needed, 0, sizeof(Needed));

View file

@ -59,10 +59,12 @@ class _EnemyOnMapTile
{
public:
_EnemyOnMapTile(const CUnit &unit, const Vec2i _pos, CUnit **enemy) :
source(&unit) , pos(_pos), best(enemy) {
source(&unit) , pos(_pos), best(enemy)
{
}
void operator()(CUnit *const unit) const {
void operator()(CUnit *const unit) const
{
const CUnitType &type = *unit->Type;
// unusable unit ?
// if (unit->IsUnusable()) can't attack constructions
@ -302,7 +304,8 @@ static bool AiFindTarget(const CUnit &unit, const TerrainTraversal &terrainTrans
class IsAFreeTransporter
{
public:
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return unit->Type->CanMove() && unit->BoardCount < unit->Type->MaxOnBoard;
}
};

View file

@ -170,7 +170,8 @@ class IsAEnemyUnitOf
{
public:
explicit IsAEnemyUnitOf(const CPlayer &_player) : player(&_player) {}
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return unit->IsVisibleAsGoal(*player) && unit->IsEnemy(*player);
}
private:
@ -183,7 +184,8 @@ public:
explicit IsAEnemyUnitWhichCanCounterAttackOf(const CPlayer &_player, const CUnitType &_type) :
player(&_player), type(&_type)
{}
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return unit->IsVisibleAsGoal(*player)
&& unit->IsEnemy(*player)
&& CanTarget(*unit->Type, *type);
@ -430,7 +432,8 @@ class IsAWorker
{
public:
explicit IsAWorker() {}
bool operator()(const CUnit *const unit) const {
bool operator()(const CUnit *const unit) const
{
return (unit->Type->Harvester && unit->Type->ResInfo && !unit->Removed);
}
};
@ -439,7 +442,8 @@ class CompareDepotsByDistance
{
public:
explicit CompareDepotsByDistance(const CUnit &worker) : worker(worker) {}
bool operator()(const CUnit *lhs, const CUnit *rhs) const {
bool operator()(const CUnit *lhs, const CUnit *rhs) const
{
return lhs->MapDistanceTo(worker) < rhs->MapDistanceTo(worker);
}
private:

View file

@ -133,7 +133,8 @@ static gcn::Slider *editorSlider;
class EditorUnitSliderListener : public gcn::ActionListener
{
public:
virtual void action(const std::string &) {
virtual void action(const std::string &)
{
const int iconsPerStep = VisibleUnitIcons;
const int steps = (Editor.ShownUnitTypes.size() + iconsPerStep - 1) / iconsPerStep;
const double value = editorUnitSlider->getValue();
@ -151,7 +152,8 @@ static EditorUnitSliderListener *editorUnitSliderListener;
class EditorSliderListener : public gcn::ActionListener
{
public:
virtual void action(const std::string &) {
virtual void action(const std::string &)
{
const int iconsPerStep = VisibleTileIcons;
const int steps = (Editor.ShownTileTypes.size() + iconsPerStep - 1) / iconsPerStep;
const double value = editorSlider->getValue();
@ -1271,14 +1273,14 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar)
}
break;
// FIXME: move to lua
// FIXME: move to lua
case 'r': // CTRL+R Randomize map
if (KeyModifiers & ModifierControl) {
Editor.CreateRandomMap();
}
break;
// FIXME: move to lua
// FIXME: move to lua
case 'm': // CTRL+M Mirror edit
if (KeyModifiers & ModifierControl) {
++MirrorEdit;

View file

@ -73,7 +73,8 @@ class LogEntry
{
public:
LogEntry() : GameCycle(0), Flush(0), PosX(0), PosY(0), DestUnitNumber(0),
Num(0), SyncRandSeed(0), Next(NULL) {
Num(0), SyncRandSeed(0), Next(NULL)
{
UnitNumber = 0;
}
@ -114,7 +115,8 @@ public:
FullReplay() :
MapId(0), Type(0), Race(0), LocalPlayer(0),
Resource(0), NumUnits(0), Difficulty(0), NoFow(false), RevealMap(0),
MapRichness(0), GameType(0), Opponents(0), Commands(NULL) {
MapRichness(0), GameType(0), Opponents(0), Commands(NULL)
{
memset(Engine, 0, sizeof(Engine));
memset(Network, 0, sizeof(Network));
}

View file

@ -38,7 +38,8 @@ class COrder_Build : public COrder
{
friend COrder *COrder::NewActionBuild(const CUnit &builder, const Vec2i &pos, CUnitType &building);
public:
COrder_Build() : COrder(UnitActionBuild), Type(NULL), State(0), Range(0) {
COrder_Build() : COrder(UnitActionBuild), Type(NULL), State(0), Range(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -38,7 +38,8 @@ class COrder_Defend : public COrder
{
friend COrder *COrder::NewActionDefend(CUnit &dest);
public:
COrder_Defend() : COrder(UnitActionDefend), State(0), Range(0) {
COrder_Defend() : COrder(UnitActionDefend), State(0), Range(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -38,7 +38,8 @@ class COrder_Follow : public COrder
{
friend COrder *COrder::NewActionFollow(CUnit &dest);
public:
COrder_Follow() : COrder(UnitActionFollow), State(0), Range(0) {
COrder_Follow() : COrder(UnitActionFollow), State(0), Range(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -38,7 +38,8 @@ class COrder_Move : public COrder
{
friend COrder *COrder::NewActionMove(const Vec2i &pos);
public:
COrder_Move() : COrder(UnitActionMove), Range(0) {
COrder_Move() : COrder(UnitActionMove), Range(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -38,7 +38,8 @@ class COrder_Patrol : public COrder
{
friend COrder *COrder::NewActionPatrol(const Vec2i &currentPos, const Vec2i &dest);
public:
COrder_Patrol() : COrder(UnitActionPatrol), WaitingCycle(0), Range(0) {
COrder_Patrol() : COrder(UnitActionPatrol), WaitingCycle(0), Range(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -39,7 +39,8 @@ class COrder_Repair : public COrder
friend COrder *COrder::NewActionRepair(CUnit &unit, CUnit &target);
friend COrder *COrder::NewActionRepair(const Vec2i &pos);
public:
COrder_Repair() : COrder(UnitActionRepair), State(0), RepairCycle(0) {
COrder_Repair() : COrder(UnitActionRepair), State(0), RepairCycle(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -42,7 +42,8 @@ class COrder_Resource : public COrder
public:
COrder_Resource(CUnit &harvester) : COrder(UnitActionResource), worker(&harvester),
CurrentResource(0), State(0), TimeToHarvest(0), DoneHarvesting(false) {
CurrentResource(0), State(0), TimeToHarvest(0), DoneHarvesting(false)
{
Resource.Pos.x = Resource.Pos.y = -1;
goalPos.x = goalPos.y = -1;
}

View file

@ -38,7 +38,8 @@ class COrder_SpellCast : public COrder
{
friend COrder *COrder::NewActionSpellCast(const SpellType &spell, const Vec2i &pos, CUnit *target);
public:
COrder_SpellCast() : COrder(UnitActionSpellCast), Spell(NULL), State(0), Range(0) {
COrder_SpellCast() : COrder(UnitActionSpellCast), Spell(NULL), State(0), Range(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -38,7 +38,8 @@ class COrder_Unload : public COrder
{
friend COrder *COrder::NewActionUnload(const Vec2i &pos, CUnit *what);
public:
COrder_Unload() : COrder(UnitActionUnload), State(0) {
COrder_Unload() : COrder(UnitActionUnload), State(0)
{
goalPos.x = -1;
goalPos.y = -1;
}

View file

@ -93,7 +93,8 @@ struct lua_State;
class COrder
{
public:
explicit COrder(int action) : Goal(), Action(action), Finished(false) {
explicit COrder(int action) : Goal(), Action(action), Finished(false)
{
}
virtual ~COrder();

View file

@ -109,12 +109,14 @@ class CAnimations
public:
CAnimations() : Attack(NULL), Build(NULL), Move(NULL), Repair(NULL),
Research(NULL), SpellCast(NULL), Start(NULL), Still(NULL),
Train(NULL), Upgrade(NULL) {
Train(NULL), Upgrade(NULL)
{
memset(Death, 0, sizeof(Death));
memset(Harvest, 0, sizeof(Harvest));
}
~CAnimations() {
~CAnimations()
{
delete Attack;
delete Build;
for (int i = 0; i < ANIMATIONS_DEATHTYPES + 1; ++i) {

View file

@ -126,7 +126,8 @@ class CConstruction
{
public:
CConstruction() : Frames(NULL), Sprite(NULL), Width(0),
Height(0), ShadowSprite(NULL), ShadowWidth(0), ShadowHeight(0) {
Height(0), ShadowSprite(NULL), ShadowWidth(0), ShadowHeight(0)
{
File.Width = 0;
File.Height = 0;
ShadowFile.Width = 0;

View file

@ -188,7 +188,8 @@ extern void CleanFonts();
class CLabel
{
public:
CLabel(const CFont &f, const std::string &nc, const std::string &rc): font(&f) {
CLabel(const CFont &f, const std::string &nc, const std::string &rc): font(&f)
{
normal = CFontColor::Get(nc);
reverse = CFontColor::Get(rc);
}

View file

@ -80,7 +80,8 @@ class FileList
public:
FileList() : type(0) {}
bool operator < (const FileList &rhs) const {
bool operator < (const FileList &rhs) const
{
if (type != rhs.type) {
return type < rhs.type;
}

View file

@ -119,11 +119,13 @@ class CUnitType;
class CMapInfo
{
public:
bool IsPointOnMap(int x, int y) const {
bool IsPointOnMap(int x, int y) const
{
return (x >= 0 && y >= 0 && x < MapWidth && y < MapHeight);
}
bool IsPointOnMap(const Vec2i &pos) const {
bool IsPointOnMap(const Vec2i &pos) const
{
return IsPointOnMap(pos.x, pos.y);
}
@ -150,21 +152,26 @@ public:
CMap();
~CMap();
unsigned int getIndex(int x, int y) const {
unsigned int getIndex(int x, int y) const
{
return x + y * this->Info.MapWidth;
}
unsigned int getIndex(const Vec2i &pos) const {
unsigned int getIndex(const Vec2i &pos) const
{
return getIndex(pos.x, pos.y);
}
CMapField *Field(unsigned int index) const {
CMapField *Field(unsigned int index) const
{
return &this->Fields[index];
}
/// Get the MapField at location x,y
CMapField *Field(int x, int y) const {
CMapField *Field(int x, int y) const
{
return &this->Fields[x + y * this->Info.MapWidth];
}
CMapField *Field(const Vec2i &pos) const {
CMapField *Field(const Vec2i &pos) const
{
return Field(pos.x, pos.y);
}
@ -227,7 +234,8 @@ public:
void Clamp(Vec2i &pos) const;
//Warning: we expect typical usage as xmin = x - range
void FixSelectionArea(Vec2i &minpos, Vec2i &maxpos) {
void FixSelectionArea(Vec2i &minpos, Vec2i &maxpos)
{
minpos.x = std::max<short>(0, minpos.x);
minpos.y = std::max<short>(0, minpos.y);

View file

@ -42,8 +42,7 @@
struct lua_State;
// Log data used in metaserver client
struct CClientLog
{
struct CClientLog {
std::string entry; // command itself
};
@ -61,13 +60,13 @@ public:
int Recv();
int GetLastRecvState() { return lastRecvState; }
int GetLogSize() { return events.size(); }
CClientLog* GetLastMessage() { return events.back(); }
CClientLog *GetLastMessage() { return events.back(); }
private:
CTCPSocket metaSocket; /// This is a TCP socket
std::string metaHost; /// Address of metaserver
int metaPort; /// Port of metaserver
std::list <CClientLog*> events; /// All commands received from metaserver
std::list <CClientLog *> events; /// All commands received from metaserver
int lastRecvState; /// Now many bytes have been received in last reply
};

View file

@ -432,7 +432,8 @@ public:
class CNetworkPacketHeader
{
public:
CNetworkPacketHeader() {
CNetworkPacketHeader()
{
Cycle = 0;
memset(Type, 0, sizeof(Type));
}

View file

@ -202,7 +202,8 @@ public:
/**
** Check if the player index is an enemy
*/
bool IsEnemy(const int index) const {
bool IsEnemy(const int index) const
{
return (Index != index && (Enemy & (1 << index)) != 0);
}
@ -244,7 +245,8 @@ private:
class PlayerRace
{
public:
PlayerRace() : Count(0) {
PlayerRace() : Count(0)
{
memset(Visible, 0, sizeof(Visible));
}

View file

@ -97,7 +97,8 @@ public:
class CSound
{
public:
CSound() : Mapref(0), Range(0), Number(0) {
CSound() : Mapref(0), Range(0), Number(0)
{
memset(&Sound, 0, sizeof(Sound));
}
~CSound();

View file

@ -137,7 +137,8 @@ class ConditionInfo
public:
ConditionInfo() : Alliance(0), Opponent(0), TargetSelf(0),
BoolFlag(NULL), Variable(NULL) {};
~ConditionInfo() {
~ConditionInfo()
{
delete[] BoolFlag;
delete[] Variable;
};
@ -224,7 +225,8 @@ public:
// Graphics and sounds. Add something else here?
SoundConfig SoundWhenCast; /// Sound played if cast
bool IsCasterOnly() const {
bool IsCasterOnly() const
{
return !Range && Target == TargetSelf;
}
bool ForceUseAnimation;

View file

@ -150,7 +150,8 @@ struct lua_State;
class CMapFieldPlayerInfo
{
public:
CMapFieldPlayerInfo() : SeenTile(0) {
CMapFieldPlayerInfo() : SeenTile(0)
{
memset(Visible, 0, sizeof(Visible));
memset(VisCloak, 0, sizeof(VisCloak));
memset(Radar, 0, sizeof(Radar));

View file

@ -86,7 +86,8 @@ public:
CTileInfo(unsigned char base, unsigned char mix) : BaseTerrain(base), MixTerrain(mix)
{}
bool operator ==(const CTileInfo &rhs) const {
bool operator ==(const CTileInfo &rhs) const
{
return BaseTerrain == rhs.BaseTerrain && MixTerrain == rhs.MixTerrain;
}
bool operator !=(const CTileInfo &rhs) const { return !(*this == rhs); }

View file

@ -56,7 +56,8 @@ class TitleScreen
{
public:
TitleScreen() : StretchImage(true), Timeout(0), Iterations(0), Editor(0), Labels(NULL) {}
~TitleScreen() {
~TitleScreen()
{
if (this->Labels) {
for (int i = 0; this->Labels[i]; ++i) {
delete this->Labels[i];

View file

@ -50,7 +50,8 @@ public:
CTimer() : Init(false), Running(false), Increasing(false), Cycles(0),
LastUpdate(0) {}
void Reset() {
void Reset()
{
Init = false;
Running = false;
Increasing = false;

View file

@ -182,7 +182,8 @@ public:
ConditionPanel() : ShowOnlySelected(false), HideNeutral(false),
HideAllied(false), ShowOpponent(false), BoolFlags(NULL),
Variables(NULL) {}
~ConditionPanel() {
~ConditionPanel()
{
delete[] BoolFlags;
delete[] Variables;
}
@ -227,7 +228,8 @@ class CFiller
void Init(CGraphic *g);
bool TransparentPixel(int x, int y) {
bool TransparentPixel(int x, int y)
{
if (bstore) {
const unsigned int x_index = x / 32;
y *= Width;
@ -249,7 +251,8 @@ public:
void Load();
bool OnGraphic(int x, int y) {
bool OnGraphic(int x, int y)
{
x -= X;
y -= Y;
if (x >= 0 && y >= 0 && x < map.Width && y < map.Height) {
@ -304,7 +307,8 @@ public:
class CPieMenu
{
public:
CPieMenu() : G(NULL), MouseButton(NoButton) {
CPieMenu() : G(NULL), MouseButton(NoButton)
{
memset(this->X, 0, sizeof(this->X));
memset(this->Y, 0, sizeof(this->Y));
}
@ -314,7 +318,8 @@ public:
int X[9]; /// X position of the pies
int Y[9]; /// Y position of the pies
void SetRadius(int radius) {
void SetRadius(int radius)
{
const int coeffX[] = { 0, 193, 256, 193, 0, -193, -256, -193, 0};
const int coeffY[] = { -256, -193, 0, 193, 256, 193, 0, -193, 0};
for (int i = 0; i < 9; ++i) {

View file

@ -67,7 +67,8 @@ class CContentTypeText : public CContentType
public:
CContentTypeText() : Text(NULL), Font(NULL), Centered(0), Index(-1),
Component(VariableValue), ShowName(0), Stat(0) {}
virtual ~CContentTypeText() {
virtual ~CContentTypeText()
{
FreeStringDesc(Text);
delete Text;
}

View file

@ -54,7 +54,8 @@ class PopupConditionPanel
public:
PopupConditionPanel() : HasHint(false), HasDescription(false), HasDependencies(false),
ButtonAction(-1), BoolFlags(NULL), Variables(NULL) {}
~PopupConditionPanel() {
~PopupConditionPanel()
{
delete[] BoolFlags;
delete[] Variables;
}
@ -187,7 +188,8 @@ class CPopupContentTypeVariable : public CPopupContentType
{
public:
CPopupContentTypeVariable() : Text(NULL), Font(NULL), Centered(0), Index(-1) {}
virtual ~CPopupContentTypeVariable() {
virtual ~CPopupContentTypeVariable()
{
FreeStringDesc(Text);
delete Text;
}

View file

@ -166,7 +166,8 @@ public:
bool CanStoreOrder(COrder *order);
// Cowards and invisible units don't attack unless ordered.
bool IsAgressive() const {
bool IsAgressive() const
{
return (Type->CanAttack && !Type->Coward
&& Variable[INVISIBLE_INDEX].Value == 0);
}
@ -174,7 +175,8 @@ public:
/// Returns true, if unit is directly seen by an allied unit.
bool IsVisible(const CPlayer &player) const;
inline bool IsInvisibile(const CPlayer &player) const {
inline bool IsInvisibile(const CPlayer &player) const
{
return (&player != Player && !!Variable[INVISIBLE_INDEX].Value
&& !player.IsBothSharedVision(*Player));
}
@ -193,7 +195,8 @@ public:
**
** @return True if alive, false otherwise.
*/
inline bool IsAliveOnMap() const {
inline bool IsAliveOnMap() const
{
return !Removed && IsAlive();
}
@ -204,7 +207,8 @@ public:
**
** @return True if visible, false otherwise.
*/
inline bool IsVisibleAsGoal(const CPlayer &player) const {
inline bool IsVisibleAsGoal(const CPlayer &player) const
{
// Invisibility
if (IsInvisibile(player)) {
return false;
@ -231,7 +235,8 @@ public:
**
** @return True if visible, false otherwise.
*/
inline bool IsVisibleOnMap(const CPlayer &player) const {
inline bool IsVisibleOnMap(const CPlayer &player) const
{
return IsAliveOnMap() && !IsInvisibile(player) && IsVisible(player);
}
@ -264,7 +269,8 @@ public:
**
** @return The distance between in tiles.
*/
int MapDistanceTo(const CUnit &dst) const {
int MapDistanceTo(const CUnit &dst) const
{
return MapDistanceBetweenTypes(*Type, tilePos, *dst.Type, dst.tilePos);
}
@ -372,8 +378,8 @@ public:
signed char IY; /// seen Y image displacement to map position
unsigned Constructed : 1; /// Unit seen construction
unsigned State : 3; /// Unit seen build/upgrade state
unsigned Destroyed : PlayerMax; /// Unit seen destroyed or not
unsigned ByPlayer : PlayerMax; /// Track unit seen by player
unsigned Destroyed : PlayerMax; /// Unit seen destroyed or not
unsigned ByPlayer : PlayerMax; /// Track unit seen by player
} Seen;
CVariable *Variable; /// array of User Defined variables.

View file

@ -65,11 +65,13 @@ public:
const_iterator end() const { return Units.end(); }
iterator end() { return Units.end(); }
CUnit *operator[](const unsigned int index) const {
CUnit *operator[](const unsigned int index) const
{
//Assert(index < Units.size());
return Units[index];
}
CUnit *operator[](const unsigned int index) {
CUnit *operator[](const unsigned int index)
{
//Assert(index < Units.size());
return Units[index];
}
@ -81,7 +83,8 @@ public:
* such that @p pred(u) is true, or NULL if no such unit exists.
*/
template<typename _T>
CUnit *find(const _T &pred) const {
CUnit *find(const _T &pred) const
{
std::vector<CUnit *>::const_iterator ret = std::find_if(Units.begin(), Units.end(), pred);
return ret != Units.end() ? (*ret) : NULL;
@ -96,7 +99,8 @@ public:
* @p functor must not modify the order of the cache.
*/
template<typename _T>
void for_each(const _T functor) {
void for_each(const _T functor)
{
const size_t size = Units.size();
for (size_t i = 0; i != size; ++i) {
@ -114,7 +118,8 @@ public:
* If @p functor return false then loop is exited.
*/
template<typename _T>
int for_each_if(const _T &functor) {
int for_each_if(const _T &functor)
{
const size_t size = Units.size();
for (size_t count = 0; count != size; ++count) {
@ -132,7 +137,8 @@ public:
** @param index Unit index to remove from container.
** @return pointer to removed element.
*/
CUnit *Remove(const unsigned int index) {
CUnit *Remove(const unsigned int index)
{
const size_t size = Units.size();
Assert(index < size);
CUnit *tmp = Units[index];
@ -148,7 +154,8 @@ public:
**
** @param unit Unit pointer to remove from container.
*/
bool Remove(CUnit *const unit) {
bool Remove(CUnit *const unit)
{
#ifndef SECURE_UNIT_REMOVING
const size_t size = Units.size();
if (size == 1 && unit == Units[0]) {
@ -180,7 +187,8 @@ public:
**
** @param unit Unit pointer to remove from container.
*/
void RemoveS(CUnit *const unit) {
void RemoveS(CUnit *const unit)
{
for (std::vector<CUnit *>::iterator i(Units.begin()), end(Units.end()); i != end; ++i) {
if ((*i) == unit) {
Units.erase(i);
@ -196,7 +204,8 @@ public:
** @param unit Unit pointer to place in cache.
** @return false if unit is already in cache and nothing is added.
*/
bool InsertS(CUnit *unit) {
bool InsertS(CUnit *unit)
{
if (!binary_search(Units.begin(), Units.end(), unit)) {
Units.insert(std::lower_bound(Units.begin(), Units.end(), unit), unit);
return true;
@ -209,7 +218,8 @@ public:
**
** @param unit Unit pointer to place in cache.
*/
void Insert(CUnit *unit) {
void Insert(CUnit *unit)
{
Units.push_back(unit);
}

View file

@ -100,7 +100,8 @@ public:
player(&_player), type(&_type)
{}
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return (unit->Player == player && unit->Type == type);
}
@ -158,7 +159,8 @@ class CUnitTypeFinder
{
public:
explicit CUnitTypeFinder(const UnitTypeType t) : unitTypeType(t) {}
bool operator()(const CUnit *const unit) const {
bool operator()(const CUnit *const unit) const
{
const CUnitType &type = *unit->Type;
if (type.Vanishes || (unitTypeType != static_cast<UnitTypeType>(-1) && type.UnitType != unitTypeType)) {
return false;

View file

@ -119,7 +119,8 @@ class CVariable
public:
CVariable() : Max(0), Value(0), Increase(0), Enable(0) {}
bool operator ==(const CVariable &rhs) const {
bool operator ==(const CVariable &rhs) const
{
return this->Max == rhs.Max
&& this->Value == rhs.Value
&& this->Increase == rhs.Increase
@ -226,7 +227,8 @@ class CDecoVar
public:
CDecoVar() {};
virtual ~CDecoVar() {
virtual ~CDecoVar()
{
};
/// function to draw the decorations.
@ -335,14 +337,16 @@ public:
class CBuildRestrictionAnd : public CBuildRestriction
{
public:
virtual ~CBuildRestrictionAnd() {
virtual ~CBuildRestrictionAnd()
{
for (std::vector<CBuildRestriction *>::const_iterator i = _or_list.begin();
i != _or_list.end(); ++i) {
delete *i;
}
_or_list.clear();
}
virtual void Init() {
virtual void Init()
{
for (std::vector<CBuildRestriction *>::const_iterator i = _or_list.begin();
i != _or_list.end(); ++i) {
(*i)->Init();
@ -619,7 +623,8 @@ public:
struct DataKey {
static bool key_pred(const DataKey &lhs,
const DataKey &rhs) {
const DataKey &rhs)
{
return ((lhs.keylen == rhs.keylen) ?
(strcmp(lhs.key, rhs.key) < 0) : (lhs.keylen < rhs.keylen));
}
@ -634,11 +639,13 @@ public:
std::map<std::string, int> user;
unsigned int TotalKeys;
void Init() {
void Init()
{
std::sort(buildin, buildin + SIZE, DataKey::key_pred);
}
const char *operator[](int index) {
const char *operator[](int index)
{
for (unsigned int i = 0; i < SIZE; ++i) {
if (buildin[i].offset == index) {
return buildin[i].key;
@ -661,7 +668,8 @@ public:
**
** @return Index of the variable, -1 if not found.
*/
int operator[](const char *const key) {
int operator[](const char *const key)
{
DataKey k;
k.key = key;
k.keylen = strlen(key);
@ -680,7 +688,8 @@ public:
return -1;
}
int AddKey(const char *const key) {
int AddKey(const char *const key)
{
int index = this->operator[](key);
if (index != -1) {
DebugPrint("Warning, Key '%s' already defined\n" _C_ key);
@ -712,11 +721,13 @@ public:
std::vector<CVariable> Variable; /// Array of user defined variables (default value for unittype).
std::vector<CDecoVar *> DecoVar; /// Array to describe how showing variable.
unsigned int GetNumberBoolFlag() const {
unsigned int GetNumberBoolFlag() const
{
return BoolFlagNameLookup.TotalKeys;
}
unsigned int GetNumberVariable() const {
unsigned int GetNumberVariable() const
{
return VariableNameLookup.TotalKeys;
}
};

View file

@ -129,7 +129,8 @@ extern int GetResourceIdByName(lua_State *l, const char *resourceName);
class CUnitStats
{
public:
CUnitStats() : Variables(NULL) {
CUnitStats() : Variables(NULL)
{
memset(Costs, 0, sizeof(Costs));
memset(Storing, 0, sizeof(Storing));
}
@ -179,12 +180,14 @@ public:
class CUpgradeModifier
{
public:
CUpgradeModifier() : UpgradeId(0), ModifyPercent(NULL), ConvertTo(NULL) {
CUpgradeModifier() : UpgradeId(0), ModifyPercent(NULL), ConvertTo(NULL)
{
memset(ChangeUnits, 0, sizeof(ChangeUnits));
memset(ChangeUpgrades, 0, sizeof(ChangeUpgrades));
memset(ApplyTo, 0, sizeof(ApplyTo));
}
~CUpgradeModifier() {
~CUpgradeModifier()
{
delete [] this->ModifyPercent;
}
@ -222,7 +225,8 @@ class CAllow
public:
CAllow() { this->Clear(); }
void Clear() {
void Clear()
{
memset(Units, 0, sizeof(Units));
memset(Upgrades, 0, sizeof(Upgrades));
}
@ -240,7 +244,8 @@ class CUpgradeTimers
public:
CUpgradeTimers() { this->Clear(); }
void Clear() {
void Clear()
{
memset(Upgrades, 0, sizeof(Upgrades));
}

View file

@ -154,7 +154,8 @@ public:
class CPlayerColorGraphic : public CGraphic
{
protected:
CPlayerColorGraphic() {
CPlayerColorGraphic()
{
#if defined(USE_OPENGL) || defined(USE_GLES)
memset(PlayerColorTextures, 0, sizeof(PlayerColorTextures));
#endif
@ -298,7 +299,8 @@ public:
void FillCircleClip(Uint32 color, const PixelPos &screenPos, int radius);
void FillTransCircleClip(Uint32 color, int x, int y, int radius, unsigned char alpha);
inline Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b) {
inline Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b)
{
#if defined(USE_OPENGL) || defined(USE_GLES)
if (UseOpenGL) {
return MapRGBA(f, r, g, b, 0xFF);
@ -308,10 +310,12 @@ public:
return SDL_MapRGB(f, r, g, b);
}
}
inline Uint32 MapRGB(SDL_PixelFormat *f, const CColor &color) {
inline Uint32 MapRGB(SDL_PixelFormat *f, const CColor &color)
{
return MapRGB(f, color.R, color.G, color.B);
}
inline Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
inline Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
#if defined(USE_OPENGL) || defined(USE_GLES)
if (UseOpenGL) {
return ((r << RSHIFT) | (g << GSHIFT) | (b << BSHIFT) | (a << ASHIFT));
@ -321,10 +325,12 @@ public:
return SDL_MapRGBA(f, r, g, b, a);
}
}
inline Uint32 MapRGBA(SDL_PixelFormat *f, const CColor &color) {
inline Uint32 MapRGBA(SDL_PixelFormat *f, const CColor &color)
{
return MapRGBA(f, color.R, color.G, color.B, color.A);
}
inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b) {
inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b)
{
#if defined(USE_OPENGL) || defined(USE_GLES)
if (UseOpenGL) {
*r = (c >> RSHIFT) & 0xff;
@ -336,7 +342,8 @@ public:
SDL_GetRGB(c, f, r, g, b);
}
}
inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) {
inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
{
#if defined(USE_OPENGL) || defined(USE_GLES)
if (UseOpenGL) {
*r = (c >> RSHIFT) & 0xff;

View file

@ -84,7 +84,8 @@ public:
class ButtonWidget : public gcn::Button
{
public:
explicit ButtonWidget(const std::string &caption) : Button(caption) {
explicit ButtonWidget(const std::string &caption) : Button(caption)
{
this->setHotKey(GetHotKey(caption));
}
};

View file

@ -77,11 +77,13 @@ static CGraphic *AlphaFogG;
class _filter_flags
{
public:
_filter_flags(const CPlayer &p, int *fogmask) : player(&p), fogmask(fogmask) {
_filter_flags(const CPlayer &p, int *fogmask) : player(&p), fogmask(fogmask)
{
Assert(fogmask != NULL);
}
void operator()(const CUnit *const unit) const {
void operator()(const CUnit *const unit) const
{
if (!unit->IsVisibleAsGoal(*player)) {
*fogmask &= ~unit->Type->FieldFlags;
}
@ -124,7 +126,8 @@ public:
_TileSeen(const CPlayer &p , int c) : player(&p), cloak(c)
{}
void operator()(CUnit *const unit) const {
void operator()(CUnit *const unit) const
{
if (cloak != (int)unit->Type->PermanentCloak) {
return ;
}

View file

@ -46,12 +46,14 @@ struct LandMineTargetFinder {
int CanHitOwner;
LandMineTargetFinder(const CUnit *unit, int hit):
source(unit), CanHitOwner(hit) {}
inline bool operator()(const CUnit *const unit) const {
inline bool operator()(const CUnit *const unit) const
{
return (!(unit == source && !CanHitOwner)
&& unit->Type->UnitType != UnitTypeFly
&& unit->CurrentAction() != UnitActionDie);
}
inline CUnit *FindOnTile(const CMapField *const mf) const {
inline CUnit *FindOnTile(const CMapField *const mf) const
{
return mf->UnitCache.find(*this);
}
};

View file

@ -67,12 +67,12 @@ CMetaClient MetaClient;
** @param l Lua state.
** @warning Deprecated function, need to be removed soon
*/
int CclSetMetaServer(lua_State *l)
{
LuaCheckArgs(l, 2);
MetaClient.SetMetaServer(LuaToString(l, 1), LuaToNumber(l, 2));
return 0;
int CclSetMetaServer(lua_State *l)
{
LuaCheckArgs(l, 2);
MetaClient.SetMetaServer(LuaToString(l, 1), LuaToNumber(l, 2));
return 0;
}
/**
@ -89,7 +89,7 @@ void CMetaClient::SetMetaServer(const std::string host, const int port)
CMetaClient::~CMetaClient()
{
for (std::list<CClientLog*>::iterator it = events.begin(); it != events.end(); ++it) {
for (std::list<CClientLog *>::iterator it = events.begin(); it != events.end(); ++it) {
CClientLog *log = *it;
delete log;
}

View file

@ -60,7 +60,8 @@
** Connect state information of network systems active in current game.
*/
struct NetworkState {
void Clear() {
void Clear()
{
State = ccs_unused;
MsgCnt = 0;
LastFrame = 0;
@ -1078,12 +1079,12 @@ void CServer::Parse_Resync(const int h)
{
switch (networkStates[h].State) {
case ccs_mapinfo:
// a delayed ack - fall through..
// a delayed ack - fall through..
case ccs_async:
// client has recvd welcome and is waiting for info
networkStates[h].State = ccs_synced;
networkStates[h].MsgCnt = 0;
/* Fall through */
/* Fall through */
case ccs_synced: {
// this code path happens until client falls back to ICMWaiting
// (indicating Resync has completed)
@ -1109,11 +1110,11 @@ void CServer::Parse_Resync(const int h)
void CServer::Parse_Waiting(const int h)
{
switch (networkStates[h].State) {
// client has recvd welcome and is waiting for info
// client has recvd welcome and is waiting for info
case ccs_connecting:
networkStates[h].State = ccs_connected;
networkStates[h].MsgCnt = 0;
/* Fall through */
/* Fall through */
case ccs_connected: {
// this code path happens until client acknowledges the map
Send_Map(Hosts[h]);
@ -1133,7 +1134,7 @@ void CServer::Parse_Waiting(const int h)
networkStates[i].State = ccs_async;
}
}
/* Fall through */
/* Fall through */
case ccs_synced:
// the wanted state - do nothing.. until start...
networkStates[h].MsgCnt = 0;
@ -1167,11 +1168,11 @@ void CServer::Parse_Waiting(const int h)
void CServer::Parse_Map(const int h)
{
switch (networkStates[h].State) {
// client has recvd map info waiting for state info
// client has recvd map info waiting for state info
case ccs_connected:
networkStates[h].State = ccs_mapinfo;
networkStates[h].MsgCnt = 0;
/* Fall through */
/* Fall through */
case ccs_mapinfo: {
// this code path happens until client acknowledges the state info
// by falling back to ICMWaiting with prev. State synced
@ -1199,8 +1200,8 @@ void CServer::Parse_State(const int h, const CInitMessage_State &msg)
{
switch (networkStates[h].State) {
case ccs_mapinfo:
// User State Change right after connect - should not happen, but..
/* Fall through */
// User State Change right after connect - should not happen, but..
/* Fall through */
case ccs_synced:
// Default case: Client is in sync with us, but notes a local change
// networkStates[h].State = ccs_async;
@ -1216,7 +1217,7 @@ void CServer::Parse_State(const int h, const CInitMessage_State &msg)
networkStates[i].State = ccs_async;
}
}
/* Fall through */
/* Fall through */
case ccs_async: {
// this code path happens until client acknowledges the state change reply
// by sending ICMResync
@ -1246,7 +1247,7 @@ void CServer::Parse_GoodBye(const int h)
// We can enter here from _ANY_ state!
networkStates[h].MsgCnt = 0;
networkStates[h].State = ccs_detaching;
/* Fall through */
/* Fall through */
case ccs_detaching: {
// this code path happens until client acknoledges the GoodBye
// by sending ICMSeeYou;

View file

@ -74,7 +74,8 @@ public:
bool Open(const CHost &host) { socket = NetOpenUDP(host.getIp(), host.getPort()); return socket != INVALID_SOCKET; }
void Close() { NetCloseUDP(socket); socket = Socket(-1); }
void Send(const CHost &host, const void *buf, unsigned int len) { NetSendUDP(socket, host.getIp(), host.getPort(), buf, len); }
int Recv(void *buf, int len, CHost *hostFrom) {
int Recv(void *buf, int len, CHost *hostFrom)
{
unsigned long ip;
int port;
int res = NetRecvUDP(socket, buf, len, &ip, &port);
@ -187,7 +188,8 @@ public:
void Close() { NetCloseTCP(socket); socket = Socket(-1); }
bool Connect(const CHost &host) { return NetConnectTCP(socket, host.getIp(), host.getPort()) != -1; }
int Send(const void *buf, unsigned int len) { return NetSendTCP(socket, buf, len); }
int Recv(void *buf, int len) {
int Recv(void *buf, int len)
{
int res = NetRecvTCP(socket, buf, len);
return res;
}
@ -204,7 +206,7 @@ bool CTCPSocket_Impl::Open(const CHost &host)
memset(&ip, 0, sizeof(ip));
sprintf(ip, "%d.%d.%d.%d", NIPQUAD(ntohl(host.getIp())));
this->socket = NetOpenTCP(ip, host.getPort());
return this->socket != INVALID_SOCKET;
return this->socket != INVALID_SOCKET;
}
//

View file

@ -258,7 +258,8 @@ public:
CNetworkCommandQueue() : Time(0), Type(0) {}
void Clear() { this->Time = this->Type = 0; Data.clear(); }
bool operator == (const CNetworkCommandQueue &rhs) const {
bool operator == (const CNetworkCommandQueue &rhs) const
{
return Time == rhs.Time && Type == rhs.Type && Data == rhs.Data;
}
bool operator != (const CNetworkCommandQueue &rhs) const { return !(*this == rhs); }
@ -309,7 +310,8 @@ public:
resentPacketCount(0)
{}
void print() const {
void print() const
{
DebugPrint("resent: %d packets\n" _C_ resentPacketCount);
}

View file

@ -591,7 +591,8 @@ public:
unit(unit), goal_reachable(goal_reachable)
{}
void operator()(int offset) const {
void operator()(int offset) const
{
if (CostMoveTo(offset, unit) >= 0) {
AStarMatrix[offset].InGoal = 1;
*goal_reachable = true;
@ -610,22 +611,26 @@ class MinMaxRangeVisitor
public:
explicit MinMaxRangeVisitor(const T &func) : func(func), minrange(0), maxrange(0) {}
void SetGoal(Vec2i goalTopLeft, Vec2i goalBottomRight) {
void SetGoal(Vec2i goalTopLeft, Vec2i goalBottomRight)
{
this->goalTopLeft = goalTopLeft;
this->goalBottomRight = goalBottomRight;
}
void SetRange(int minrange, int maxrange) {
void SetRange(int minrange, int maxrange)
{
this->minrange = minrange;
this->maxrange = maxrange;
}
void SetUnitSize(const Vec2i &tileSize) {
void SetUnitSize(const Vec2i &tileSize)
{
this->unitExtraTileSize.x = tileSize.x - 1;
this->unitExtraTileSize.y = tileSize.y - 1;
}
void Visit() const {
void Visit() const
{
TopHemicycle();
TopHemicycleNoMinRange();
Center();
@ -634,12 +639,14 @@ public:
}
private:
int GetMaxOffsetX(int dy, int range) const {
int GetMaxOffsetX(int dy, int range) const
{
return isqrt(square(range + 1) - square(dy) - 1);
}
// Distance are computed between bottom of unit and top of goal
void TopHemicycle() const {
void TopHemicycle() const
{
const int miny = std::max(0, goalTopLeft.y - maxrange - unitExtraTileSize.y);
const int maxy = std::min(goalTopLeft.y - minrange - unitExtraTileSize.y, goalTopLeft.y - 1 - unitExtraTileSize.y);
for (int y = miny; y <= maxy; ++y) {
@ -655,7 +662,8 @@ private:
}
}
void HemiCycleRing(int y, int offsetminx, int offsetmaxx) const {
void HemiCycleRing(int y, int offsetminx, int offsetmaxx) const
{
const int minx = std::max(0, goalTopLeft.x - offsetmaxx - unitExtraTileSize.x);
const int maxx = std::min(Map.Info.MapWidth - 1 - unitExtraTileSize.x, goalBottomRight.x + offsetmaxx);
Vec2i mpos(minx, y);
@ -669,7 +677,8 @@ private:
}
}
void TopHemicycleNoMinRange() const {
void TopHemicycleNoMinRange() const
{
const int miny = std::max(0, goalTopLeft.y - (minrange - 1) - unitExtraTileSize.y);
const int maxy = goalTopLeft.y - 1 - unitExtraTileSize.y;
for (int y = miny; y <= maxy; ++y) {
@ -680,7 +689,8 @@ private:
}
}
void Center() const {
void Center() const
{
const int miny = std::max(0, goalTopLeft.y - unitExtraTileSize.y);
const int maxy = std::min<int>(Map.Info.MapHeight - 1 - unitExtraTileSize.y, goalBottomRight.y);
const int minx = std::max(0, goalTopLeft.x - maxrange - unitExtraTileSize.x);
@ -710,7 +720,8 @@ private:
}
}
void BottomHemicycleNoMinRange() const {
void BottomHemicycleNoMinRange() const
{
const int miny = goalBottomRight.y + 1;
const int maxy = std::min(Map.Info.MapHeight - 1 - unitExtraTileSize.y, goalBottomRight.y + (minrange - 1));
@ -722,7 +733,8 @@ private:
}
}
void BottomHemicycle() const {
void BottomHemicycle() const
{
const int miny = std::max(goalBottomRight.y + minrange, goalBottomRight.y + 1);
const int maxy = std::min(Map.Info.MapHeight - 1 - unitExtraTileSize.y, goalBottomRight.y + maxrange);
for (int y = miny; y <= maxy; ++y) {

View file

@ -77,7 +77,8 @@
class IsDyingAndNotABuilding
{
public:
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return unit->CurrentAction() == UnitActionDie && !unit->Type->Building;
}
};

View file

@ -205,7 +205,8 @@ class AutoCastPrioritySort
public:
explicit AutoCastPrioritySort(const CUnit &caster, const int var, const bool reverse) :
caster(caster), variable(var), reverse(reverse) {}
bool operator()(const CUnit *lhs, const CUnit *rhs) const {
bool operator()(const CUnit *lhs, const CUnit *rhs) const
{
if (variable == ACP_DISTANCE) {
if (reverse) {
return lhs->MapDistanceTo(caster) > rhs->MapDistanceTo(caster);
@ -282,12 +283,12 @@ static Target *SelectTargetUnitsOfAutoCast(CUnit &caster, const SpellType &spell
return NULL;
case TargetPosition:
return 0;
// Autocast with a position? That's hard
// Possibilities: cast reveal-map on a dark region
// Cast raise dead on a bunch of corpses. That would rule.
// Cast summon until out of mana in the heat of battle. Trivial?
// Find a tight group of units and cast area-damage spells. HARD,
// but it is a must-have for AI. What about area-heal?
// Autocast with a position? That's hard
// Possibilities: cast reveal-map on a dark region
// Cast raise dead on a bunch of corpses. That would rule.
// Cast summon until out of mana in the heat of battle. Trivial?
// Find a tight group of units and cast area-damage spells. HARD,
// but it is a must-have for AI. What about area-heal?
case TargetUnit: {
// The units are already selected.
// Check every unit if it is a possible target
@ -298,8 +299,8 @@ static Target *SelectTargetUnitsOfAutoCast(CUnit &caster, const SpellType &spell
if (autocast->Attacker == CONDITION_ONLY) {
const int range = table[i]->Player->Type == PlayerPerson ? table[i]->Type->ReactRangePerson : table[i]->Type->ReactRangeComputer;
if ((table[i]->CurrentAction() != UnitActionAttack
&& table[i]->CurrentAction() != UnitActionAttackGround
&& table[i]->CurrentAction() != UnitActionSpellCast)
&& table[i]->CurrentAction() != UnitActionAttackGround
&& table[i]->CurrentAction() != UnitActionSpellCast)
|| table[i]->CurrentOrder()->HasGoal() == false
|| table[i]->MapDistanceTo(table[i]->CurrentOrder()->GetGoalPos()) > range) {
continue;

View file

@ -67,9 +67,9 @@ public:
}
bool isTainted() const { return tainted; }
const std::vector<CUnit *>& getUnits() const { return units; }
const std::vector<CUnit *> &getUnits() const { return units; }
void add(CUnit& unit, unsigned int num)
void add(CUnit &unit, unsigned int num)
{
if (ThisPlayer->IsTeamed(unit)) {
if (!tainted) {
@ -80,7 +80,7 @@ public:
}
}
void remove(CUnit& unit)
void remove(CUnit &unit)
{
std::vector<CUnit *>::iterator it = find(units.begin(), units.end(), &unit);
@ -175,7 +175,7 @@ void ClearGroup(int num)
CUnitGroup &group = Groups[num];
for (size_t i = 0; i != group.getUnits().size(); ++i) {
CUnit& unit = *group.getUnits()[i];
CUnit &unit = *group.getUnits()[i];
unit.GroupId &= ~(1 << num);
Assert(!unit.Destroyed);
}

View file

@ -506,7 +506,7 @@ long CFile::PImpl::tell()
**
** @return true if the file has been found.
*/
static bool FindFileWithExtension(char (&file)[PATH_MAX])
static bool FindFileWithExtension(char(&file)[PATH_MAX])
{
if (!access(file, R_OK)) {
return true;
@ -540,7 +540,7 @@ static bool FindFileWithExtension(char (&file)[PATH_MAX])
** @param file Filename to open.
** @param buffer Allocated buffer for generated filename.
*/
static void LibraryFileName(const char *file, char (&buffer)[PATH_MAX])
static void LibraryFileName(const char *file, char(&buffer)[PATH_MAX])
{
// Absolute path or in current directory.
strcpy_s(buffer, PATH_MAX, file);
@ -726,7 +726,8 @@ class RawFileWriter : public FileWriter
FILE *file;
public:
RawFileWriter(const std::string &filename) {
RawFileWriter(const std::string &filename)
{
file = fopen(filename.c_str(), "wb");
if (!file) {
fprintf(stderr, "Can't open file '%s' for writing\n", filename.c_str());
@ -734,11 +735,13 @@ public:
}
}
virtual ~RawFileWriter() {
virtual ~RawFileWriter()
{
if (file) { fclose(file); }
}
virtual int write(const char *data, unsigned int size) {
virtual int write(const char *data, unsigned int size)
{
return fwrite(data, size, 1, file);
}
};
@ -748,7 +751,8 @@ class GzFileWriter : public FileWriter
gzFile file;
public:
GzFileWriter(const std::string &filename) {
GzFileWriter(const std::string &filename)
{
file = gzopen(filename.c_str(), "wb9");
if (!file) {
fprintf(stderr, "Can't open file '%s' for writing\n", filename.c_str());
@ -756,11 +760,13 @@ public:
}
}
virtual ~GzFileWriter() {
virtual ~GzFileWriter()
{
if (file) { gzclose(file); }
}
virtual int write(const char *data, unsigned int size) {
virtual int write(const char *data, unsigned int size)
{
return gzwrite(file, data, size);
}
};

View file

@ -245,7 +245,7 @@ static void GameLogicLoop()
MissileActions(); // handle missiles
PlayersEachCycle(); // handle players
UpdateTimer(); // update game timer
//
// Work todo each second.

View file

@ -1129,7 +1129,7 @@ void FreeNumberDesc(NumberDesc *number)
}
switch (number->e) {
case ENumber_Lua : // a lua function.
// FIXME: when lua table should be freed ?
// FIXME: when lua table should be freed ?
case ENumber_Dir : // directly a number.
break;
case ENumber_Add : // a + b.

View file

@ -494,7 +494,7 @@ int SelectGroup(int group_number, GroupSelectionMode mode)
return 0;
}
if (mode == SELECT_ALL || !IsGroupTainted(group_number)) {
ChangeSelectedUnits(const_cast<CUnit**>(&units[0]), units.size());
ChangeSelectedUnits(const_cast<CUnit **>(&units[0]), units.size());
return Selected.size();
}
std::vector<CUnit *> table;

View file

@ -314,7 +314,7 @@ static int GetButtonStatus(const ButtonAction &button, int UnderCursor)
res |= IconAutoCast;
}
break;
// FIXME: must handle more actions
// FIXME: must handle more actions
default:
break;
}
@ -905,7 +905,7 @@ bool IsButtonAllowed(const CUnit &unit, const ButtonAction &buttonaction)
if (!EnableTrainingQueue && unit.CurrentAction() == UnitActionTrain) {
break;
}
// FALL THROUGH
// FALL THROUGH
case ButtonUpgradeTo:
case ButtonResearch:
case ButtonBuild:

View file

@ -431,7 +431,7 @@ void UiFindIdleWorker()
}
CUnit *unit = ThisPlayer->FreeWorkers[0];
if (LastIdleWorker) {
const std::vector<CUnit *>& freeWorkers = ThisPlayer->FreeWorkers;
const std::vector<CUnit *> &freeWorkers = ThisPlayer->FreeWorkers;
std::vector<CUnit *>::const_iterator it = std::find(freeWorkers.begin(),
freeWorkers.end(),
LastIdleWorker);
@ -574,19 +574,19 @@ static bool CommandKey(int key)
}
switch (key) {
// Return enters chat/input mode.
// Return enters chat/input mode.
case SDLK_RETURN:
case SDLK_KP_ENTER: // RETURN
UiBeginInput();
return true;
// Unselect everything
// Unselect everything
case SDLK_CARET:
case SDLK_BACKQUOTE:
UiUnselectAll();
break;
// Group selection
// Group selection
case '0': case '1': case '2':
case '3': case '4': case '5':
case '6': case '7': case '8':
@ -647,7 +647,7 @@ static bool CommandKey(int key)
if (!(KeyModifiers & (ModifierAlt | ModifierControl))) {
break;
}
// FALL THROUGH
// FALL THROUGH
case SDLK_PERIOD: // ., ALT+I, CTRL+I: Find idle worker
UiFindIdleWorker();
break;
@ -664,7 +664,7 @@ static bool CommandKey(int key)
if (!(KeyModifiers & (ModifierAlt | ModifierControl))) {
break;
}
// FALL THROUGH (CTRL+P, ALT+P)
// FALL THROUGH (CTRL+P, ALT+P)
case SDLK_PAUSE:
UiTogglePause();
break;
@ -865,7 +865,7 @@ static int InputKey(int key)
NetworkSendChatMessage(chatMessage);
}
}
// FALL THROUGH
// FALL THROUGH
case SDLK_ESCAPE:
KeyState = KeyStateCommand;
UI.StatusLine.Clear();
@ -1355,13 +1355,13 @@ void InputMouseMove(const EventCallback &callbacks,
const int buff = 32;
const PixelDiff diff = LastMousePos - mousePos;
if (abs(diff.x) > buff || abs (diff.y) > buff) {
if (abs(diff.x) > buff || abs(diff.y) > buff) {
MouseState = InitialMouseState;
LastMouseTicks = ticks;
// Reset rectangle select cursor state if we moved by a lot
// - rectangle select should be a drag, not a tap
if (CursorState == CursorStateRectangle
&& (abs(diff.x) > 2 * buff || abs (diff.y) > 2 * buff)) {
&& (abs(diff.x) > 2 * buff || abs(diff.y) > 2 * buff)) {
CursorState = CursorStatePoint;
}
}

View file

@ -223,7 +223,7 @@ static bool CanShowContent(const ConditionPanel *condition, const CUnit &unit)
return true;
}
enum UStrIntType{
enum UStrIntType {
USTRINT_STR, USTRINT_INT
};
struct UStrInt {
@ -381,7 +381,7 @@ static void DrawUnitInfo_Training(const CUnit &unit)
}
}
static void DrawUnitInfo_portrait(const CUnitType& type)
static void DrawUnitInfo_portrait(const CUnitType &type)
{
#ifdef USE_MNG
if (type.Portrait.Num) {
@ -410,7 +410,7 @@ static void DrawUnitInfo_portrait(const CUnitType& type)
}
}
static bool DrawUnitInfo_single_selection(const CUnit& unit)
static bool DrawUnitInfo_single_selection(const CUnit &unit)
{
switch (unit.CurrentAction()) {
case UnitActionTrain: { // Building training units.
@ -591,7 +591,8 @@ static int MessagesEventIndex; /// FIXME: docu
class MessagesDisplay
{
public:
MessagesDisplay() : show(true) {
MessagesDisplay() : show(true)
{
#ifdef DEBUG
showBuilList = false;
#endif
@ -967,7 +968,7 @@ void CenterOnMessage()
if (MessagesEventCount == 0) {
return;
}
const Vec2i& pos(MessagesEventPos[MessagesEventIndex]);
const Vec2i &pos(MessagesEventPos[MessagesEventIndex]);
UI.SelectedViewport->Center(Map.TilePosToMapPixelPos_Center(pos));
SetMessage(_("~<Event: %s~>"), MessagesEvent[MessagesEventIndex]);
++MessagesEventIndex;
@ -1117,7 +1118,7 @@ static void InfoPanel_draw_no_selection()
static void InfoPanel_draw_single_selection()
{
CUnit& unit = *Selected[0];
CUnit &unit = *Selected[0];
int panelIndex;
// FIXME: not correct for enemy's units

View file

@ -205,18 +205,18 @@ static bool DoRightButton_Harvest_Unit(CUnit &unit, CUnit &dest, int flush, int
if (unit.ResourcesHeld > 0
&& dest.Type->CanStore[unit.CurrentResource]
&& (dest.Player == unit.Player
|| (dest.Player->IsAllied(*unit.Player) && unit.Player->IsAllied(*dest.Player)))) {
dest.Blink = 4;
if (!acknowledged) {
PlayUnitSound(unit, VoiceAcknowledging);
acknowledged = 1;
}
SendCommandReturnGoods(unit, &dest, flush);
return true;
|| (dest.Player->IsAllied(*unit.Player) && unit.Player->IsAllied(*dest.Player)))) {
dest.Blink = 4;
if (!acknowledged) {
PlayUnitSound(unit, VoiceAcknowledging);
acknowledged = 1;
}
SendCommandReturnGoods(unit, &dest, flush);
return true;
}
// Go and harvest from a unit
const int res = dest.Type->GivesResource;
const CUnitType& type = *unit.Type;
const CUnitType &type = *unit.Type;
if (res
&& type.ResInfo[res]
&& unit.ResourcesHeld < type.ResInfo[res]->ResourceCapacity
@ -238,7 +238,7 @@ static bool DoRightButton_Harvest_Pos(CUnit &unit, const Vec2i &pos, int flush,
if (!Map.Field(pos)->playerInfo.IsExplored(*unit.Player)) {
return false;
}
const CUnitType& type = *unit.Type;
const CUnitType &type = *unit.Type;
// FIXME: support harvesting more types of terrain.
for (int res = 0; res < MaxCosts; ++res) {
if (type.ResInfo[res]

View file

@ -1017,7 +1017,7 @@ static int CclDefineButton(lua_State *l)
ba.AllowStr = allowstr;
} else if (!strcmp(value, "Key")) {
std::string key(LuaToString(l, -1));
ba.Key = GetHotKey(key);
ba.Key = GetHotKey(key);
} else if (!strcmp(value, "Hint")) {
ba.Hint = LuaToString(l, -1);
} else if (!strcmp(value, "Description")) {

View file

@ -87,7 +87,7 @@ void ShowLoadProgress(const char *fmt, ...)
if (Video.Depth && IsGameFontReady() && GetGameFont().IsLoaded()) {
// Remove non printable chars
for (unsigned char *s = (unsigned char*)temp; *s; ++s) {
for (unsigned char *s = (unsigned char *)temp; *s; ++s) {
if (*s < 32) {
*s = ' ';
}

View file

@ -217,7 +217,8 @@ class AliveConstructedAndSameTypeAs
{
public:
explicit AliveConstructedAndSameTypeAs(const CUnitType &unitType) : type(&unitType) {}
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return unit->IsAlive() && unit->Type == type && unit->CurrentAction() != UnitActionBuilt;
}
private:

View file

@ -759,7 +759,8 @@ class HasSameUnitTypeAs
{
public:
explicit HasSameUnitTypeAs(const CUnitType *_type) : type(_type) {}
bool operator()(const CUnit *unit) const {
bool operator()(const CUnit *unit) const
{
return (type == ANY_UNIT || type == unit->Type
|| (type == ALL_FOODUNITS && !unit->Type->Building)
|| (type == ALL_BUILDINGS && unit->Type->Building));
@ -1017,8 +1018,9 @@ static int CclSetUnitVariable(lua_State *l)
}
value = LuaToNumber(l, 3);
bool stats = false;
if (nargs == 5)
if (nargs == 5) {
stats = LuaToBoolean(l, 5);
}
if (stats) { // stat variables
const char *const type = LuaToString(l, 4);
if (!strcmp(type, "Value")) {

View file

@ -932,7 +932,8 @@ public:
_UnmarkUnitFieldFlags(const CUnit &unit, CMapField *mf) : main(&unit), mf(mf)
{}
void operator()(CUnit *const unit) const {
void operator()(CUnit *const unit) const
{
if (main != unit && unit->CurrentAction() != UnitActionDie) {
mf->Flags |= unit->Type->FieldFlags;
}

View file

@ -184,7 +184,8 @@ bool FindTerrainType(int movemask, int resmask, int range,
template <const bool NEARLOCATION>
class BestDepotFinder
{
inline void operator()(CUnit *const dest) {
inline void operator()(CUnit *const dest)
{
/* Only resource depots */
if (dest->Type->CanStore[resource]
&& dest->IsAliveOnMap()
@ -233,25 +234,29 @@ class BestDepotFinder
public:
BestDepotFinder(const CUnit &w, int res, int ran) :
resource(res), range(ran),
best_dist(INT_MAX), best_depot(0) {
best_dist(INT_MAX), best_depot(0)
{
u_near.worker = &w;
}
BestDepotFinder(const Vec2i &pos, int res, int ran) :
resource(res), range(ran),
best_dist(INT_MAX), best_depot(0) {
best_dist(INT_MAX), best_depot(0)
{
u_near.loc = pos;
}
template <typename ITERATOR>
CUnit *Find(ITERATOR begin, ITERATOR end) {
CUnit *Find(ITERATOR begin, ITERATOR end)
{
for (ITERATOR it = begin; it != end; ++it) {
this->operator()(*it);
}
return best_depot;
}
CUnit *Find(CUnitCache &cache) {
CUnit *Find(CUnitCache &cache)
{
cache.for_each(*this);
return best_depot;
}
@ -288,7 +293,8 @@ class CResourceFinder
{
public:
CResourceFinder(int r, bool on_top) : resource(r), mine_on_top(on_top) {}
bool operator()(const CUnit *const unit) const {
bool operator()(const CUnit *const unit) const
{
const CUnitType &type = *unit->Type;
return (type.GivesResource == resource
&& unit->ResourcesHeld != 0
@ -312,7 +318,8 @@ public:
maxRange(maxRange),
check_usage(check_usage),
res_finder(resource, 1),
resultMine(resultMine) {
resultMine(resultMine)
{
bestCost.SetToMax();
*resultMine = NULL;
}
@ -323,7 +330,8 @@ private:
struct ResourceUnitFinder_Cost {
public:
void SetFrom(const CUnit &mine, const CUnit *deposit, bool check_usage);
bool operator < (const ResourceUnitFinder_Cost &rhs) const {
bool operator < (const ResourceUnitFinder_Cost &rhs) const
{
if (waiting != rhs.waiting) {
return waiting < rhs.waiting;
} else if (distance != rhs.distance) {
@ -636,7 +644,8 @@ class IsADepositForResource
{
public:
explicit IsADepositForResource(const int r) : resource(r) {}
bool operator()(const CUnit *const unit) const {
bool operator()(const CUnit *const unit) const
{
return (unit->Type->CanStore[resource] && !unit->IsUnusable());
}
private:
@ -667,17 +676,20 @@ public:
attacker(&a)
{}
CUnit *Find(const std::vector<CUnit *> &table) const {
CUnit *Find(const std::vector<CUnit *> &table) const
{
return Find(table.begin(), table.end());
}
CUnit *Find(CUnitCache &cache) const {
CUnit *Find(CUnitCache &cache) const
{
return Find(cache.begin(), cache.end());
}
private:
template <typename Iterator>
CUnit *Find(Iterator begin, Iterator end) const {
CUnit *Find(Iterator begin, Iterator end) const
{
CUnit *enemy = NULL;
int best_cost = INT_MAX;
@ -692,7 +704,8 @@ private:
return enemy;
}
int ComputeCost(CUnit *const dest) const {
int ComputeCost(CUnit *const dest) const
{
const CPlayer &player = *attacker->Player;
const CUnitType &type = *attacker->Type;
const CUnitType &dtype = *dest->Type;
@ -779,7 +792,8 @@ public:
**
*/
BestRangeTargetFinder(const CUnit &a, const int r) : attacker(&a), range(r),
best_unit(0), best_cost(INT_MIN) {
best_unit(0), best_cost(INT_MIN)
{
memset(good, 0 , sizeof(int) * 32 * 32);
memset(bad, 0 , sizeof(int) * 32 * 32);
};
@ -789,15 +803,18 @@ public:
public:
FillBadGood(const CUnit &a, int r, int *g, int *b):
attacker(&a), range(r),
enemy_count(0), good(g), bad(b) {
enemy_count(0), good(g), bad(b)
{
}
int Fill(CUnitCache &cache) {
int Fill(CUnitCache &cache)
{
return Fill(cache.begin(), cache.end());
}
template <typename Iterator>
int Fill(Iterator begin, Iterator end) {
int Fill(Iterator begin, Iterator end)
{
for (Iterator it = begin; it != end; ++it) {
Compute(*it);
}
@ -805,7 +822,8 @@ public:
}
private:
void Compute(CUnit *const dest) {
void Compute(CUnit *const dest)
{
const CPlayer &player = *attacker->Player;
if (!dest->IsVisibleAsGoal(player)) {
@ -835,7 +853,7 @@ public:
hp_damage_evaluate = CalculateDamage(*attacker, *dest, Damage);
} else {
hp_damage_evaluate = attacker->Stats->Variables[BASICDAMAGE_INDEX].Value
+ attacker->Stats->Variables[PIERCINGDAMAGE_INDEX].Value;
+ attacker->Stats->Variables[PIERCINGDAMAGE_INDEX].Value;
}
if (!player.IsEnemy(*dest)) { // a friend or neutral
dest->CacheLock = 1;
@ -942,27 +960,31 @@ public:
int *bad;
};
CUnit *Find(std::vector<CUnit *> &table) {
CUnit *Find(std::vector<CUnit *> &table)
{
FillBadGood(*attacker, range, good, bad).Fill(table.begin(), table.end());
return Find(table.begin(), table.end());
}
CUnit *Find(CUnitCache &cache) {
CUnit *Find(CUnitCache &cache)
{
FillBadGood(*attacker, range, good, bad).Fill(cache);
return Find(cache.begin(), cache.end());
}
private:
template <typename Iterator>
CUnit *Find(Iterator begin, Iterator end) {
CUnit *Find(Iterator begin, Iterator end)
{
for (Iterator it = begin; it != end; ++it) {
Compute(*it);
}
return best_unit;
}
void Compute(CUnit *const dest) {
void Compute(CUnit *const dest)
{
if (dest->CacheLock) {
dest->CacheLock = 0;
return;
@ -1026,7 +1048,8 @@ private:
struct CompareUnitDistance {
const CUnit *referenceunit;
CompareUnitDistance(const CUnit &unit): referenceunit(&unit) {}
bool operator()(const CUnit *c1, const CUnit *c2) {
bool operator()(const CUnit *c1, const CUnit *c2)
{
int d1 = c1->MapDistanceTo(*referenceunit);
int d2 = c2->MapDistanceTo(*referenceunit);
if (d1 == d2) {

View file

@ -395,10 +395,10 @@ int GetHotKey(const std::string &text)
if (text.length() > 1) {
hotkey = convertKey(text.c_str());
} else if (text.length() == 1){
} else if (text.length() == 1) {
GetUTF8(text, pos, hotkey);
}
return hotkey;
}

View file

@ -621,7 +621,7 @@ void CGraphic::GenFramesMap()
}
}
static void ApplyGrayScale(SDL_Surface* Surface, int Width, int Height)
static void ApplyGrayScale(SDL_Surface *Surface, int Width, int Height)
{
SDL_LockSurface(Surface);
const SDL_PixelFormat *f = Surface->format;
@ -1293,14 +1293,14 @@ void CGraphic::Resize(int w, int h)
unsigned char *p1 = &pixels[iy * Surface->pitch + ix * bpp];
unsigned char *p2 = (iy != Surface->h - 1) ?
&pixels[(iy + 1) * Surface->pitch + ix * bpp] :
p1;
&pixels[(iy + 1) * Surface->pitch + ix * bpp] :
p1;
unsigned char *p3 = (ix != Surface->w - 1) ?
&pixels[iy * Surface->pitch + (ix + 1) * bpp] :
p1;
&pixels[iy * Surface->pitch + (ix + 1) * bpp] :
p1;
unsigned char *p4 = (iy != Surface->h - 1 && ix != Surface->w - 1) ?
&pixels[(iy + 1) * Surface->pitch + (ix + 1) * bpp] :
p1;
&pixels[(iy + 1) * Surface->pitch + (ix + 1) * bpp] :
p1;
data[x * bpp + 0] = static_cast<unsigned char>(
(p1[0] * (1 - fy) + p2[0] * fy +

View file

@ -184,15 +184,15 @@ static inline void DrawHLine(void *pixels, unsigned int index,
case 3:
PutPixel<BPP>(pixels, index, color);
index++;
//--width;
//--width;
case 2:
PutPixel<BPP>(pixels, index, color);
index++;
//--width;
//--width;
case 1:
PutPixel<BPP>(pixels, index, color);
index++;
//--width;
//--width;
default:
break;
}
@ -210,7 +210,8 @@ class CRenderer : public CPrimitives
{
static inline void PutTransPixel(void *pixels, unsigned int index,
Uint32 color, unsigned int alpha) {
Uint32 color, unsigned int alpha)
{
unsigned int dp;
if (BPP == 2) {
Uint16 *p = (((Uint16 *)pixels) + index);
@ -259,7 +260,8 @@ class CRenderer : public CPrimitives
} // __attribute__ ((nothrow,nonnull (1)));
static inline void PutTransPixelDouble(void *pixels, unsigned int index,
Uint32 color, unsigned int alpha) {
Uint32 color, unsigned int alpha)
{
if (BPP == 2) {
/*
@ -336,7 +338,8 @@ class CRenderer : public CPrimitives
} // __attribute__ ((nothrow,nonnull (1)));
static inline void PutTransPixel128(void *pixels, unsigned int index, Uint32 color) {
static inline void PutTransPixel128(void *pixels, unsigned int index, Uint32 color)
{
if (BPP == 2) {
/* blend a single 16 bit pixel at 50% */
#define BLEND16_50(d, s, mask) \
@ -362,7 +365,8 @@ class CRenderer : public CPrimitives
};
static inline void PutTransPixel128Double(void *pixels, const unsigned int index,
const Uint32 color) {
const Uint32 color)
{
if (BPP == 2) {
/* blend two 16 bit pixels at 50% */
#define BLEND2x16_50(d, s, mask) \
@ -404,7 +408,8 @@ class CRenderer : public CPrimitives
} // __attribute__ ((nothrow,nonnull (1)));
static void DrawVLine(void *pixels, const unsigned int pitch,
unsigned int index, int height, Uint32 color) {
unsigned int index, int height, Uint32 color)
{
if (height < 1) { return; }
do {
DRAW::PutPixel<BPP>(pixels, index, color);
@ -413,7 +418,8 @@ class CRenderer : public CPrimitives
} // __attribute__ ((nothrow,nonnull (1)));
static void DrawTransVLine(void *pixels, const unsigned int pitch,
unsigned int index, int height, Uint32 color, unsigned int alpha) {
unsigned int index, int height, Uint32 color, unsigned int alpha)
{
if (height < 1) { return; }
if (alpha == 128) {
do {
@ -429,7 +435,8 @@ class CRenderer : public CPrimitives
} // __attribute__ ((nothrow,nonnull (1)));
static inline void DrawTransHLine128(void *pixels,
unsigned int index, int width, Uint32 color) {
unsigned int index, int width, Uint32 color)
{
#ifdef __x86_64__
//FIXME: this may not work on 16 bpp
if (((uintptr_t)pixels) & BPP) {
@ -453,7 +460,8 @@ class CRenderer : public CPrimitives
static inline void DrawTransHLineNon128(void *pixels,
unsigned int index, int width, Uint32 color, unsigned int alpha) {
unsigned int index, int width, Uint32 color, unsigned int alpha)
{
#ifdef __x86_64__
if (((uintptr_t)pixels) & BPP) {
#else
@ -474,7 +482,8 @@ class CRenderer : public CPrimitives
} // __attribute__ ((nothrow,nonnull (1)));
static inline void DrawTransHLine(void *pixels,
unsigned int index, int width, Uint32 color, unsigned int alpha) {
unsigned int index, int width, Uint32 color, unsigned int alpha)
{
//if(width < 1) return;
if (alpha == 128) {
DrawTransHLine128(pixels, index, width, color);
@ -483,14 +492,16 @@ class CRenderer : public CPrimitives
}
};
void DrawPixel(Uint32 color, int x, int y) {
void DrawPixel(Uint32 color, int x, int y)
{
unsigned int index = TheScreen->pitch / BPP;
index *= y;
index += x;
DRAW::PutPixel<BPP>(TheScreen->pixels, index, color);
};
void DrawTransPixel(Uint32 color, int x, int y, unsigned char alpha) {
void DrawTransPixel(Uint32 color, int x, int y, unsigned char alpha)
{
unsigned int index = TheScreen->pitch / BPP;
index *= y;
index += x;
@ -501,7 +512,8 @@ class CRenderer : public CPrimitives
}
};
void DrawLine(Uint32 color, int sx, int sy, int dx, int dy) {
void DrawLine(Uint32 color, int sx, int sy, int dx, int dy)
{
unsigned int index;
const unsigned int pitch = TheScreen->pitch / BPP;
@ -617,12 +629,14 @@ class CRenderer : public CPrimitives
};
void DrawTransLine(Uint32 color, int sx, int sy,
int dx, int dy, unsigned char alpha) {
int dx, int dy, unsigned char alpha)
{
DrawLine(color, sx, sy, dx, dy);
}
void DrawRectangle(Uint32 color, int x, int y, int w, int h) {
void DrawRectangle(Uint32 color, int x, int y, int w, int h)
{
const unsigned int pitch = TheScreen->pitch / BPP;
unsigned int index = y * pitch;
unsigned int y_offset = (h - 1) * pitch;
@ -641,7 +655,8 @@ class CRenderer : public CPrimitives
};
void DrawTransRectangle(Uint32 color, int x, int y,
int w, int h, unsigned char alpha) {
int w, int h, unsigned char alpha)
{
const unsigned int pitch = TheScreen->pitch / BPP;
unsigned int index = y * pitch;
unsigned int y_offset = (h - 1) * pitch;
@ -664,7 +679,8 @@ class CRenderer : public CPrimitives
};
void FillTransRectangle(Uint32 color, int x, int y,
int w, int h, unsigned char alpha) {
int w, int h, unsigned char alpha)
{
const unsigned int pitch = TheScreen->pitch / BPP;
unsigned int index = y * pitch;
if (alpha == 128) {
@ -680,7 +696,8 @@ class CRenderer : public CPrimitives
}
};
void DrawCircle(Uint32 color, int x, int y, int r) {
void DrawCircle(Uint32 color, int x, int y, int r)
{
const unsigned int pitch = TheScreen->pitch / BPP;
int p = 1 - r;
int px = 0;
@ -713,7 +730,8 @@ class CRenderer : public CPrimitives
};
void DrawTransCircle(Uint32 color, int x, int y,
int r, unsigned char alpha) {
int r, unsigned char alpha)
{
const unsigned int pitch = TheScreen->pitch / BPP;
int p = 1 - r;
int px = 0;
@ -745,7 +763,8 @@ class CRenderer : public CPrimitives
}
};
void FillCircle(Uint32 color, int x, int y, int r) {
void FillCircle(Uint32 color, int x, int y, int r)
{
const unsigned int pitch = TheScreen->pitch / BPP;
int p = 1 - r;
int px = 0;
@ -799,7 +818,8 @@ class CRenderer : public CPrimitives
};
void FillTransCircle(Uint32 color, int x, int y,
int r, unsigned char alpha) {
int r, unsigned char alpha)
{
const unsigned int pitch = TheScreen->pitch / BPP;
int p = 1 - r;
int px = 0;

View file

@ -835,8 +835,8 @@ static void SdlDoEvent(const EventCallback &callbacks, SDL_Event &event)
InputMouseButtonRelease(callbacks, SDL_GetTicks(), event.button.button);
break;
// FIXME: check if this is only useful for the cursor
// FIXME: if this is the case we don't need this.
// FIXME: check if this is only useful for the cursor
// FIXME: if this is the case we don't need this.
case SDL_MOUSEMOTION:
InputMouseMove(callbacks, SDL_GetTicks(), event.motion.x, event.motion.y);
// FIXME: Same bug fix from X11

View file

@ -127,7 +127,8 @@ private:
CColorCycling() : ColorCycleAll(false), cycleCount(0)
{}
static void CreateInstanceIfNeeded() {
static void CreateInstanceIfNeeded()
{
if (s_instance == NULL) {
s_instance = new CColorCycling;
}