[AStyle] : on most cpp files.

This commit is contained in:
Joris 2012-04-18 16:09:57 +02:00
parent 4ec2ba35af
commit 720bc8c831
24 changed files with 156 additions and 133 deletions

View file

@ -390,8 +390,8 @@ void COrder_Attack::MoveToTarget(CUnit &unit)
return; return;
} }
// Attacking wall or ground. // Attacking wall or ground.
if (((goal && goal->Type && goal->Type->Wall) || ((!goal) if (((goal && goal->Type && goal->Type->Wall)
&& (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround))) || (!goal && (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround)))
&& unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) { && unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
// Reached wall or ground, now attacking it // Reached wall or ground, now attacking it
unit.State = 0; unit.State = 0;

View file

@ -876,9 +876,9 @@ static void AiMoveUnitInTheWay(CUnit &unit)
// Check for collision // Check for collision
if (!((u0.x == b1.x + 1 || u1.x == b0.x - 1) if (!((u0.x == b1.x + 1 || u1.x == b0.x - 1)
&& (std::max<int>(b0.y, u0.y) <= std::min<int>(b1.y, u1.y))) && (std::max<int>(b0.y, u0.y) <= std::min<int>(b1.y, u1.y)))
&& !((u0.y == b1.y + 1 || u1.y == b0.y - 1) && !((u0.y == b1.y + 1 || u1.y == b0.y - 1)
&& (std::max<int>(b0.x, u0.x) <= std::min<int>(b1.x, u1.x)))) { && (std::max<int>(b0.x, u0.x) <= std::min<int>(b1.x, u1.x)))) {
continue; continue;
} }

View file

@ -95,8 +95,8 @@ static int AiCheckSurrounding(const CUnit &worker,
if (x == worker.tilePos.x && y == worker.tilePos.y) { if (x == worker.tilePos.x && y == worker.tilePos.y) {
surrounding[surroundingnb++] = 1; surrounding[surroundingnb++] = 1;
} else if (Map.CheckMask(x + y_offset, } else if (Map.CheckMask(x + y_offset,
(MapFieldUnpassable | MapFieldWall | MapFieldRocks (MapFieldUnpassable | MapFieldWall | MapFieldRocks
| MapFieldForest | MapFieldBuilding))) { | MapFieldForest | MapFieldBuilding))) {
surrounding[surroundingnb++] = 0; surrounding[surroundingnb++] = 0;
} else { } else {
// Can pass there // Can pass there

View file

@ -397,7 +397,7 @@ static int CclDefineAiHelper(lua_State *l)
return 0; return 0;
} }
static CAiType *GetAiTypesByName(const char* name) static CAiType *GetAiTypesByName(const char *name)
{ {
for (size_t i = 0; i < AiTypes.size(); ++i) { for (size_t i = 0; i < AiTypes.size(); ++i) {
CAiType *ait = AiTypes[i]; CAiType *ait = AiTypes[i];
@ -425,7 +425,7 @@ static int CclDefineAi(lua_State *l)
CAiType *aitype = new CAiType; CAiType *aitype = new CAiType;
// AI Name // AI Name
const char* aiName = LuaToString(l, 1); const char *aiName = LuaToString(l, 1);
aitype->Name = aiName; aitype->Name = aiName;
#ifdef DEBUG #ifdef DEBUG
@ -1273,7 +1273,7 @@ static int CclDefineAiPlayer(lua_State *l)
++j; ++j;
if (!strcmp(value, "ai-type")) { if (!strcmp(value, "ai-type")) {
const char* aiName = LuaToString(l, j + 1); const char *aiName = LuaToString(l, j + 1);
CAiType *ait = GetAiTypesByName(aiName); CAiType *ait = GetAiTypesByName(aiName);
if (ait == NULL) { if (ait == NULL) {
lua_pushfstring(l, "ai-type not found: %s", aiName); lua_pushfstring(l, "ai-type not found: %s", aiName);
@ -1299,7 +1299,7 @@ static int CclDefineAiPlayer(lua_State *l)
for (int k = 1; k < subargs; ++k) { for (int k = 1; k < subargs; ++k) {
lua_rawgeti(l, j + 1, k + 1); lua_rawgeti(l, j + 1, k + 1);
const char* value = LuaToString(l, -1); const char *value = LuaToString(l, -1);
lua_pop(l, 1); lua_pop(l, 1);
++k; ++k;
if (!strcmp(value, "complete")) { if (!strcmp(value, "complete")) {

View file

@ -99,7 +99,7 @@ static int ParseAnimFlags(CUnit &unit, const char *parseflag)
const int destx = ParseAnimInt(&unit, this->destXStr.c_str()); const int destx = ParseAnimInt(&unit, this->destXStr.c_str());
const int desty = ParseAnimInt(&unit, this->destYStr.c_str()); const int desty = ParseAnimInt(&unit, this->destYStr.c_str());
const int flags = ParseAnimFlags(unit, this->flagsStr.c_str()); const int flags = ParseAnimFlags(unit, this->flagsStr.c_str());
const CUnit *goal = flags & ANIM_SM_RELTARGET ? unit.CurrentOrder()->GetGoal(): &unit; const CUnit *goal = flags & ANIM_SM_RELTARGET ? unit.CurrentOrder()->GetGoal() : &unit;
PixelPos start; PixelPos start;
PixelPos dest; PixelPos dest;

View file

@ -30,17 +30,17 @@
extern "C" { extern "C" {
/** /**
** Need init function for beos. ** Need init function for beos.
** **
** @param argc Number of command line argurments ** @param argc Number of command line argurments
*/ */
void beos_init(int argc, char** argv) void beos_init(int argc, char **argv)
{ {
BPath path( argv[0] ); BPath path(argv[0]);
path.GetParent( &path ); path.GetParent(&path);
chdir( path.Path() ); chdir(path.Path());
} }
} }

View file

@ -44,7 +44,7 @@
-- Variables -- Variables
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
static osso_context_t * osso = NULL; static osso_context_t *osso = NULL;
static SDL_TimerID timer = NULL; static SDL_TimerID timer = NULL;
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
@ -57,8 +57,9 @@ static SDL_TimerID timer = NULL;
**/ **/
static Uint32 OssoKeepBacklightAlive(Uint32 interval, void *) static Uint32 OssoKeepBacklightAlive(Uint32 interval, void *)
{ {
if (!osso) if (!osso) {
return 0; return 0;
}
osso_display_state_on(osso); osso_display_state_on(osso);
osso_display_blanking_pause(osso); osso_display_blanking_pause(osso);
@ -72,15 +73,16 @@ static Uint32 OssoKeepBacklightAlive(Uint32 interval, void *)
**/ **/
static void OssoInitialize(void) static void OssoInitialize(void)
{ {
char * application; char *application;
if (FullGameName.empty()) { if (FullGameName.empty()) {
application = strdup("org.stratagus"); application = strdup("org.stratagus");
} else { } else {
application = (char *)calloc(FullGameName.size() + 15, 1); application = (char *)calloc(FullGameName.size() + 15, 1);
strcpy(application, "org.stratagus."); strcpy(application, "org.stratagus.");
for (int i = 0; i < FullGameName.size(); i++) for (int i = 0; i < FullGameName.size(); i++) {
application[i+14] = tolower(FullGameName[i]); application[i + 14] = tolower(FullGameName[i]);
}
} }
osso = osso_initialize(application, VERSION, TRUE, NULL); osso = osso_initialize(application, VERSION, TRUE, NULL);

View file

@ -114,9 +114,9 @@ void CMap::MarkSeenTile(const unsigned int index)
// Handle Walls changes. // Handle Walls changes.
} else if (this->Tileset.TileTypeTable[tile] == TileTypeHumanWall } else if (this->Tileset.TileTypeTable[tile] == TileTypeHumanWall
|| this->Tileset.TileTypeTable[tile] == TileTypeOrcWall || this->Tileset.TileTypeTable[tile] == TileTypeOrcWall
|| this->Tileset.TileTypeTable[seentile] == TileTypeHumanWall || this->Tileset.TileTypeTable[seentile] == TileTypeHumanWall
|| this->Tileset.TileTypeTable[seentile] == TileTypeOrcWall) { || this->Tileset.TileTypeTable[seentile] == TileTypeOrcWall) {
MapFixSeenWallTile(pos); MapFixSeenWallTile(pos);
MapFixSeenWallNeighbors(pos); MapFixSeenWallNeighbors(pos);
} }
@ -231,8 +231,8 @@ bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos)
for (int addy = 0; addy < type.TileHeight; ++addy) { for (int addy = 0; addy < type.TileHeight; ++addy) {
for (int addx = 0; addx < type.TileWidth; ++addx) { for (int addx = 0; addx < type.TileWidth; ++addx) {
if (!(Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy) if (Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy) == false
&& !Map.CheckMask(pos.x + addx + index, mask))) { || Map.CheckMask(pos.x + addx + index, mask) == true) {
return false; return false;
} }
} }

View file

@ -352,7 +352,7 @@ void CViewport::Draw() const
//FIXME: This is still unsecure during parallel //FIXME: This is still unsecure during parallel
if (!Preference.ShowOrders) { if (!Preference.ShowOrders) {
} else if (Preference.ShowOrders < 0 } else if (Preference.ShowOrders < 0
|| (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) { || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
for (int i = 0; i < NumSelected; ++i) { for (int i = 0; i < NumSelected; ++i) {
ShowOrder(*Selected[i]); ShowOrder(*Selected[i]);
} }

View file

@ -781,7 +781,7 @@ void Missile::MissileHit()
// //
if (!mtype.Range) { if (!mtype.Range) {
if (this->TargetUnit && (mtype.FriendlyFire == false if (this->TargetUnit && (mtype.FriendlyFire == false
|| this->TargetUnit->Player->Index != this->SourceUnit->Player->Index)) { || this->TargetUnit->Player->Index != this->SourceUnit->Player->Index)) {
// //
// Missiles without range only hits the goal always. // Missiles without range only hits the goal always.
// //
@ -934,7 +934,7 @@ void Missile::NextMissileFrameCycle()
j = f - i; j = f - i;
} }
this->SpriteFrame = this->SpriteFrame % (this->Type->NumDirections / 2 + 1) + this->SpriteFrame = this->SpriteFrame % (this->Type->NumDirections / 2 + 1) +
j * (this->Type->NumDirections / 2 + 1); j * (this->Type->NumDirections / 2 + 1);
break; break;
} }
} }
@ -1048,7 +1048,7 @@ void Missile::SaveMissile(CFile &file) const
file.printf(", \"goal\", "); file.printf(", \"goal\", ");
SavePixelPos(file, this->destination); SavePixelPos(file, this->destination);
file.printf(",\n \"frame\", %d, \"state\", %d, \"anim-wait\", %d, \"wait\", %d, \"delay\", %d,\n ", file.printf(",\n \"frame\", %d, \"state\", %d, \"anim-wait\", %d, \"wait\", %d, \"delay\", %d,\n ",
this->SpriteFrame, this->State, this->AnimWait, this->Wait, this->Delay); this->SpriteFrame, this->State, this->AnimWait, this->Wait, this->Delay);
if (this->SourceUnit != NULL) { if (this->SourceUnit != NULL) {
file.printf(" \"source\", \"%s\",", UnitReference(this->SourceUnit).c_str()); file.printf(" \"source\", \"%s\",", UnitReference(this->SourceUnit).c_str());
} }

View file

@ -1038,7 +1038,7 @@ void NetworkEvent()
if (slot < UnitSlotFree if (slot < UnitSlotFree
&& (UnitSlots[slot]->Player->Index == player && (UnitSlots[slot]->Player->Index == player
|| Players[player].IsTeamed(*UnitSlots[slot]))) { || Players[player].IsTeamed(*UnitSlots[slot]))) {
validCommand = true; validCommand = true;
} else { } else {
validCommand = false; validCommand = false;
@ -1054,7 +1054,7 @@ void NetworkEvent()
} else { } else {
SetMessage(_("%s sent bad command"), Players[player].Name.c_str()); SetMessage(_("%s sent bad command"), Players[player].Name.c_str());
DebugPrint("%s sent bad command: 0x%x\n" _C_ Players[player].Name.c_str() DebugPrint("%s sent bad command: 0x%x\n" _C_ Players[player].Name.c_str()
_C_ packet.Header.Type[i] & 0x7F); _C_ packet.Header.Type[i] & 0x7F);
} }
} }

View file

@ -201,7 +201,7 @@ inline void ProfilePrint()
} }
std::vector<ProfileData *> prof; std::vector<ProfileData *> prof;
for (std::map<const char *const, ProfileData>::iterator i = functionProfiles.begin(); for (std::map<const char *const, ProfileData>::iterator i = functionProfiles.begin();
i != functionProfiles.end(); ++i) { i != functionProfiles.end(); ++i) {
ProfileData *data = &i->second; ProfileData *data = &i->second;
prof.insert(std::upper_bound(prof.begin(), prof.end(), data, compProfileData), data); prof.insert(std::upper_bound(prof.begin(), prof.end(), data, compProfileData), data);
} }
@ -415,7 +415,7 @@ static inline int AStarAddNode(const Vec2i &pos, int o, int costs)
smalli = midi; smalli = midi;
} else if (costs < midcost || (costs == midcost } else if (costs < midcost || (costs == midcost
&& (costToGoal < midCostToGoal || (costToGoal == midCostToGoal && (costToGoal < midCostToGoal || (costToGoal == midCostToGoal
&& dist < midDist)))) { && dist < midDist)))) {
if (bigi == midi) { if (bigi == midi) {
bigi++; bigi++;
} else { } else {

View file

@ -839,12 +839,12 @@ static int CclSetPlayerData(lua_State *l)
const std::string res = LuaToString(l, 3); const std::string res = LuaToString(l, 3);
const int resId = GetResourceIdByName(l, res.c_str()); const int resId = GetResourceIdByName(l, res.c_str());
p->SetResource(resId, LuaToNumber(l, 4), true); p->SetResource(resId, LuaToNumber(l, 4), true);
// } else if (!strcmp(data, "UnitTypesCount")) { // } else if (!strcmp(data, "UnitTypesCount")) {
// } else if (!strcmp(data, "AiEnabled")) { // } else if (!strcmp(data, "AiEnabled")) {
// } else if (!strcmp(data, "TotalNumUnits")) { // } else if (!strcmp(data, "TotalNumUnits")) {
// } else if (!strcmp(data, "NumBuildings")) { // } else if (!strcmp(data, "NumBuildings")) {
// } else if (!strcmp(data, "Supply")) { // } else if (!strcmp(data, "Supply")) {
// } else if (!strcmp(data, "Demand")) { // } else if (!strcmp(data, "Demand")) {
} else if (!strcmp(data, "UnitLimit")) { } else if (!strcmp(data, "UnitLimit")) {
p->UnitLimit = LuaToNumber(l, 3); p->UnitLimit = LuaToNumber(l, 3);
} else if (!strcmp(data, "BuildingLimit")) { } else if (!strcmp(data, "BuildingLimit")) {

View file

@ -779,7 +779,7 @@ int AddSelectedUnitsInRectangle(int x0, int y0, int x1, int y1)
// In this case, do nothing. // In this case, do nothing.
if (NumSelected == 1 if (NumSelected == 1
&& (!CanSelectMultipleUnits(*Selected[0]->Player) && (!CanSelectMultipleUnits(*Selected[0]->Player)
|| !Selected[0]->Type->SelectableByRectangle)) { || !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected; return NumSelected;
} }
// If there is no selected unit yet, do a simple selection. // If there is no selected unit yet, do a simple selection.
@ -929,7 +929,7 @@ int AddSelectedGroundUnitsInRectangle(int sx0, int sy0, int sx1, int sy1)
// In this case, do nothing. // In this case, do nothing.
if (NumSelected == 1 if (NumSelected == 1
&& (!CanSelectMultipleUnits(*Selected[0]->Player) && (!CanSelectMultipleUnits(*Selected[0]->Player)
|| !Selected[0]->Type->SelectableByRectangle)) { || !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected; return NumSelected;
} }
@ -993,7 +993,7 @@ int AddSelectedAirUnitsInRectangle(int sx0, int sy0, int sx1, int sy1)
// In this case, do nothing. // In this case, do nothing.
if (NumSelected == 1 if (NumSelected == 1
&& (!CanSelectMultipleUnits(*Selected[0]->Player) && (!CanSelectMultipleUnits(*Selected[0]->Player)
|| !Selected[0]->Type->SelectableByRectangle)) { || !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected; return NumSelected;
} }

View file

@ -324,7 +324,6 @@ int SpawnMissile::Cast(CUnit &caster, const SpellType *, CUnit *target, const Ve
missile->SourceUnit = &caster; missile->SourceUnit = &caster;
} }
missile->TargetUnit = target; missile->TargetUnit = target;
return 1; return 1;
} }
@ -423,11 +422,11 @@ int AdjustVitals::Cast(CUnit &caster, const SpellType *spell, CUnit *target, con
int castcount = 1; int castcount = 1;
if (hp) { if (hp) {
castcount = std::max<int>(castcount, castcount = std::max<int>(castcount,
diffHP / abs(hp) + (((hp < 0) && (diffHP % (-hp) > 0)) ? 1 : 0)); diffHP / abs(hp) + (((hp < 0) && (diffHP % (-hp) > 0)) ? 1 : 0));
} }
if (mana) { if (mana) {
castcount = std::max<int>(castcount, castcount = std::max<int>(castcount,
diffMana / abs(mana) + (((mana < 0) && (diffMana % (-mana) > 0)) ? 1 : 0)); diffMana / abs(mana) + (((mana < 0) && (diffMana % (-mana) > 0)) ? 1 : 0));
} }
if (manacost) { if (manacost) {
castcount = std::min<int>(castcount, caster.Variable[MANA_INDEX].Value / manacost); castcount = std::min<int>(castcount, caster.Variable[MANA_INDEX].Value / manacost);
@ -689,7 +688,7 @@ static Target *NewTargetUnit(CUnit &unit)
** @return true if passed, false otherwise. ** @return true if passed, false otherwise.
*/ */
static bool PassCondition(const CUnit &caster, const SpellType *spell, const CUnit *target, static bool PassCondition(const CUnit &caster, const SpellType *spell, const CUnit *target,
const Vec2i &/*goalPos*/, const ConditionInfo *condition) const Vec2i &/*goalPos*/, const ConditionInfo *condition)
{ {
if (caster.Variable[MANA_INDEX].Value < spell->ManaCost) { // Check caster mana. if (caster.Variable[MANA_INDEX].Value < spell->ManaCost) { // Check caster mana.
return false; return false;

View file

@ -352,7 +352,7 @@ int CPopupContentTypeCosts::GetWidth(const ButtonAction *button, int *Costs) con
for (unsigned int i = 1; i < MaxCosts; ++i) { for (unsigned int i = 1; i < MaxCosts; ++i) {
if (Costs[i]) { if (Costs[i]) {
if(UI.Resources[i].IconWidth != -1) { if (UI.Resources[i].IconWidth != -1) {
popupWidth += (UI.Resources[i].IconWidth + 5); popupWidth += (UI.Resources[i].IconWidth + 5);
} else { } else {
const CGraphic *G = UI.Resources[i].G; const CGraphic *G = UI.Resources[i].G;
@ -551,8 +551,8 @@ static void GetPopupSize(const ButtonAction *button, const CUIButton *uibutton,
CPopup &popup = *PopupByIdent(button->Popup); CPopup &popup = *PopupByIdent(button->Popup);
for (std::vector<CPopupContentType *>::const_iterator it = popup.Contents.begin(); for (std::vector<CPopupContentType *>::const_iterator it = popup.Contents.begin();
it != popup.Contents.end(); it != popup.Contents.end();
++it) { ++it) {
const CPopupContentType &content = **it; const CPopupContentType &content = **it;
if (CanShowPopupContent(content.Condition, button, UnitTypes[button->Value])) { if (CanShowPopupContent(content.Condition, button, UnitTypes[button->Value])) {
@ -724,10 +724,10 @@ void DrawPopup(const ButtonAction *button, const CUIButton *uibutton)
// Contents // Contents
for (std::vector<CPopupContentType *>::const_iterator content = popup->Contents.begin(); for (std::vector<CPopupContentType *>::const_iterator content = popup->Contents.begin();
content != popup->Contents.end(); ++content) { content != popup->Contents.end(); ++content) {
if (CanShowPopupContent((*content)->Condition, button, UnitTypes[button->Value])) { if (CanShowPopupContent((*content)->Condition, button, UnitTypes[button->Value])) {
(*content)->Draw(x + (*content)->PosX, y + (*content)->PosY, button, Costs); (*content)->Draw(x + (*content)->PosX, y + (*content)->PosY, button, Costs);
} }
} }
#if 0 // Fixme: need to remove soon #if 0 // Fixme: need to remove soon
@ -994,9 +994,9 @@ static bool IsButtonAllowed(const CUnit &unit, const ButtonAction *buttonaction)
break; break;
case ButtonReturn: case ButtonReturn:
if (!(!unit.CurrentResource if (!(!unit.CurrentResource
|| !(unit.ResourcesHeld > 0 && !unit.Type->ResInfo[unit.CurrentResource]->LoseResources) || !(unit.ResourcesHeld > 0 && !unit.Type->ResInfo[unit.CurrentResource]->LoseResources)
|| (unit.ResourcesHeld != unit.Type->ResInfo[unit.CurrentResource]->ResourceCapacity || (unit.ResourcesHeld != unit.Type->ResInfo[unit.CurrentResource]->ResourceCapacity
&& unit.Type->ResInfo[unit.CurrentResource]->LoseResources))) { && unit.Type->ResInfo[unit.CurrentResource]->LoseResources))) {
res = true; res = true;
} }
break; break;
@ -1234,7 +1234,7 @@ void CButtonPanel::DoClicked(int button)
// That or a bunker. // That or a bunker.
// //
if ((NumSelected == 1 && Selected[0]->CurrentAction() == UnitActionStill if ((NumSelected == 1 && Selected[0]->CurrentAction() == UnitActionStill
&& Map.CoastOnMap(Selected[0]->tilePos)) && Map.CoastOnMap(Selected[0]->tilePos))
|| !Selected[0]->CanMove()) { || !Selected[0]->CanMove()) {
SendCommandUnload(*Selected[0], Selected[0]->tilePos, NoUnitP, flush); SendCommandUnload(*Selected[0], Selected[0]->tilePos, NoUnitP, flush);
break; break;
@ -1420,8 +1420,9 @@ void CButtonPanel::DoClicked(int button)
UI.StatusLine.Clear(); UI.StatusLine.Clear();
ClearCosts(); ClearCosts();
} else if (Selected[0]->Player->CheckLimits(type) == -3) } else if (Selected[0]->Player->CheckLimits(type) == -3)
if (GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound) if (GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound) {
PlayGameSound(GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound, MaxSampleVolume); PlayGameSound(GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound, MaxSampleVolume);
}
break; break;
} }
case ButtonUpgradeTo: { case ButtonUpgradeTo: {

View file

@ -703,7 +703,7 @@ static void DrawUnitInfo(CUnit &unit)
order.GetUnitType().Icon.Icon->DrawUnitIcon( order.GetUnitType().Icon.Icon->DrawUnitIcon(
UI.UpgradingButton->Style, UI.UpgradingButton->Style,
(ButtonAreaUnderCursor == ButtonAreaUpgrading (ButtonAreaUnderCursor == ButtonAreaUpgrading
&& ButtonUnderCursor == 0) ? && ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0, (IconActive | (MouseButtons & LeftButton)) : 0,
UI.UpgradingButton->X, UI.UpgradingButton->Y, ""); UI.UpgradingButton->X, UI.UpgradingButton->Y, "");
} }
@ -716,7 +716,7 @@ static void DrawUnitInfo(CUnit &unit)
order.GetUpgrade().Icon->DrawUnitIcon( order.GetUpgrade().Icon->DrawUnitIcon(
UI.ResearchingButton->Style, UI.ResearchingButton->Style,
(ButtonAreaUnderCursor == ButtonAreaResearching (ButtonAreaUnderCursor == ButtonAreaResearching
&& ButtonUnderCursor == 0) ? && ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0, (IconActive | (MouseButtons & LeftButton)) : 0,
UI.ResearchingButton->X, UI.ResearchingButton->Y, ""); UI.ResearchingButton->X, UI.ResearchingButton->Y, "");
} }

View file

@ -890,7 +890,7 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l)
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
key = LuaToString(l, -2); key = LuaToString(l, -2);
if (!strcmp(key, "ButtonType")) { if (!strcmp(key, "ButtonType")) {
} else { } else {
int index = UnitTypeVar.BoolFlagNameLookup[key]; int index = UnitTypeVar.BoolFlagNameLookup[key];
if (index != -1) { if (index != -1) {
@ -959,20 +959,20 @@ static CPopupContentType *CclParsePopupContent(lua_State *l)
} }
content = contentname; content = contentname;
} else if (!strcmp(key, "Costs")) { } else if (!strcmp(key, "Costs")) {
CPopupContentTypeCosts *contentcosts = new CPopupContentTypeCosts; CPopupContentTypeCosts *contentcosts = new CPopupContentTypeCosts;
Assert(lua_istable(l, -1)); Assert(lua_istable(l, -1));
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
key = LuaToString(l, -2); key = LuaToString(l, -2);
if (!strcmp(key, "Font")) { if (!strcmp(key, "Font")) {
contentcosts->Font = CFont::Get(LuaToString(l, -1)); contentcosts->Font = CFont::Get(LuaToString(l, -1));
} else if (!strcmp(key, "Centered")) { } else if (!strcmp(key, "Centered")) {
contentcosts->Centered = LuaToBoolean(l, -1); contentcosts->Centered = LuaToBoolean(l, -1);
} else { } else {
LuaError(l, "'%s' invalid for method 'Costs' in DefinePopups" _C_ key); LuaError(l, "'%s' invalid for method 'Costs' in DefinePopups" _C_ key);
}
} }
content = contentcosts; }
content = contentcosts;
} else if (!strcmp(key, "Variable")) { } else if (!strcmp(key, "Variable")) {
CPopupContentTypeVariable *contenttext = new CPopupContentTypeVariable; CPopupContentTypeVariable *contenttext = new CPopupContentTypeVariable;

View file

@ -276,8 +276,8 @@ void CleanUserInterface()
// Button Popups // Button Popups
for (std::vector<CPopup *>::iterator popup = UI.ButtonPopups.begin(); for (std::vector<CPopup *>::iterator popup = UI.ButtonPopups.begin();
popup != UI.ButtonPopups.end(); ++popup) { popup != UI.ButtonPopups.end(); ++popup) {
delete *popup; delete *popup;
} }
UI.ButtonPopups.clear(); UI.ButtonPopups.clear();

View file

@ -1591,10 +1591,10 @@ void CUnit::AssignWorkerToMine(CUnit &mine)
CUnit *head = mine.Resource.Workers; CUnit *head = mine.Resource.Workers;
#if 0 #if 0
DebugPrint("%d: Worker [%d] is adding into %s [%d] on %d pos\n" DebugPrint("%d: Worker [%d] is adding into %s [%d] on %d pos\n"
_C_ this->Player->Index _C_ this->Slot _C_ this->Player->Index _C_ this->Slot
_C_ mine.Type->Name.c_str() _C_ mine.Type->Name.c_str()
_C_ mine.Slot _C_ mine.Slot
_C_ mine.Data.Resource.Assigned); _C_ mine.Data.Resource.Assigned);
#endif #endif
this->RefsIncrease(); this->RefsIncrease();
this->NextWorker = head; this->NextWorker = head;
@ -1610,10 +1610,10 @@ void CUnit::DeAssignWorkerFromMine(CUnit &mine)
CUnit *prev = NULL, *worker = mine.Resource.Workers; CUnit *prev = NULL, *worker = mine.Resource.Workers;
#if 0 #if 0
DebugPrint("%d: Worker [%d] is removing from %s [%d] left %d units assigned\n" DebugPrint("%d: Worker [%d] is removing from %s [%d] left %d units assigned\n"
_C_ this->Player->Index _C_ this->Slot _C_ this->Player->Index _C_ this->Slot
_C_ mine.Type->Name.c_str() _C_ mine.Type->Name.c_str()
_C_ mine.Slot _C_ mine.Slot
_C_ mine.CurrentOrder()->Data.Resource.Assigned); _C_ mine.CurrentOrder()->Data.Resource.Assigned);
#endif #endif
for (int i = 0; NULL != worker; worker = worker->NextWorker, ++i) { for (int i = 0; NULL != worker; worker = worker->NextWorker, ++i) {
if (worker == this) { if (worker == this) {

View file

@ -578,13 +578,13 @@ static void DrawDecoration(const CUnit &unit, const CUnitType *type, int x, int
Assert(value <= max); Assert(value <= max);
if (!((value == 0 && !var->ShowWhenNull) || (value == max && !var->ShowWhenMax) if (!((value == 0 && !var->ShowWhenNull) || (value == max && !var->ShowWhenMax)
|| (var->HideHalf && value != 0 && value != max) || (var->HideHalf && value != 0 && value != max)
|| (!var->ShowIfNotEnable && !unit.Variable[var->Index].Enable) || (!var->ShowIfNotEnable && !unit.Variable[var->Index].Enable)
|| (var->ShowOnlySelected && !unit.Selected) || (var->ShowOnlySelected && !unit.Selected)
|| (unit.Player->Type == PlayerNeutral && var->HideNeutral) || (unit.Player->Type == PlayerNeutral && var->HideNeutral)
|| (ThisPlayer->IsEnemy(unit) && !var->ShowOpponent) || (ThisPlayer->IsEnemy(unit) && !var->ShowOpponent)
|| (ThisPlayer->IsAllied(unit) && (unit.Player != ThisPlayer) && var->HideAllied) || (ThisPlayer->IsAllied(unit) && (unit.Player != ThisPlayer) && var->HideAllied)
|| max == 0)) { || max == 0)) {
var->Draw( var->Draw(
x + var->OffsetX + var->OffsetXPercent * unit.Type->TileWidth * PixelTileSize.x / 100, x + var->OffsetX + var->OffsetXPercent * unit.Type->TileWidth * PixelTileSize.x / 100,
y + var->OffsetY + var->OffsetYPercent * unit.Type->TileHeight * PixelTileSize.y / 100, y + var->OffsetY + var->OffsetYPercent * unit.Type->TileHeight * PixelTileSize.y / 100,
@ -719,8 +719,9 @@ static void DrawInformations(const CUnit &unit, const CUnitType &type, int x, in
// For debug draw sight, react and attack range! // For debug draw sight, react and attack range!
// //
if (NumSelected == 1 && unit.Selected) { if (NumSelected == 1 && unit.Selected) {
const PixelPos center = {x + type.TileWidth * PixelTileSize.x / 2, const PixelPos center = {x + type.TileWidth *PixelTileSize.x / 2,
y + type.TileHeight * PixelTileSize.y / 2}; y + type.TileHeight *PixelTileSize.y / 2
};
if (Preference.ShowSightRange) { if (Preference.ShowSightRange) {
const int value = stats.Variables[SIGHTRANGE_INDEX].Max; const int value = stats.Variables[SIGHTRANGE_INDEX].Max;

View file

@ -61,7 +61,7 @@ std::string UnitReference(const CUnit &unit)
{ {
std::ostringstream ss; std::ostringstream ss;
ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase
<< std::hex << UnitNumber(unit); << std::hex << UnitNumber(unit);
return ss.str(); return ss.str();
} }
@ -74,7 +74,7 @@ std::string UnitReference(const CUnitPtr &unit)
std::ostringstream ss; std::ostringstream ss;
ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase
<< std::hex << unit->Slot; << std::hex << unit->Slot;
return ss.str(); return ss.str();
} }

View file

@ -56,7 +56,7 @@ void CUnitPtr::Reset()
unit = NULL; unit = NULL;
} }
CUnitPtr& CUnitPtr::operator= (CUnit *u) CUnitPtr &CUnitPtr::operator= (CUnit *u)
{ {
if (this->unit != u) { if (this->unit != u) {
if (u) { if (u) {

View file

@ -36,47 +36,54 @@ static HINSTANCE lib_ntdll = NULL;
typedef int FAR WINAPI proto_AttachConsole(int); typedef int FAR WINAPI proto_AttachConsole(int);
typedef int FAR WINAPI proto_NtQueryObject(HANDLE, int, void *, unsigned long int, unsigned long int *); typedef int FAR WINAPI proto_NtQueryObject(HANDLE, int, void *, unsigned long int, unsigned long int *);
static proto_AttachConsole * func_AttachConsole = NULL; static proto_AttachConsole *func_AttachConsole = NULL;
static proto_NtQueryObject * func_NtQueryObject = NULL; static proto_NtQueryObject *func_NtQueryObject = NULL;
/// Check if HANDLE is attached to console /// Check if HANDLE is attached to console
static int WINAPI_CheckIfConsoleHandle(HANDLE handle) { static int WINAPI_CheckIfConsoleHandle(HANDLE handle)
{
wchar_t filename[MAX_PATH]; wchar_t filename[MAX_PATH];
unsigned long int length = 0; unsigned long int length = 0;
// Try to get filename of HANDLE // Try to get filename of HANDLE
if ( func_NtQueryObject ) if (func_NtQueryObject) {
func_NtQueryObject(handle, 1, filename, MAX_PATH, &length); func_NtQueryObject(handle, 1, filename, MAX_PATH, &length);
}
// Filename start at position 8 // Filename start at position 8
if ( length > 8 ) if (length > 8) {
return 0; return 0;
else } else {
return 1; return 1;
}
} }
/// Try to reopen FILE* from WINAPI HANDLE /// Try to reopen FILE* from WINAPI HANDLE
static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char * mode) { static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE *file, const char *mode)
{
int fd; int fd;
FILE * newfile; FILE *newfile;
if ( ! handle || handle == INVALID_HANDLE_VALUE ) if (! handle || handle == INVALID_HANDLE_VALUE) {
return; return;
}
// Get file descriptor from HANDLE // Get file descriptor from HANDLE
fd = _open_osfhandle((intptr_t)handle, O_TEXT); fd = _open_osfhandle((intptr_t)handle, O_TEXT);
if ( fd < 0 ) if (fd < 0) {
return; return;
}
// Get C structure FILE* from file descriptior // Get C structure FILE* from file descriptior
newfile = _fdopen(fd, mode); newfile = _fdopen(fd, mode);
if ( ! newfile ) if (! newfile) {
return; return;
}
// Close current file // Close current file
fclose(file); fclose(file);
@ -87,7 +94,7 @@ static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char *
setvbuf(file, NULL, _IONBF, 0); setvbuf(file, NULL, _IONBF, 0);
// If stdout/stderr write 2 empty lines to cmd console // If stdout/stderr write 2 empty lines to cmd console
if ( ! fixmode && strcmp(mode, "w") == 0 ) { if (! fixmode && strcmp(mode, "w") == 0) {
fprintf(file, "\n\n"); fprintf(file, "\n\n");
fixmode = 1; fixmode = 1;
@ -97,27 +104,31 @@ static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char *
} }
/// Try to set std HANDLE from FILE* /// Try to set std HANDLE from FILE*
static void WINAPI_SetStdHandleFromFile(int type, FILE * file) { static void WINAPI_SetStdHandleFromFile(int type, FILE *file)
{
int fd; int fd;
HANDLE handle; HANDLE handle;
fd = _fileno(file); fd = _fileno(file);
if ( fd < 0 ) if (fd < 0) {
return; return;
}
handle = (HANDLE)_get_osfhandle(fd); handle = (HANDLE)_get_osfhandle(fd);
if ( ! handle || handle == INVALID_HANDLE_VALUE ) if (! handle || handle == INVALID_HANDLE_VALUE) {
return; return;
}
SetStdHandle(type, handle); SetStdHandle(type, handle);
} }
/// Try attach console of parent process for std input/output in Windows NT, 2000, XP or new /// Try attach console of parent process for std input/output in Windows NT, 2000, XP or new
static void WINAPI_AttachConsole(void) { static void WINAPI_AttachConsole(void)
{
OSVERSIONINFO osvi; OSVERSIONINFO osvi;
int hasVersion; int hasVersion;
@ -132,29 +143,34 @@ static void WINAPI_AttachConsole(void) {
hasVersion = GetVersionEx(&osvi); hasVersion = GetVersionEx(&osvi);
if ( ! hasVersion ) if (! hasVersion) {
return; return;
}
version = ( osvi.dwMajorVersion << 8 ) | osvi.dwMinorVersion; version = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
// We need Windows 2000 or new // We need Windows 2000 or new
if ( version < 0x0500 ) if (version < 0x0500) {
return; return;
}
lib_kernel32 = LoadLibrary("kernel32.dll"); lib_kernel32 = LoadLibrary("kernel32.dll");
if ( ! lib_kernel32 ) if (! lib_kernel32) {
return; return;
}
func_AttachConsole = (proto_AttachConsole*)GetProcAddress(lib_kernel32, "AttachConsole"); func_AttachConsole = (proto_AttachConsole *)GetProcAddress(lib_kernel32, "AttachConsole");
if ( ! func_AttachConsole ) if (! func_AttachConsole) {
return; return;
}
lib_ntdll = LoadLibrary("ntdll.dll"); lib_ntdll = LoadLibrary("ntdll.dll");
if ( lib_ntdll ) if (lib_ntdll) {
func_NtQueryObject = (proto_NtQueryObject*)GetProcAddress(lib_ntdll, "NtQueryObject"); func_NtQueryObject = (proto_NtQueryObject *)GetProcAddress(lib_ntdll, "NtQueryObject");
}
// Ignore if HANDLE is not attached console // Ignore if HANDLE is not attached console
reopen_stdin = WINAPI_CheckIfConsoleHandle(GetStdHandle(STD_INPUT_HANDLE)); reopen_stdin = WINAPI_CheckIfConsoleHandle(GetStdHandle(STD_INPUT_HANDLE));
@ -163,23 +179,27 @@ static void WINAPI_AttachConsole(void) {
attached = func_AttachConsole(-1); attached = func_AttachConsole(-1);
if ( ! attached ) if (! attached) {
return; return;
}
if ( reopen_stdin ) if (reopen_stdin) {
WINAPI_ReopenFileFromHandle(GetStdHandle(STD_INPUT_HANDLE), stdin, "r"); WINAPI_ReopenFileFromHandle(GetStdHandle(STD_INPUT_HANDLE), stdin, "r");
else } else {
WINAPI_SetStdHandleFromFile(STD_INPUT_HANDLE, stdin); WINAPI_SetStdHandleFromFile(STD_INPUT_HANDLE, stdin);
}
if ( reopen_stdout ) if (reopen_stdout) {
WINAPI_ReopenFileFromHandle(GetStdHandle(STD_OUTPUT_HANDLE), stdout, "w"); WINAPI_ReopenFileFromHandle(GetStdHandle(STD_OUTPUT_HANDLE), stdout, "w");
else } else {
WINAPI_SetStdHandleFromFile(STD_OUTPUT_HANDLE, stdout); WINAPI_SetStdHandleFromFile(STD_OUTPUT_HANDLE, stdout);
}
if ( reopen_stderr ) if (reopen_stderr) {
WINAPI_ReopenFileFromHandle(GetStdHandle(STD_ERROR_HANDLE), stderr, "w"); WINAPI_ReopenFileFromHandle(GetStdHandle(STD_ERROR_HANDLE), stderr, "w");
else } else {
WINAPI_SetStdHandleFromFile(STD_ERROR_HANDLE, stderr); WINAPI_SetStdHandleFromFile(STD_ERROR_HANDLE, stderr);
}
#ifdef __cplusplus #ifdef __cplusplus
std::cin.clear(); std::cin.clear();