From 390b143f3d35a02fcd3d21dd44f4921a36e11f9a Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Mon, 31 Jul 2023 23:12:21 +0200 Subject: [PATCH] Use `nullptr` instead of `NULL`. --- src/action/action_attack.cpp | 22 +-- src/action/action_board.cpp | 2 +- src/action/action_build.cpp | 26 ++-- src/action/action_built.cpp | 22 +-- src/action/action_defend.cpp | 2 +- src/action/action_die.cpp | 8 +- src/action/action_follow.cpp | 14 +- src/action/action_repair.cpp | 16 +- src/action/action_resource.cpp | 46 +++--- src/action/action_still.cpp | 22 +-- src/action/action_train.cpp | 6 +- src/action/action_unload.cpp | 4 +- src/action/action_upgradeto.cpp | 2 +- src/action/actions.cpp | 14 +- src/action/command.cpp | 54 +++---- src/ai/ai.cpp | 12 +- src/ai/ai_building.cpp | 14 +- src/ai/ai_force.cpp | 60 ++++---- src/ai/ai_local.h | 8 +- src/ai/ai_plan.cpp | 16 +- src/ai/ai_resource.cpp | 22 +-- src/ai/script_ai.cpp | 14 +- src/animation/animation.cpp | 18 +-- src/animation/animation_exactframe.cpp | 2 +- src/animation/animation_frame.cpp | 2 +- src/animation/animation_setvar.cpp | 2 +- src/animation/animation_spawnmissile.cpp | 2 +- src/animation/animation_spawnunit.cpp | 4 +- src/editor/editloop.cpp | 52 +++---- src/editor/editor.cpp | 2 +- src/editor/edmap.cpp | 10 +- src/game/game.cpp | 14 +- src/game/replay.cpp | 22 +-- src/game/trigger.cpp | 4 +- src/include/action/action_attack.h | 2 +- src/include/action/action_build.h | 2 +- src/include/action/action_built.h | 2 +- src/include/action/action_research.h | 2 +- src/include/action/action_spellcast.h | 2 +- src/include/action/action_train.h | 2 +- src/include/action/action_upgradeto.h | 4 +- src/include/actions.h | 2 +- src/include/animation.h | 10 +- src/include/animation/animation_goto.h | 2 +- src/include/animation/animation_ifvar.h | 2 +- src/include/animation/animation_luacallback.h | 2 +- src/include/animation/animation_randomgoto.h | 2 +- src/include/animation/animation_wiggle.h | 2 +- src/include/construct.h | 6 +- src/include/cursor.h | 6 +- src/include/font.h | 4 +- src/include/icons.h | 2 +- src/include/interface.h | 4 +- src/include/missile.h | 4 +- src/include/missileconfig.h | 2 +- src/include/movie.h | 6 +- src/include/sound.h | 2 +- src/include/sound_server.h | 2 +- src/include/spell/spell_adjustvariable.h | 2 +- src/include/spell/spell_areabombardment.h | 2 +- src/include/spell/spell_luacallback.h | 2 +- src/include/spell/spell_polymorph.h | 2 +- src/include/spell/spell_summon.h | 2 +- src/include/spells.h | 6 +- src/include/st_backtrace.h | 4 +- src/include/title.h | 2 +- src/include/ui.h | 26 ++-- src/include/ui/contenttype.h | 12 +- src/include/ui/popup.h | 14 +- src/include/ui/uitimer.h | 2 +- src/include/unit.h | 12 +- src/include/unit_cache.h | 4 +- src/include/unit_find.h | 6 +- src/include/unitptr.h | 2 +- src/include/unitsound.h | 4 +- src/include/unittype.h | 16 +- src/include/upgrade_structs.h | 4 +- src/include/video.h | 14 +- src/include/widgets.h | 6 +- src/map/fov.cpp | 2 +- src/map/fow.cpp | 4 +- src/map/map.cpp | 6 +- src/map/map_draw.cpp | 16 +- src/map/map_fog.cpp | 4 +- src/map/minimap.cpp | 20 +-- src/map/script_map.cpp | 2 +- src/map/script_tileset.cpp | 2 +- src/missile/missile.cpp | 42 +++--- src/missile/missile_cliptotarget.cpp | 2 +- src/missile/missile_deathcoil.cpp | 2 +- src/missile/missile_landmine.cpp | 2 +- src/missile/missile_parabolic.cpp | 2 +- src/missile/missile_tracer.cpp | 2 +- src/missile/missileconfig.cpp | 4 +- src/missile/script_missile.cpp | 14 +- src/network/commands.cpp | 112 +++++++------- src/network/mdns.cpp | 6 +- src/network/net_lowlevel.cpp | 20 +-- src/network/net_message.cpp | 8 +- src/network/network.cpp | 8 +- src/network/online_service.cpp | 66 ++++----- src/network/xsha1.h | 2 +- src/particle/particlemanager.cpp | 4 +- src/pathfinder/astar.cpp | 6 +- src/pathfinder/pathfinder.cpp | 6 +- src/sound/script_sound.cpp | 6 +- src/sound/sound.cpp | 22 +-- src/sound/sound_id.cpp | 4 +- src/sound/sound_server.cpp | 56 +++---- src/sound/unitsound.cpp | 4 +- src/spell/script_spell.cpp | 4 +- src/spell/spell_areabombardment.cpp | 4 +- src/spell/spell_capture.cpp | 4 +- src/spell/spell_polymorph.cpp | 4 +- src/spell/spell_spawnmissile.cpp | 6 +- src/spell/spell_spawnportal.cpp | 2 +- src/spell/spell_summon.cpp | 10 +- src/spell/spell_teleport.cpp | 4 +- src/spell/spells.cpp | 26 ++-- src/stratagus/construct.cpp | 12 +- src/stratagus/groups.cpp | 2 +- src/stratagus/iolib.cpp | 6 +- src/stratagus/mainloop.cpp | 2 +- src/stratagus/parameters.cpp | 4 +- src/stratagus/player.cpp | 4 +- src/stratagus/script.cpp | 52 +++---- src/stratagus/selection.cpp | 6 +- src/stratagus/stratagus.cpp | 10 +- src/stratagus/title.cpp | 2 +- src/stratagus/translate.cpp | 2 +- src/stratagus/util.cpp | 18 +-- src/ui/botpanel.cpp | 12 +- src/ui/button_checks.cpp | 12 +- src/ui/contenttype.cpp | 14 +- src/ui/icons.cpp | 6 +- src/ui/interface.cpp | 8 +- src/ui/mainscr.cpp | 2 +- src/ui/mouse.cpp | 56 +++---- src/ui/popup.cpp | 10 +- src/ui/script_ui.cpp | 12 +- src/ui/statusline.cpp | 4 +- src/ui/ui.cpp | 28 ++-- src/ui/widgets.cpp | 104 ++++++------- src/unit/build.cpp | 48 +++--- src/unit/depend.cpp | 14 +- src/unit/script_unit.cpp | 34 ++--- src/unit/script_unittype.cpp | 46 +++--- src/unit/unit.cpp | 140 +++++++++--------- src/unit/unit_draw.cpp | 8 +- src/unit/unit_find.cpp | 32 ++-- src/unit/unit_manager.cpp | 6 +- src/unit/unit_save.cpp | 4 +- src/unit/unitptr.cpp | 2 +- src/unit/unittype.cpp | 26 ++-- src/unit/upgrade.cpp | 2 +- src/video/cursor.cpp | 38 ++--- src/video/font.cpp | 18 +-- src/video/graphic.cpp | 40 ++--- src/video/mng.cpp | 10 +- src/video/movie.cpp | 32 ++-- src/video/png.cpp | 2 +- src/video/sdl.cpp | 24 +-- src/video/shaders.cpp | 12 +- src/video/video.cpp | 8 +- src/win32/SetupConsole_win32.cpp | 2 +- tests/network/test_net_lowlevel.cpp | 10 +- tests/stratagus/test_util.cpp | 14 +- tools/genversion.cpp | 10 +- tools/png2stratagus.cpp | 12 +- 169 files changed, 1131 insertions(+), 1131 deletions(-) diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp index 182519204..cbbf83a8a 100644 --- a/src/action/action_attack.cpp +++ b/src/action/action_attack.cpp @@ -333,8 +333,8 @@ bool COrder_Attack::IsAttackGroundOrWall() const CUnit *const COrder_Attack::BestTarget(const CUnit &unit, CUnit *const target1, CUnit *const target2) const { - Assert(target1 != NULL); - Assert(target2 != NULL); + Assert(target1 != nullptr); + Assert(target2 != nullptr); return (GameSettings.SimplifiedAutoTargeting ? ((TargetPriorityCalculate(&unit, target1) > TargetPriorityCalculate(&unit, target2)) ? target1 : target2) @@ -350,7 +350,7 @@ CUnit *const COrder_Attack::BestTarget(const CUnit &unit, CUnit *const target1, */ void COrder_Attack::OfferNewTarget(const CUnit &unit, CUnit *const target) { - Assert(target != NULL); + Assert(target != nullptr); Assert(this->IsAutoTargeting() || unit.Player->AiEnabled); /// if attacker cant't move (stand_ground, building, in a bunker or transport) @@ -358,10 +358,10 @@ void COrder_Attack::OfferNewTarget(const CUnit &unit, CUnit *const target) if (immobile && !InAttackRange(unit, *target)) { return; } - CUnit *best = (this->offeredTarget != NULL && this->offeredTarget->IsVisibleAsGoal(*unit.Player)) + CUnit *best = (this->offeredTarget != nullptr && this->offeredTarget->IsVisibleAsGoal(*unit.Player)) ? BestTarget(unit, this->offeredTarget, target) : target; - if (this->offeredTarget != NULL) { + if (this->offeredTarget != nullptr) { this->offeredTarget.Reset(); } this->offeredTarget = best; @@ -404,7 +404,7 @@ bool COrder_Attack::CheckIfGoalValid(CUnit &unit) ** Turn unit to Target or position on map for attack. ** ** @param unit Unit to turn. -** @param target Turn to this Target. If NULL then turn to goalPos. +** @param target Turn to this Target. If nullptr then turn to goalPos. ** */ void COrder_Attack::TurnToTarget(CUnit &unit, const CUnit *target) @@ -434,7 +434,7 @@ void COrder_Attack::TurnToTarget(CUnit &unit, const CUnit *target) ** Also if there is no active target Attack-Move action will be saved. ** ** @param unit Attacker. -** @param target Turn to this Target. If NULL then turn to goalPos. +** @param target Turn to this Target. If nullptr then turn to goalPos. ** */ void COrder_Attack::SetAutoTarget(CUnit &unit, CUnit *target) @@ -473,12 +473,12 @@ bool COrder_Attack::AutoSelectTarget(CUnit &unit) // if unit can't attack, or if unit is not bunkered and removed - exit, no targets if (unit.Type->CanAttack == false || (unit.Removed - && (unit.Container == NULL || unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value == false))) { + && (unit.Container == nullptr || unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value == false))) { this->offeredTarget.Reset(); return false; } CUnit *goal = this->GetGoal(); - CUnit *newTarget = NULL; + CUnit *newTarget = nullptr; if (unit.Selected) { DebugPrint("UnderAttack counter: %d \n" _C_ unit.UnderAttack); @@ -492,7 +492,7 @@ bool COrder_Attack::AutoSelectTarget(CUnit &unit) newTarget = AttackUnitsInReactRange(unit); // search for enemies in reaction range } /// If we have target offered from outside - try it - if (this->offeredTarget != NULL) { + if (this->offeredTarget != nullptr) { if (this->offeredTarget->IsVisibleAsGoal(*unit.Player) && (!immobile || InAttackRange(unit, *this->offeredTarget))) { @@ -759,7 +759,7 @@ void COrder_Attack::MoveToTarget(CUnit &unit) && InAttackRange(unit, this->goalPos)) { // Reached wall or ground, now attacking it - TurnToTarget(unit, NULL); + TurnToTarget(unit, nullptr); this->State &= AUTO_TARGETING; this->State |= ATTACK_TARGET; return; diff --git a/src/action/action_board.cpp b/src/action/action_board.cpp index c43e5b4b6..193d59408 100644 --- a/src/action/action_board.cpp +++ b/src/action/action_board.cpp @@ -223,7 +223,7 @@ static void EnterTransporter(CUnit &unit, COrder_Board &order) { CUnit *transporter = order.GetGoal(); - Assert(transporter != NULL); + Assert(transporter != nullptr); if (!transporter->IsVisibleAsGoal(*unit.Player)) { DebugPrint("Transporter gone\n"); diff --git a/src/action/action_build.cpp b/src/action/action_build.cpp index 2e6670b69..a1431b8de 100644 --- a/src/action/action_build.cpp +++ b/src/action/action_build.cpp @@ -100,7 +100,7 @@ enum { file.printf(" \"range\", %d,", this->Range); file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y); - if (this->BuildingUnit != NULL) { + if (this->BuildingUnit != nullptr) { file.printf(" \"building\", \"%s\",", UnitReference(this->BuildingUnit).c_str()); } file.printf(" \"type\", \"%s\",", this->Type->Ident.c_str()); @@ -172,7 +172,7 @@ void COrder_Build::AiUnitKilled(CUnit &unit) DebugPrint("%d: %d(%s) killed, with order %s!\n" _C_ unit.Player->Index _C_ UnitNumber(unit) _C_ unit.Type->Ident.c_str() _C_ this->Type->Ident.c_str()); - if (this->BuildingUnit == NULL) { + if (this->BuildingUnit == nullptr) { AiReduceMadeInBuilt(*unit.Player->Ai, *this->Type); } } @@ -276,7 +276,7 @@ CUnit *COrder_Build::CheckCanBuild(CUnit &unit) CUnit *ontop = CanBuildUnitType(&unit, type, pos, 1); - if (ontop != NULL) { + if (ontop != nullptr) { return ontop; } #if 0 @@ -285,7 +285,7 @@ CUnit *COrder_Build::CheckCanBuild(CUnit &unit) * enabled/disable via game lua scripting */ CUnit *building = AlreadyBuildingFinder(unit, type).Find(Map.Field(pos)); - if (building != NULL) { + if (building != nullptr) { if (unit.CurrentOrder() == this) { DebugPrint("%d: Worker [%d] is helping build: %s [%d]\n" _C_ unit.Player->Index _C_ unit.Slot @@ -294,7 +294,7 @@ CUnit *COrder_Build::CheckCanBuild(CUnit &unit) delete this; // Bad unit.Orders[0] = COrder::NewActionRepair(unit, *building); - return NULL; + return nullptr; } } #endif @@ -303,7 +303,7 @@ CUnit *COrder_Build::CheckCanBuild(CUnit &unit) // To keep the load low, retry each 10 cycles // NOTE: we can already inform the AI about this problem? unit.Wait = 10; - return NULL; + return nullptr; } @@ -316,7 +316,7 @@ bool COrder_Build::StartBuilding(CUnit &unit, CUnit &ontop) CUnit *build = MakeUnit(const_cast(type), unit.Player); // If unable to make unit, stop, and report message - if (build == NULL) { + if (build == nullptr) { // FIXME: Should we retry this? unit.Player->Notify(NotifyYellow, unit.tilePos, _("Unable to create building %s"), type.Name.c_str()); @@ -339,7 +339,7 @@ bool COrder_Build::StartBuilding(CUnit &unit, CUnit &ontop) build->Variable[GIVERESOURCE_INDEX].Value = ontop.Variable[GIVERESOURCE_INDEX].Value; build->Variable[GIVERESOURCE_INDEX].Max = ontop.Variable[GIVERESOURCE_INDEX].Max; build->Variable[GIVERESOURCE_INDEX].Enable = ontop.Variable[GIVERESOURCE_INDEX].Enable; - ontop.Remove(NULL); // Destroy building beneath + ontop.Remove(nullptr); // Destroy building beneath UnitLost(ontop); UnitClearOrders(ontop); ontop.Release(); @@ -394,7 +394,7 @@ static void AnimateActionBuild(CUnit &unit) { CAnimations *animations = unit.Type->Animations; - if (animations == NULL) { + if (animations == nullptr) { return ; } if (animations->Build) { @@ -414,7 +414,7 @@ bool COrder_Build::BuildFromOutside(CUnit &unit) const { AnimateActionBuild(unit); - if (this->BuildingUnit == NULL) { + if (this->BuildingUnit == nullptr) { return false; } @@ -437,7 +437,7 @@ CUnit *COrder_Build::GetBuildingUnit() const /* virtual */ void COrder_Build::UpdateUnitVariables(CUnit &unit) const { - if (this->State == State_BuildFromOutside && this->BuildingUnit != NULL) { + if (this->State == State_BuildFromOutside && this->BuildingUnit != nullptr) { unit.Variable[TRAINING_INDEX].Value = this->BuildingUnit->Variable[BUILD_INDEX].Value; unit.Variable[TRAINING_INDEX].Max = this->BuildingUnit->Variable[BUILD_INDEX].Max; } @@ -464,7 +464,7 @@ CUnit *COrder_Build::GetBuildingUnit() const } CUnit *ontop = this->CheckCanBuild(unit); - if (ontop != NULL) { + if (ontop != nullptr) { this->StartBuilding(unit, *ontop); } } @@ -486,7 +486,7 @@ CUnit *COrder_Build::GetBuildingUnit() const /* virtual */ void COrder_Build::Cancel(CUnit &unit) { - if (this->State == State_BuildFromOutside && this->BuildingUnit != NULL && this->BuildingUnit->CurrentAction() == UnitActionBuilt) { + if (this->State == State_BuildFromOutside && this->BuildingUnit != nullptr && this->BuildingUnit->CurrentAction() == UnitActionBuilt) { COrder_Built &targetOrder = *static_cast(this->BuildingUnit->CurrentOrder()); targetOrder.Cancel(*this->BuildingUnit); } diff --git a/src/action/action_built.cpp b/src/action/action_built.cpp index af5d1c2c0..16dbdebfa 100644 --- a/src/action/action_built.cpp +++ b/src/action/action_built.cpp @@ -83,7 +83,7 @@ extern void AiReduceMadeInBuilt(PlayerAi &pai, const CUnitType &type); cframe = cframe->Next; ++frame; } - if (this->Worker != NULL) { + if (this->Worker != nullptr) { file.printf("\"worker\", \"%s\", ", UnitReference(this->Worker).c_str()); } file.printf("\"progress\", %d, \"frame\", %d", this->ProgressCounter, frame); @@ -109,7 +109,7 @@ extern void AiReduceMadeInBuilt(PlayerAi &pai, const CUnitType &type); ++j; int frame = LuaToNumber(l, -1, j + 1); CConstructionFrame *cframe = unit.Type->Construction->Frames; - while (frame-- && cframe->Next != NULL) { + while (frame-- && cframe->Next != nullptr) { cframe = cframe->Next; } this->Frame = cframe; @@ -132,16 +132,16 @@ extern void AiReduceMadeInBuilt(PlayerAi &pai, const CUnitType &type); static void CancelBuilt(COrder_Built &order, CUnit *unit) { - Assert(unit == NULL || unit->CurrentOrder() == &order); + Assert(unit == nullptr || unit->CurrentOrder() == &order); CUnit *worker = order.GetWorkerPtr(); // Drop out unit - if (worker != NULL && worker->CurrentAction() == UnitActionBuild) { + if (worker != nullptr && worker->CurrentAction() == UnitActionBuild) { worker->ClearAction(); DropOutOnSide(*worker, LookingW, unit); } - if (unit != NULL) { + if (unit != nullptr) { // Player gets back 75% of the original cost for a building. unit->Player->AddCostsFactor(unit->Stats->Costs, CancelBuildingCostsFactor); // Cancel building @@ -169,11 +169,11 @@ static void Finish(COrder_Built &order, CUnit &unit) } CUnit *worker = order.GetWorkerPtr(); - if (worker != NULL) { + if (worker != nullptr) { if (type.BoolFlag[BUILDERLOST_INDEX].value) { // Bye bye worker. LetUnitDie(*worker); - worker = NULL; + worker = nullptr; } else { // Drop out the worker. worker->ClearAction(); @@ -207,7 +207,7 @@ static void Finish(COrder_Built &order, CUnit &unit) } if (player.AiEnabled) { - /* Worker can be NULL */ + /* Worker can be nullptr */ AiWorkComplete(worker, unit); } @@ -222,7 +222,7 @@ static void Finish(COrder_Built &order, CUnit &unit) // FIXME: Johns: hardcoded unit-type wall / more races! if (&type == UnitTypeOrcWall || &type == UnitTypeHumanWall) { Map.SetWall(unit.tilePos, &type == UnitTypeHumanWall); - unit.Remove(NULL); + unit.Remove(nullptr); UnitLost(unit); UnitClearOrders(unit); unit.Release(); @@ -253,7 +253,7 @@ static void Finish(COrder_Built &order, CUnit &unit) COrder_Built::~COrder_Built() { - CancelBuilt(*this, NULL); + CancelBuilt(*this, nullptr); } /* virtual */ void COrder_Built::Execute(CUnit &unit) @@ -351,7 +351,7 @@ void COrder_Built::UpdateConstructionFrame(CUnit &unit) const int percent = this->ProgressCounter / (type.Stats[unit.Player->Index].Costs[TimeCost] * 6); const CConstructionFrame *cframe = FindCFramePercent(*type.Construction->Frames, percent); - Assert(cframe != NULL); + Assert(cframe != nullptr); if (cframe != this->Frame) { this->Frame = cframe; diff --git a/src/action/action_defend.cpp b/src/action/action_defend.cpp index ccdf9e212..94fbfbed9 100644 --- a/src/action/action_defend.cpp +++ b/src/action/action_defend.cpp @@ -197,7 +197,7 @@ enum { DebugPrint("Goal gone\n"); this->goalPos = goal->tilePos + goal->Type->GetHalfTileSize(); this->ClearGoal(); - goal = NULL; + goal = nullptr; if (this->State == State_Defending) { this->Finished = true; return; diff --git a/src/action/action_die.cpp b/src/action/action_die.cpp index b20be6d3c..45bbba3a7 100644 --- a/src/action/action_die.cpp +++ b/src/action/action_die.cpp @@ -80,7 +80,7 @@ static bool AnimateActionDie(CUnit &unit) { const CAnimations *animations = unit.Type->Animations; - if (animations == NULL) { + if (animations == nullptr) { return false; } if (animations->Death[unit.DamagedType]) { @@ -107,8 +107,8 @@ static bool AnimateActionDie(CUnit &unit) const CUnitType &type = *unit.Type; // Die sequence terminated, generate corpse. - if (type.CorpseType == NULL) { - unit.Remove(NULL); + if (type.CorpseType == nullptr) { + unit.Remove(nullptr); unit.Release(); return ; } @@ -120,7 +120,7 @@ static bool AnimateActionDie(CUnit &unit) // We have to unmark BEFORE changing the type. // Always do that, since types can have different vision properties. - unit.Remove(NULL); + unit.Remove(nullptr); unit.Type = &corpseType; unit.Stats = &corpseType.Stats[unit.Player->Index]; UpdateUnitSightRange(unit); diff --git a/src/action/action_follow.cpp b/src/action/action_follow.cpp index 7e1e68617..565932b15 100644 --- a/src/action/action_follow.cpp +++ b/src/action/action_follow.cpp @@ -222,7 +222,7 @@ enum { goal->Variable[MANA_INDEX].Value -= goal->Goal->Type->TeleportCost; } // Everything is OK, now teleport the unit - unit.Remove(NULL); + unit.Remove(nullptr); if (goal->Type->TeleportEffectIn) { goal->Type->TeleportEffectIn->pushPreamble(); goal->Type->TeleportEffectIn->pushInteger(UnitNumber(unit)); @@ -232,7 +232,7 @@ enum { goal->Type->TeleportEffectIn->run(); } unit.tilePos = goal->Goal->tilePos; - DropOutOnSide(unit, unit.Direction, NULL); + DropOutOnSide(unit, unit.Direction, nullptr); // FIXME: we must check if the units supports the new order. CUnit &dest = *goal->Goal; @@ -245,7 +245,7 @@ enum { dest.Type->TeleportEffectOut->run(); } - if (dest.NewOrder == NULL + if (dest.NewOrder == nullptr || (dest.NewOrder->Action == UnitActionResource && !unit.Type->BoolFlag[HARVESTER_INDEX].value) || (dest.NewOrder->Action == UnitActionAttack && !unit.Type->CanAttack) || (dest.NewOrder->Action == UnitActionBoard && unit.Type->UnitType != UnitTypeLand)) { @@ -255,7 +255,7 @@ enum { if (dest.NewOrder->HasGoal()) { if (dest.NewOrder->GetGoal()->Destroyed) { delete dest.NewOrder; - dest.NewOrder = NULL; + dest.NewOrder = nullptr; this->Finished = true; return ; } @@ -278,7 +278,7 @@ enum { DebugPrint("Goal gone\n"); this->goalPos = goal->tilePos + goal->Type->GetHalfTileSize(); this->ClearGoal(); - goal = NULL; + goal = nullptr; } if (unit.Anim.Unbreakable) { @@ -293,7 +293,7 @@ enum { CUnit *target = AttackUnitsInReactRange(unit); if (target) { // Save current command to come back. - COrder *savedOrder = NULL; + COrder *savedOrder = nullptr; if (unit.CanStoreOrder(unit.CurrentOrder())) { savedOrder = this->Clone(); } @@ -301,7 +301,7 @@ enum { this->Finished = true; unit.Orders.insert(unit.Orders.begin() + 1, COrder::NewActionAttack(unit, target->tilePos)); - if (savedOrder != NULL) { + if (savedOrder != nullptr) { unit.SavedOrder = savedOrder; } } diff --git a/src/action/action_repair.cpp b/src/action/action_repair.cpp index 5cc462085..4530f6e92 100644 --- a/src/action/action_repair.cpp +++ b/src/action/action_repair.cpp @@ -90,7 +90,7 @@ } file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y); - if (this->ReparableTarget != NULL) { + if (this->ReparableTarget != nullptr) { file.printf(" \"repair-target\", \"%s\",", UnitReference(this->GetReparableTarget()).c_str()); } @@ -133,7 +133,7 @@ { PixelPos targetPos; - if (this->ReparableTarget != NULL) { + if (this->ReparableTarget != nullptr) { targetPos = vp.MapToScreenPixelPos(this->ReparableTarget->GetMapPixelPosCenter()); } else { targetPos = vp.TilePosToScreen_Center(this->goalPos); @@ -149,10 +149,10 @@ const CUnit &unit = *input.GetUnit(); input.SetMinRange(0); - input.SetMaxRange(ReparableTarget != NULL ? unit.Type->RepairRange : 0); + input.SetMaxRange(ReparableTarget != nullptr ? unit.Type->RepairRange : 0); Vec2i tileSize; - if (ReparableTarget != NULL) { + if (ReparableTarget != nullptr) { tileSize.x = ReparableTarget->Type->TileWidth; tileSize.y = ReparableTarget->Type->TileHeight; input.SetGoal(ReparableTarget->tilePos, tileSize); @@ -255,9 +255,9 @@ static void AnimateActionRepair(CUnit &unit) if (!goal->IsVisibleAsGoal(*unit.Player)) { DebugPrint("repair target gone.\n"); this->goalPos = goal->tilePos + goal->Type->GetHalfTileSize(); - ReparableTarget = NULL; + ReparableTarget = nullptr; this->ClearGoal(); - goal = NULL; + goal = nullptr; } } else if (unit.Player->AiEnabled) { // Ai players workers should stop if target is killed @@ -292,8 +292,8 @@ static void AnimateActionRepair(CUnit &unit) this->goalPos = goal->tilePos + goal->Type->GetHalfTileSize(); // FIXME: should I clear this here? this->ClearGoal(); - ReparableTarget = NULL; - goal = NULL; + ReparableTarget = nullptr; + goal = nullptr; } else { const int dist = unit.MapDistanceTo(*goal); diff --git a/src/action/action_resource.cpp b/src/action/action_resource.cpp index 3519247d9..4de159a29 100644 --- a/src/action/action_resource.cpp +++ b/src/action/action_resource.cpp @@ -176,16 +176,16 @@ static bool FindNearestReachableTerrainType(int movemask, int resmask, int range // Destination could be killed. NETWORK! if (depot && depot->Destroyed) { - depot = NULL; + depot = nullptr; } // clicking on an allied depot still doesn't allow you to deposit there depending on preference if (depot && !GameSettings.AllyDepositsAllowed && depot->Player != harvester.Player) { - depot = NULL; + depot = nullptr; } order->CurrentResource = harvester.CurrentResource; order->DoneHarvesting = true; - if (depot == NULL) { + if (depot == nullptr) { depot = FindDeposit(harvester, 1000, harvester.CurrentResource); } if (depot) { @@ -201,7 +201,7 @@ static bool FindNearestReachableTerrainType(int movemask, int resmask, int range Vec2i COrder_Resource::GetHarvestLocation() const { - if (this->Resource.Mine != NULL) { + if (this->Resource.Mine != nullptr) { return this->Resource.Mine->tilePos; } else { return this->Resource.Pos; @@ -226,12 +226,12 @@ bool COrder_Resource::IsGatheringWaiting() const COrder_Resource::~COrder_Resource() { CUnit *mine = this->Resource.Mine; - this->Resource.Mine = NULL; + this->Resource.Mine = nullptr; if (mine && mine->IsAlive()) { worker->DeAssignWorkerFromMine(*mine); } - Depot = NULL; + Depot = nullptr; CUnit *goal = this->GetGoal(); if (goal) { @@ -255,15 +255,15 @@ COrder_Resource::~COrder_Resource() } file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y); - Assert(this->worker != NULL && worker->IsAlive()); + Assert(this->worker != nullptr && worker->IsAlive()); file.printf(" \"worker\", \"%s\",", UnitReference(worker).c_str()); file.printf(" \"current-res\", %d,", this->CurrentResource); file.printf(" \"res-pos\", {%d, %d},", this->Resource.Pos.x, this->Resource.Pos.y); - if (this->Resource.Mine != NULL) { + if (this->Resource.Mine != nullptr) { file.printf(" \"res-mine\", \"%s\",", UnitReference(this->Resource.Mine).c_str()); } - if (this->Depot != NULL) { + if (this->Depot != nullptr) { file.printf(" \"res-depot\", \"%s\",", UnitReference(this->Depot).c_str()); } if (this->DoneHarvesting) { @@ -702,7 +702,7 @@ int COrder_Resource::GatherResource(CUnit &unit) if (resinfo.HarvestFromOutside || resinfo.TerrainHarvester) { AnimateActionHarvest(unit); } else { - unit.Anim.CurrAnim = NULL; + unit.Anim.CurrAnim = nullptr; } this->TimeToHarvest--; @@ -806,11 +806,11 @@ int COrder_Resource::GatherResource(CUnit &unit) LetUnitDie(*source); // FIXME: make the workers inside look for a new resource. } - source = NULL; + source = nullptr; return 0; } if (resinfo.HarvestFromOutside) { - if ((unit.ResourcesHeld == resinfo.ResourceCapacity) || (source == NULL)) { + if ((unit.ResourcesHeld == resinfo.ResourceCapacity) || (source == nullptr)) { // Mark as complete. this->DoneHarvesting = true; } @@ -828,7 +828,7 @@ int GetNumWaitingWorkers(const CUnit &mine) int ret = 0; CUnit *worker = mine.Resource.Workers; - for (int i = 0; NULL != worker; worker = worker->NextWorker, ++i) { + for (int i = 0; nullptr != worker; worker = worker->NextWorker, ++i) { Assert(worker->CurrentAction() == UnitActionResource); COrder_Resource &order = *static_cast(worker->CurrentOrder()); @@ -876,8 +876,8 @@ int COrder_Resource::StopGathering(CUnit &unit) if (source->Type->MaxOnBoard) { int count = 0; CUnit *worker = source->Resource.Workers; - CUnit *next = NULL; - for (; NULL != worker; worker = worker->NextWorker) { + CUnit *next = nullptr; + for (; nullptr != worker; worker = worker->NextWorker) { Assert(worker->CurrentAction() == UnitActionResource); COrder_Resource &order = *static_cast(worker->CurrentOrder()); if (worker != &unit && order.IsGatheringWaiting()) { @@ -908,7 +908,7 @@ int COrder_Resource::StopGathering(CUnit &unit) } else { // Store resource position. this->Resource.Pos = unit.tilePos; - Assert(this->Resource.Mine == NULL); + Assert(this->Resource.Mine == nullptr); } #ifdef DEBUG @@ -937,7 +937,7 @@ int COrder_Resource::StopGathering(CUnit &unit) if (mine) { unit.DeAssignWorkerFromMine(*mine); - this->Resource.Mine = NULL; + this->Resource.Mine = nullptr; } DebugPrint("%d: Worker %d report: Can't find a resource [%d] deposit.\n" @@ -1037,7 +1037,7 @@ int COrder_Resource::MoveToDepot(CUnit &unit) SelectionChanged(); unit.Removed = 1; } - unit.Anim.CurrAnim = NULL; + unit.Anim.CurrAnim = nullptr; } // Update resource. @@ -1101,14 +1101,14 @@ bool COrder_Resource::WaitInDepot(CUnit &unit) // Use depot's ref counter for that if (longWay || !mine || (depot->Refs > tooManyWorkers)) { newdepot = AiGetSuitableDepot(unit, *depot, &goal); - if (newdepot == NULL && longWay) { + if (newdepot == nullptr && longWay) { // We need a new depot AiNewDepotRequest(unit); } } } - // If goal is not NULL, then we got it in AiGetSuitableDepot + // If goal is not nullptr, then we got it in AiGetSuitableDepot if (!goal) { if (mine != nullptr && mine->IsAlive()) { goal = mine; @@ -1153,7 +1153,7 @@ bool COrder_Resource::WaitInDepot(CUnit &unit) } if (mine) { unit.DeAssignWorkerFromMine(*mine); - this->Resource.Mine = NULL; + this->Resource.Mine = nullptr; } this->Finished = true; return false; @@ -1174,7 +1174,7 @@ void COrder_Resource::DropResource(CUnit &unit) } } //fast clean both resource data: pos and mine - this->Resource.Mine = NULL; + this->Resource.Mine = nullptr; unit.CurrentResource = 0; unit.ResourcesHeld = 0; } @@ -1252,7 +1252,7 @@ bool COrder_Resource::ActionResourceInit(CUnit &unit) if (mine) { unit.DeAssignWorkerFromMine(*mine); - this->Resource.Mine = NULL; + this->Resource.Mine = nullptr; } if (goal && goal->IsAlive() == false) { return false; diff --git a/src/action/action_still.cpp b/src/action/action_still.cpp index be969a423..747795ef6 100644 --- a/src/action/action_still.cpp +++ b/src/action/action_still.cpp @@ -134,7 +134,7 @@ private: /* virtual */ void COrder_Still::OnAnimationAttack(CUnit &unit) { CUnit *goal = this->GetGoal(); - if (goal == NULL) { + if (goal == nullptr) { return; } if (IsTargetInRange(unit)(goal) == false) { @@ -262,7 +262,7 @@ private: ** @param unit unit which can repair. ** @param range range to find a repairable unit. ** -** @return unit to repair if found, NULL otherwise +** @return unit to repair if found, nullptr otherwise ** ** @todo FIXME: find the best unit (most damaged, ...). */ @@ -287,18 +287,18 @@ bool AutoRepair(CUnit &unit) } CUnit *repairedUnit = UnitToRepairInRange(unit, repairRange); - if (repairedUnit == NULL) { + if (repairedUnit == nullptr) { return false; } const Vec2i invalidPos(-1, -1); - COrder *savedOrder = NULL; + COrder *savedOrder = nullptr; if (unit.CanStoreOrder(unit.CurrentOrder())) { savedOrder = unit.CurrentOrder()->Clone(); } //Command* will clear unit.SavedOrder CommandRepair(unit, invalidPos, repairedUnit, FlushCommands); - if (savedOrder != NULL) { + if (savedOrder != nullptr) { unit.SavedOrder = savedOrder; } return true; @@ -314,7 +314,7 @@ bool COrder_Still::AutoAttackStand(CUnit &unit) // Removed units can only attack in AttackRange, from bunker CUnit *autoAttackUnit = AttackUnitsInRange(unit); - if (autoAttackUnit == NULL) { + if (autoAttackUnit == nullptr) { return false; } @@ -364,10 +364,10 @@ bool AutoAttack(CUnit &unit) // Normal units react in reaction range. CUnit *goal = AttackUnitsInReactRange(unit); - if (goal == NULL) { + if (goal == nullptr) { return false; } - COrder *savedOrder = NULL; + COrder *savedOrder = nullptr; if (unit.CurrentAction() == UnitActionStill) { savedOrder = COrder::NewActionAttack(unit, unit.tilePos); @@ -375,9 +375,9 @@ bool AutoAttack(CUnit &unit) savedOrder = unit.CurrentOrder()->Clone(); } // Weak goal, can choose other unit, come back after attack - CommandAttack(unit, goal->tilePos, NULL, FlushCommands); + CommandAttack(unit, goal->tilePos, nullptr, FlushCommands); - if (savedOrder != NULL) { + if (savedOrder != nullptr) { unit.SavedOrder = savedOrder; } return true; @@ -388,7 +388,7 @@ bool AutoAttack(CUnit &unit) { // If unit is not bunkered and removed, wait if (unit.Removed - && (unit.Container == NULL || unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value == false)) { + && (unit.Container == nullptr || unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value == false)) { return ; } this->Finished = false; diff --git a/src/action/action_train.cpp b/src/action/action_train.cpp index 90fd7c932..47b55d5f5 100644 --- a/src/action/action_train.cpp +++ b/src/action/action_train.cpp @@ -141,7 +141,7 @@ void COrder_Train::ConvertUnitType(const CUnit &unit, CUnitType &newType) */ static bool CanHandleOrder(const CUnit &unit, COrder *order) { - if (order == NULL) { + if (order == nullptr) { return false; } if (order->Action == UnitActionResource) { @@ -204,7 +204,7 @@ static void AnimateActionTrain(CUnit &unit) CUnit *newUnit = MakeUnit(nType, &player); - if (newUnit == NULL) { // No more memory :/ + if (newUnit == nullptr) { // No more memory :/ player.Notify(NotifyYellow, unit.tilePos, _("Unable to train %s"), nType.Name.c_str()); unit.Wait = CYCLES_PER_SECOND / 6; return ; @@ -249,7 +249,7 @@ static void AnimateActionTrain(CUnit &unit) if (unit.NewOrder && unit.NewOrder->HasGoal() && unit.NewOrder->GetGoal()->Destroyed) { delete unit.NewOrder; - unit.NewOrder = NULL; + unit.NewOrder = nullptr; } if (CanHandleOrder(*newUnit, unit.NewOrder) == true) { diff --git a/src/action/action_unload.cpp b/src/action/action_unload.cpp index df2589756..d3847bfe8 100644 --- a/src/action/action_unload.cpp +++ b/src/action/action_unload.cpp @@ -316,7 +316,7 @@ static int ClosestFreeDropZone(CUnit &transporter, const Vec2i &startPos, int ma if (!isTransporterRemoved) { // Remove transporter to avoid "collision" with itself. - transporter.Remove(NULL); + transporter.Remove(nullptr); } const bool res = ClosestFreeDropZone_internal(transporter, startPos, maxRange, resPos); if (!isTransporterRemoved) { @@ -339,7 +339,7 @@ bool COrder_Unload::LeaveTransporter(CUnit &transporter) int stillonboard = 0; // Goal is the specific unit unit that you want to unload. - // This can be NULL, in case you want to unload everything. + // This can be nullptr, in case you want to unload everything. if (this->HasGoal()) { CUnit &goal = *this->GetGoal(); diff --git a/src/action/action_upgradeto.cpp b/src/action/action_upgradeto.cpp index 8a2b200b3..3155d8f7e 100644 --- a/src/action/action_upgradeto.cpp +++ b/src/action/action_upgradeto.cpp @@ -108,7 +108,7 @@ static int TransformUnitIntoType(CUnit &unit, const CUnitType &newtype) // by removing the unit and looking at the map fields removed = true; SaveSelection(); - unit.Remove(NULL); + unit.Remove(nullptr); if (!UnitTypeCanBeAt(newtype, pos)) { unit.Place(unit.tilePos); RestoreSelection(); diff --git a/src/action/actions.cpp b/src/action/actions.cpp index 4e5b70d0d..16112d234 100644 --- a/src/action/actions.cpp +++ b/src/action/actions.cpp @@ -151,7 +151,7 @@ void COrder::UpdatePathFinderData_NotCalled(PathFinderInput &input) if (unit.CurrentAction() == UnitActionDie) { unit.Seen.State = 3; } - unit.Seen.CFrame = NULL; + unit.Seen.CFrame = nullptr; } /* virtual */ bool COrder::OnAiHitUnit(CUnit &unit, CUnit *attacker, int /*damage*/) @@ -188,7 +188,7 @@ void COrder::UpdatePathFinderData_NotCalled(PathFinderInput &input) } CUnit *goal = AttackUnitsInRange(unit); - if (goal != NULL) { + if (goal != nullptr) { const Vec2i invalidPos(-1, -1); FireMissile(unit, goal, invalidPos); @@ -399,10 +399,10 @@ static void HandleUnitAction(CUnit &unit) { // If current action is breakable proceed with next one. if (!unit.Anim.Unbreakable) { - if (unit.CriticalOrder != NULL) { + if (unit.CriticalOrder != nullptr) { unit.CriticalOrder->Execute(unit); delete unit.CriticalOrder; - unit.CriticalOrder = NULL; + unit.CriticalOrder = nullptr; } if (unit.Orders[0]->Finished && unit.Orders[0]->Action != UnitActionStill @@ -424,7 +424,7 @@ static void HandleUnitAction(CUnit &unit) // timfel: I observed this exactly once and could never reproduce it, so I don't know why this // can happen, but in case it happens again, bring the unit back DebugPrint("Dropping out stuck unit\n"); - DropOutOnSide(unit, LookingW, NULL); + DropOutOnSide(unit, LookingW, nullptr); } else { DebugPrint("Flushing removed unit\n"); // This happens, if building with ALT+SHIFT. @@ -480,7 +480,7 @@ static void UnitActionsEachSecond(UNITP_ITERATOR begin, UNITP_ITERATOR end) static void DumpUnitInfo(CUnit &unit) { // Dump the unit to find the network sync bugs. - static FILE *logf = NULL; + static FILE *logf = nullptr; if (!logf) { time_t now; @@ -549,7 +549,7 @@ static void DumpUnitInfo(CUnit &unit) #if 0 SaveUnit(unit, logf); #endif - fflush(NULL); + fflush(nullptr); } template diff --git a/src/action/command.cpp b/src/action/command.cpp index b27212e24..f2c7d432c 100644 --- a/src/action/command.cpp +++ b/src/action/command.cpp @@ -105,9 +105,9 @@ static COrderPtr *GetNextOrder(CUnit &unit, int flush) const unsigned int maxOrderCount = 0x7F; if (unit.Orders.size() == maxOrderCount) { - return NULL; + return nullptr; } - unit.Orders.push_back(NULL); + unit.Orders.push_back(nullptr); return &unit.Orders.back(); } @@ -131,7 +131,7 @@ static void RemoveOrder(CUnit &unit, unsigned int order) static void ClearNewAction(CUnit &unit) { delete unit.NewOrder; - unit.NewOrder = NULL; + unit.NewOrder = nullptr; } /** @@ -145,7 +145,7 @@ static void ClearNewAction(CUnit &unit) static void ClearSavedAction(CUnit &unit) { delete unit.SavedOrder; - unit.SavedOrder = NULL; + unit.SavedOrder = nullptr; } static bool IsUnitValidForNetwork(const CUnit &unit) @@ -168,7 +168,7 @@ void CommandStopUnit(CUnit &unit) // Ignore that the unit could be removed. COrderPtr *order = GetNextOrder(unit, FlushCommands); // Flush them. Assert(order); - Assert(*order == NULL); + Assert(*order == nullptr); *order = COrder::NewActionStill(); ClearSavedAction(unit); @@ -190,7 +190,7 @@ void CommandStandGround(CUnit &unit, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -217,7 +217,7 @@ void CommandDefend(CUnit &unit, CUnit &dest, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -244,7 +244,7 @@ void CommandFollow(CUnit &unit, CUnit &dest, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -273,7 +273,7 @@ void CommandMove(CUnit &unit, const Vec2i &pos, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -301,7 +301,7 @@ void CommandRepair(CUnit &unit, const Vec2i &pos, CUnit *dest, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -349,7 +349,7 @@ void CommandAttack(CUnit &unit, const Vec2i &pos, CUnit *target, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -382,7 +382,7 @@ void CommandAttackGround(CUnit &unit, const Vec2i &pos, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -412,7 +412,7 @@ void CommandPatrolUnit(CUnit &unit, const Vec2i &pos, int flush) Vec2i startPos = unit.tilePos; COrderPtr *prevOrder = &unit.Orders.back(); - if(*prevOrder != NULL) { + if(*prevOrder != nullptr) { Vec2i prevGoalPos = (*prevOrder)->GetGoalPos(); if(prevGoalPos != invalidPos) { startPos = prevGoalPos; @@ -426,7 +426,7 @@ void CommandPatrolUnit(CUnit &unit, const Vec2i &pos, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -457,7 +457,7 @@ void CommandBoard(CUnit &unit, CUnit &dest, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -470,7 +470,7 @@ void CommandBoard(CUnit &unit, CUnit &dest, int flush) ** ** @param unit pointer to unit. ** @param pos map position to unload. -** @param what unit to be unloaded, NULL for all. +** @param what unit to be unloaded, nullptr for all. ** @param flush if true, flush command queue. */ void CommandUnload(CUnit &unit, const Vec2i &pos, CUnit *what, int flush) @@ -480,7 +480,7 @@ void CommandUnload(CUnit &unit, const Vec2i &pos, CUnit *what, int flush) } COrderPtr *order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } *order = COrder::NewActionUnload(pos, what); @@ -507,7 +507,7 @@ void CommandBuildBuilding(CUnit &unit, const Vec2i &pos, CUnitType &what, int fl order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -533,7 +533,7 @@ void CommandExplore(CUnit &unit, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -582,7 +582,7 @@ void CommandResourceLoc(CUnit &unit, const Vec2i &pos, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -616,7 +616,7 @@ void CommandResource(CUnit &unit, CUnit &dest, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -648,7 +648,7 @@ void CommandReturnGoods(CUnit &unit, CUnit *depot, int flush) order = &unit.NewOrder; } else { order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } } @@ -683,7 +683,7 @@ void CommandTrainUnit(CUnit &unit, CUnitType &type, int) const int noFlushCommands = 0; COrderPtr *order = GetNextOrder(unit, noFlushCommands); - if (order == NULL) { + if (order == nullptr) { return; } *order = COrder::NewActionTrain(unit, type); @@ -757,7 +757,7 @@ void CommandUpgradeTo(CUnit &unit, CUnitType &type, int flush, bool instant) COrderPtr *order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } *order = COrder::NewActionUpgradeTo(unit, type, instant); @@ -775,7 +775,7 @@ void CommandTransformIntoType(CUnit &unit, CUnitType &type) if (unit.CriticalOrder && unit.CriticalOrder->Action == UnitActionTransformInto) { return; } - Assert(unit.CriticalOrder == NULL); + Assert(unit.CriticalOrder == nullptr); unit.CriticalOrder = COrder::NewActionTransformInto(type); } @@ -815,7 +815,7 @@ void CommandResearch(CUnit &unit, CUpgrade &what, int flush) return; } COrderPtr *order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } *order = COrder::NewActionResearch(unit, what); @@ -861,7 +861,7 @@ void CommandSpellCast(CUnit &unit, const Vec2i &pos, CUnit *dest, const SpellTyp } COrderPtr *order = GetNextOrder(unit, flush); - if (order == NULL) { + if (order == nullptr) { return; } diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index fea87d343..34c2cc6fb 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -446,7 +446,7 @@ void AiInit(CPlayer &player) Exit(0); } size_t i; - CAiType *ait = NULL; + CAiType *ait = nullptr; for (i = 0; i < AiTypes.size(); ++i) { ait = AiTypes[i]; @@ -495,7 +495,7 @@ void CleanAi() { for (int p = 0; p < PlayerMax; ++p) { delete Players[p].Ai; - Players[p].Ai = NULL; + Players[p].Ai = nullptr; } } @@ -688,7 +688,7 @@ void AiHelpMe(const CUnit *attacker, CUnit &defender) const COrder_Attack &orderAttack = *static_cast(aiunit.CurrentOrder()); const CUnit *oldGoal = orderAttack.GetGoal(); - if (oldGoal == NULL || (ThreatCalculate(defender, *attacker) < ThreatCalculate(defender, *oldGoal) + if (oldGoal == nullptr || (ThreatCalculate(defender, *attacker) < ThreatCalculate(defender, *oldGoal) && aiunit.MapDistanceTo(defender) <= aiunit.Stats->Variables[ATTACKRANGE_INDEX].Max)) { shouldAttack = true; } @@ -700,7 +700,7 @@ void AiHelpMe(const CUnit *attacker, CUnit &defender) if (aiunit.CanStoreOrder(savedOrder) == false) { delete savedOrder; - savedOrder = NULL; + savedOrder = nullptr; } else { aiunit.SavedOrder = savedOrder; } @@ -899,14 +899,14 @@ static void AiMoveUnitInTheWay(CUnit &unit) // Don't move more than 1 unit. if (movablenb) { const int index = SyncRand() % movablenb; - COrder *savedOrder = NULL; + COrder *savedOrder = nullptr; if (movableunits[index]->IsIdle() == false) { if (unit.CanStoreOrder(unit.CurrentOrder())) { savedOrder = unit.CurrentOrder()->Clone(); } } CommandMove(*movableunits[index], movablepos[index], FlushCommands); - if (savedOrder != NULL) { + if (savedOrder != nullptr) { unit.SavedOrder = savedOrder; } AiPlayer->LastCanNotMoveGameCycle = GameCycle; diff --git a/src/ai/ai_building.cpp b/src/ai/ai_building.cpp index 51efa4e86..0f48ad2c0 100644 --- a/src/ai/ai_building.cpp +++ b/src/ai/ai_building.cpp @@ -172,7 +172,7 @@ VisitResult BuildingPlaceFinder::Visit(TerrainTraversal &terrainTraversal, const } #endif if (CanBuildUnitType(&worker, type, pos, 1) - && !AiEnemyUnitsInDistance(*worker.Player, NULL, pos, 8)) { + && !AiEnemyUnitsInDistance(*worker.Player, nullptr, pos, 8)) { bool backupok; if (AiCheckSurrounding(worker, type, pos, backupok) && checkSurround) { *resultPos = pos; @@ -207,7 +207,7 @@ static bool AiFindBuildingPlace2(const CUnit &worker, const CUnitType &type, con terrainTraversal.SetSize(Map.Info.MapWidth, Map.Info.MapHeight); terrainTraversal.Init(); - if (startUnit != NULL) { + if (startUnit != nullptr) { terrainTraversal.PushUnitPosAndNeighboor(*startUnit); } else { Assert(Map.Info.IsPointOnMap(startPos)); @@ -339,7 +339,7 @@ static bool AiFindHallPlace(const CUnit &worker, if (terrainTraversal.Run(hallPlaceFinder)) { return true; } - return AiFindBuildingPlace2(worker, type, startPos, NULL, true, resultPos); + return AiFindBuildingPlace2(worker, type, startPos, nullptr, true, resultPos); } class LumberMillPlaceFinder @@ -368,7 +368,7 @@ VisitResult LumberMillPlaceFinder::Visit(TerrainTraversal &terrainTraversal, con } #endif if (Map.Field(pos)->IsTerrainResourceOnMap(resource)) { - if (AiFindBuildingPlace2(worker, type, from, NULL, true, resultPos)) { + if (AiFindBuildingPlace2(worker, type, from, nullptr, true, resultPos)) { return VisitResult_Finished; } } @@ -414,7 +414,7 @@ static bool AiFindMiningPlace(const CUnit &worker, Vec2i *resultPos) { // look near (mine = ResourceOnMap(pos, resource, false) ? - return AiFindBuildingPlace2(worker, type, startPos, NULL, false, resultPos); + return AiFindBuildingPlace2(worker, type, startPos, nullptr, false, resultPos); } /** @@ -456,12 +456,12 @@ bool AiFindBuildingPlace(const CUnit &worker, const CUnitType &type, const Vec2i return AiFindMiningPlace(worker, type, startPos, i, resultPos); } else { //Mine can be build without resource restrictions: solar panels, etc - return AiFindBuildingPlace2(worker, type, startPos, NULL, true, resultPos); + return AiFindBuildingPlace2(worker, type, startPos, nullptr, true, resultPos); } } } } - return AiFindBuildingPlace2(worker, type, startPos, NULL, true, resultPos); + return AiFindBuildingPlace2(worker, type, startPos, nullptr, true, resultPos); } //@} diff --git a/src/ai/ai_force.cpp b/src/ai/ai_force.cpp index 0e9caa6f4..0b18337b5 100644 --- a/src/ai/ai_force.cpp +++ b/src/ai/ai_force.cpp @@ -68,7 +68,7 @@ public: find_type(find_type), result_unit(result_unit) { - *result_unit = NULL; + *result_unit = nullptr; } VisitResult Visit(TerrainTraversal &terrainTraversal, const Vec2i &pos, const Vec2i &from); private: @@ -108,7 +108,7 @@ VisitResult EnemyUnitFinder::Visit(TerrainTraversal &terrainTraversal, const Vec if ((find_type != AIATTACK_BUILDING || dtype.BoolFlag[BUILDING_INDEX].value) && (find_type != AIATTACK_AGRESSIVE || dest->IsAgressive())) { *result_unit = dest; return VisitResult_Finished; - } else if (*result_unit == NULL) { // if trying to search for buildings or aggressive units specifically, still put the first found unit (even if it doesn't fit those parameters) as the result unit, so that it can be returned if no unit with the specified parameters is found + } else if (*result_unit == nullptr) { // if trying to search for buildings or aggressive units specifically, still put the first found unit (even if it doesn't fit those parameters) as the result unit, so that it can be returned if no unit with the specified parameters is found *result_unit = dest; } } @@ -121,24 +121,24 @@ class AiForceEnemyFinder public: AiForceEnemyFinder(int force, const CUnit **enemy) : enemy(enemy) { - Assert(enemy != NULL); - *enemy = NULL; + Assert(enemy != nullptr); + *enemy = nullptr; AiPlayer->Force[force].Units.for_each_if(*this); } AiForceEnemyFinder(AiForce &force, const CUnit **enemy) : enemy(enemy) { - Assert(enemy != NULL); - *enemy = NULL; + Assert(enemy != nullptr); + *enemy = nullptr; force.Units.for_each_if(*this); } - bool found() const { return *enemy != NULL; } + bool found() const { return *enemy != nullptr; } bool operator()(const CUnit *const unit) const { if (unit->Type->CanAttack == false) { - return *enemy == NULL; + return *enemy == nullptr; } if (FIND_TYPE == AIATTACK_RANGE) { *enemy = AttackUnitsInReactRange(*unit); @@ -148,7 +148,7 @@ public: terrainTraversal.SetSize(Map.Info.MapWidth, Map.Info.MapHeight); terrainTraversal.Init(); terrainTraversal.PushUnitPosAndNeighboor(*unit); - CUnit *result_unit = NULL; + CUnit *result_unit = nullptr; EnemyUnitFinder enemyUnitFinder(*unit, &result_unit, FIND_TYPE); terrainTraversal.Run(enemyUnitFinder); *enemy = result_unit; @@ -161,17 +161,17 @@ public: // } else if (FIND_TYPE == AIATTACK_BUILDING) { // *enemy = AttackUnitsInDistance(*unit, MaxMapWidth, IsBuildingType()); // Assert(!*enemy); - // if (*enemy == NULL || !(*enemy)->Type->Building) { + // if (*enemy == nullptr || !(*enemy)->Type->Building) { // *enemy = AttackUnitsInDistance(*unit, MaxMapWidth); // } // } else if (FIND_TYPE == AIATTACK_AGRESSIVE) { // *enemy = AttackUnitsInDistance(*unit, MaxMapWidth, IsAggresiveUnit()); // Assert(!*enemy || (*enemy)->IsAgressive()); - // if (*enemy == NULL) { + // if (*enemy == nullptr) { // *enemy = AttackUnitsInDistance(*unit, MaxMapWidth); // } // } - return *enemy == NULL; + return *enemy == nullptr; } private: const CUnit **enemy; @@ -404,7 +404,7 @@ private: VisitResult AiForceRallyPointFinder::Visit(TerrainTraversal &terrainTraversal, const Vec2i &pos, const Vec2i &from) { const int minDist = 15; - if (AiEnemyUnitsInDistance(*startUnit.Player, NULL, pos, minDist) == false + if (AiEnemyUnitsInDistance(*startUnit.Player, nullptr, pos, minDist) == false && Distance(pos, startPos) <= abs(distance - minDist)) { *resultPos = pos; return VisitResult_Finished; @@ -475,7 +475,7 @@ void AiForce::Attack(const Vec2i &pos) } if (Map.Info.IsPointOnMap(goalPos) == false) { /* Search in entire map */ - const CUnit *enemy = NULL; + const CUnit *enemy = nullptr; if (isTransporter) { AiForceEnemyFinder(*this, &enemy); } else if (isNaval) { @@ -513,7 +513,7 @@ void AiForce::Attack(const Vec2i &pos) } // Send all units in the force to enemy. - CUnit *leader = NULL; + CUnit *leader = nullptr; for (size_t i = 0; i != this->Units.size(); ++i) { CUnit *const unit = this->Units[i]; @@ -525,12 +525,12 @@ void AiForce::Attack(const Vec2i &pos) for (size_t i = 0; i != this->Units.size(); ++i) { CUnit *const unit = this->Units[i]; - if (unit->Container == NULL) { + if (unit->Container == nullptr) { const int delay = i / 5; // To avoid lot of CPU consuption, send them with a small time difference. unit->Wait = delay; if (unit->IsAgressive()) { - CommandAttack(*unit, this->GoalPos, NULL, FlushCommands); + CommandAttack(*unit, this->GoalPos, nullptr, FlushCommands); } else { if (leader) { CommandDefend(*unit, *leader, FlushCommands); @@ -877,7 +877,7 @@ static void AiGroupAttackerForTransport(AiForce &aiForce) const CUnit &unit = *aiForce.Units[i]; const CUnit &transporter = *aiForce.Units[transporterIndex]; - if (CanTransport(transporter, unit) && unit.Container == NULL) { + if (CanTransport(transporter, unit) && unit.Container == nullptr) { forceIsReady = false; break; } @@ -896,7 +896,7 @@ static void AiGroupAttackerForTransport(AiForce &aiForce) } if (CanTransport(transporter, unit) && (unit.IsIdle() || (unit.CurrentAction() == UnitActionBoard && !unit.Moving - && static_cast(unit.CurrentOrder())->GetGoal() != &transporter)) && unit.Container == NULL) { + && static_cast(unit.CurrentOrder())->GetGoal() != &transporter)) && unit.Container == nullptr) { CommandBoard(unit, transporter, FlushCommands); CommandFollow(transporter, unit, 0); if (--nbToTransport == 0) { // full : next transporter. @@ -994,12 +994,12 @@ void AiForce::Update() const int delay = i / 5; // To avoid lot of CPU consuption, send them with a small time difference. trans.Wait = delay; - CommandUnload(trans, this->GoalPos, NULL, FlushCommands); + CommandUnload(trans, this->GoalPos, nullptr, FlushCommands); } } return; } - CUnit *leader = NULL; + CUnit *leader = nullptr; for (unsigned int i = 0; i != Size(); ++i) { CUnit &aiunit = *Units[i]; @@ -1026,7 +1026,7 @@ void AiForce::Update() --WaitOnRallyPoint; } if (maxDist <= thresholdDist || !WaitOnRallyPoint) { - const CUnit *unit = NULL; + const CUnit *unit = nullptr; AiForceEnemyFinder(*this, &unit); if (!unit) { @@ -1049,7 +1049,7 @@ void AiForce::Update() aiunit.Wait = delay; if (aiunit.IsAgressive()) { - CommandAttack(aiunit, this->GoalPos, NULL, FlushCommands); + CommandAttack(aiunit, this->GoalPos, nullptr, FlushCommands); } else { if (leader) { CommandDefend(aiunit, *leader, FlushCommands); @@ -1075,7 +1075,7 @@ void AiForce::Update() } if (State == AiForceAttackingState_Attacking && idleUnits.size() == this->Size()) { - const CUnit *unit = NULL; + const CUnit *unit = nullptr; bool isNaval = false; for (size_t i = 0; i != this->Units.size(); ++i) { @@ -1118,16 +1118,16 @@ void AiForce::Update() if (leader) { if (aiunit.IsAgressive()) { if (State == AiForceAttackingState_Attacking) { - CommandAttack(aiunit, leader->tilePos, NULL, FlushCommands); + CommandAttack(aiunit, leader->tilePos, nullptr, FlushCommands); } else { - CommandAttack(aiunit, this->GoalPos, NULL, FlushCommands); + CommandAttack(aiunit, this->GoalPos, nullptr, FlushCommands); } } else { CommandDefend(aiunit, *leader, FlushCommands); } } else { if (aiunit.IsAgressive()) { - CommandAttack(aiunit, this->GoalPos, NULL, FlushCommands); + CommandAttack(aiunit, this->GoalPos, nullptr, FlushCommands); } else { CommandMove(aiunit, this->GoalPos, FlushCommands); } @@ -1165,7 +1165,7 @@ void AiForceManager::Update() for (unsigned int i = 0; i != force.Size(); ++i) { if (force.Units[i]->MapDistanceTo(force.GoalPos) <= nearDist) { // Look if still enemies in attack range. - const CUnit *dummy = NULL; + const CUnit *dummy = nullptr; maxPathing--; if (!AiForceEnemyFinder(force, &dummy).found()) { force.ReturnToHome(); @@ -1199,12 +1199,12 @@ void AiForceManager::Update() for (unsigned int i = 0; i != idleUnits.size(); ++i) { CUnit *const unit = idleUnits[i]; - if (unit->Container == NULL) { + if (unit->Container == nullptr) { const int delay = i / 5; // To avoid lot of CPU consuption, send them with a small time difference. unit->Wait = delay; if (unit->Type->CanAttack) { - CommandAttack(*unit, force.GoalPos, NULL, FlushCommands); + CommandAttack(*unit, force.GoalPos, nullptr, FlushCommands); } else { CommandMove(*unit, force.GoalPos, FlushCommands); } diff --git a/src/ai/ai_local.h b/src/ai/ai_local.h index 67dddb12f..1eab1df63 100644 --- a/src/ai/ai_local.h +++ b/src/ai/ai_local.h @@ -71,7 +71,7 @@ public: class AiRequestType { public: - AiRequestType() : Count(0), Type(NULL) {} + AiRequestType() : Count(0), Type(nullptr) {} unsigned int Count; /// elements in table CUnitType *Type; /// the type @@ -83,7 +83,7 @@ public: class AiUnitType { public: - AiUnitType() : Want(0), Type(NULL) {} + AiUnitType() : Want(0), Type(nullptr) {} unsigned int Want; /// number of this unit-type wanted CUnitType *Type; /// unit-type self @@ -246,7 +246,7 @@ private: class AiBuildQueue { public: - AiBuildQueue() : Want(0), Made(0), Type(NULL), Wait(0) + AiBuildQueue() : Want(0), Made(0), Type(nullptr), Wait(0) { Pos.x = Pos.y = -1; } @@ -278,7 +278,7 @@ public: class PlayerAi { public: - PlayerAi() : Player(NULL), AiType(NULL), + PlayerAi() : Player(nullptr), AiType(nullptr), SleepCycles(0), NeededMask(0), NeedSupply(false), ScriptDebug(false), BuildDepots(true), LastExplorationGameCycle(0), LastCanNotMoveGameCycle(0), LastRepairBuilding(0) diff --git a/src/ai/ai_plan.cpp b/src/ai/ai_plan.cpp index 773b54a7d..e8ac061e3 100644 --- a/src/ai/ai_plan.cpp +++ b/src/ai/ai_plan.cpp @@ -110,7 +110,7 @@ private: */ static CUnit *EnemyOnMapTile(const CUnit &source, const Vec2i &pos) { - CUnit *enemy = NULL; + CUnit *enemy = nullptr; _EnemyOnMapTile filter(source, pos, &enemy); Map.Field(pos)->UnitCache.for_each(filter); @@ -203,7 +203,7 @@ int AiFindWall(AiForce *force) for (unsigned int i = 0; i < force->Units.size(); ++i) { CUnit &aiunit = *force->Units[i]; if (aiunit.Type->CanAttack) { - CommandAttack(aiunit, wallPos, NULL, FlushCommands); + CommandAttack(aiunit, wallPos, nullptr, FlushCommands); } else { CommandMove(aiunit, wallPos, FlushCommands); } @@ -353,7 +353,7 @@ int AiForce::PlanAttack() CUnit *transporter = Units.find(IsAFreeTransporter()); - if (transporter != NULL) { + if (transporter != nullptr) { DebugPrint("%d: Transporter #%d\n" _C_ player.Index _C_ UnitNumber(*transporter)); MarkReacheableTerrainType(*transporter, &transporterTerrainTraversal); } else { @@ -370,7 +370,7 @@ int AiForce::PlanAttack() // Find a land unit of the force. // FIXME: if force is split over different places -> broken CUnit *landUnit = Units.find(CUnitTypeFinder(UnitTypeLand)); - if (landUnit == NULL) { + if (landUnit == nullptr) { DebugPrint("%d: No land unit in force\n" _C_ player.Index); return 0; } @@ -428,7 +428,7 @@ int AiForce::PlanAttack() static bool ChooseRandomUnexploredPositionNear(const Vec2i ¢er, Vec2i *pos) { - Assert(pos != NULL); + Assert(pos != nullptr); int ray = 3; const int maxTryCount = 8; @@ -450,11 +450,11 @@ static CUnit *GetBestExplorer(const AiExplorationRequest &request, Vec2i *pos) // Choose a target, "near" const Vec2i ¢er = request.pos; if (ChooseRandomUnexploredPositionNear(center, pos) == false) { - return NULL; + return nullptr; } // We have an unexplored tile in sight (pos) - CUnit *bestunit = NULL; + CUnit *bestunit = nullptr; // Find an idle unit, responding to the mask bool flyeronly = false; int bestSquareDistance = -1; @@ -517,7 +517,7 @@ void AiSendExplorers() Vec2i pos; CUnit *bestunit = GetBestExplorer(request, &pos); - if (bestunit != NULL) { + if (bestunit != nullptr) { CommandMove(*bestunit, pos, FlushCommands); AiPlayer->LastExplorationGameCycle = GameCycle; break; diff --git a/src/ai/ai_resource.cpp b/src/ai/ai_resource.cpp index 1fa34cbbf..fbc2d1365 100644 --- a/src/ai/ai_resource.cpp +++ b/src/ai/ai_resource.cpp @@ -216,7 +216,7 @@ bool AiEnemyUnitsInDistance(const CPlayer &player, const Vec2i offset(range, range); std::vector units; - if (type == NULL) { + if (type == nullptr) { Select<1>(pos - offset, pos + offset, units, IsAEnemyUnitOf(player)); return static_cast(units.size()); } else { @@ -370,14 +370,14 @@ void AiNewDepotRequest(CUnit &worker) const Vec2i pos = order.GetHarvestLocation(); const int range = 15; - if (pos.x != -1 && NULL != FindDepositNearLoc(*worker.Player, pos, range, resource)) { + if (pos.x != -1 && nullptr != FindDepositNearLoc(*worker.Player, pos, range, resource)) { /* * New Depot has just be finished and worker just return to old depot * (far away) from new Deopt. */ return; } - CUnitType *best_type = NULL; + CUnitType *best_type = nullptr; int best_cost = 0; //int best_mask = 0; // Count the already made build requests. @@ -404,7 +404,7 @@ void AiNewDepotRequest(CUnit &worker) cost += type.Stats[worker.Player->Index].Costs[c]; } - if (best_type == NULL || (cost < best_cost)) { + if (best_type == nullptr || (cost < best_cost)) { best_type = &type; best_cost = cost; //best_mask = needmask; @@ -462,7 +462,7 @@ private: ** @param oldDepot Old assigned depot. ** @param resUnit Resource to harvest from, if succeed ** -** @return new depot if found, NULL otherwise. +** @return new depot if found, nullptr otherwise. */ CUnit *AiGetSuitableDepot(const CUnit &worker, const CUnit &oldDepot, CUnit **resUnit) { @@ -480,7 +480,7 @@ CUnit *AiGetSuitableDepot(const CUnit &worker, const CUnit &oldDepot, CUnit **re } // If there aren't any alternatives, exit if (depots.size() < 2) { - return NULL; + return nullptr; } std::sort(depots.begin(), depots.end(), CompareDepotsByDistance(worker)); @@ -505,7 +505,7 @@ CUnit *AiGetSuitableDepot(const CUnit &worker, const CUnit &oldDepot, CUnit **re return &unit; } } - return NULL; + return nullptr; } /** @@ -1154,7 +1154,7 @@ static void AiCollectResources() } } } - unit = NULL; + unit = nullptr; // Try to complete each ressource in the priority order for (int i = 0; i < MaxCosts; ++i) { @@ -1218,7 +1218,7 @@ static void AiCollectResources() // unit can't harvest : next one if (!unit->Type->ResInfo[c] || !AiAssignHarvester(*unit, c)) { - unit = NULL; + unit = nullptr; continue; } @@ -1305,10 +1305,10 @@ static bool AiRepairBuilding(const CPlayer &player, const CUnitType &type, CUnit const int maxRange = 15; const int movemask = type.MovementMask & ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit); - CUnit *unit = NULL; + CUnit *unit = nullptr; UnitFinder unitFinder(player, table, maxRange, movemask, &unit); - if (terrainTraversal.Run(unitFinder) && unit != NULL) { + if (terrainTraversal.Run(unitFinder) && unit != nullptr) { const Vec2i invalidPos(-1, -1); CommandRepair(*unit, invalidPos, &building, FlushCommands); return true; diff --git a/src/ai/script_ai.cpp b/src/ai/script_ai.cpp index 27339e1ca..283808f2e 100644 --- a/src/ai/script_ai.cpp +++ b/src/ai/script_ai.cpp @@ -132,7 +132,7 @@ static std::vector getSupplyUnits() // Now, sort them, best first. while (!res.empty()) { float bestscore = 0; - CUnitType *besttype = NULL; + CUnitType *besttype = nullptr; for (std::vector::const_iterator i = res.begin(); i != res.end(); ++i) { CUnitType &type = **i; @@ -364,7 +364,7 @@ static CAiType *GetAiTypesByName(const char *name) return ait; } } - return NULL; + return nullptr; } /** @@ -491,7 +491,7 @@ static AiRequestType *FindInUnitTypeRequests(const CUnitType *type) return &AiPlayer->UnitTypeRequests[i]; } } - return NULL; + return nullptr; } /** @@ -614,7 +614,7 @@ static int CclAiDebugPlayer(lua_State *l) if (lua_isstring(l, j + 1)) { item = LuaToString(l, j + 1); } else { - item = NULL; + item = nullptr; } if (item && !strcmp(item, "none")) { for (int i = 0; i != NumPlayers; ++i) { @@ -1368,7 +1368,7 @@ static int CclAiResearch(lua_State *l) upgrade = CUpgrade::Get(str); } else { LuaError(l, "Upgrade needed"); - upgrade = NULL; + upgrade = nullptr; } InsertResearchRequests(upgrade); lua_pushboolean(l, 0); @@ -1679,7 +1679,7 @@ static int CclDefineAiPlayer(lua_State *l) if (!strcmp(value, "ai-type")) { const char *aiName = LuaToString(l, j + 1); CAiType *ait = GetAiTypesByName(aiName); - if (ait == NULL) { + if (ait == nullptr) { LuaError(l, "ai-type not found: %s" _C_ aiName); } ai->AiType = ait; @@ -1935,7 +1935,7 @@ static CTCPSocket * AiProcessorSendState(lua_State *l, char prefix) { LuaCheckArgs(l, 3); CTCPSocket *s = (CTCPSocket *)lua_touserdata(l, 1); - if (s == NULL) { + if (s == nullptr) { LuaError(l, "first argument must be valid handle returned from a previous AiProcessorSetup call"); } diff --git a/src/animation/animation.cpp b/src/animation/animation.cpp index 0ee326be5..e8d86c17e 100644 --- a/src/animation/animation.cpp +++ b/src/animation/animation.cpp @@ -160,7 +160,7 @@ int ParseAnimInt(const CUnit &unit, const char *parseint) } } char *next = strchr(cur, '.'); - if (next == NULL) { + if (next == nullptr) { fprintf(stderr, "Need also specify the variable '%s' tag \n", cur); ExitFatal(1); } else { @@ -227,7 +227,7 @@ int ParseAnimInt(const CUnit &unit, const char *parseint) if (*cur == '(') { ++cur; char *end = strchr(cur, ')'); - if (end == NULL) { + if (end == nullptr) { fprintf(stderr, "ParseAnimInt: expected ')'\n"); ExitFatal(1); } @@ -236,20 +236,20 @@ int ParseAnimInt(const CUnit &unit, const char *parseint) } else { next = strchr(cur, '.'); } - if (next == NULL) { + if (next == nullptr) { fprintf(stderr, "Need also specify the %s player's property\n", cur); ExitFatal(1); } else { *next = '\0'; } char *arg = strchr(next + 1, '.'); - if (arg != NULL) { + if (arg != nullptr) { *arg = '\0'; } return GetPlayerData(ParseAnimPlayer(unit, cur), next + 1, arg + 1); } else if (s[0] == 'r') { //random value char *next = strchr(cur, '.'); - if (next == NULL) { + if (next == nullptr) { return SyncRand(atoi(cur) + 1); } else { *next = '\0'; @@ -410,7 +410,7 @@ CAnimations *AnimationsByIdent(const std::string &ident) if (ret != AnimationMap.end()) { return (*ret).second; } - return NULL; + return nullptr; } void FreeAnimations() @@ -560,7 +560,7 @@ static CAnimation *FindLabel(lua_State *l, const std::string &name) } } LuaError(l, "Label not found: %s" _C_ name.c_str()); - return NULL; + return nullptr; } /** @@ -600,7 +600,7 @@ static CAnimation *ParseAnimationFrame(lua_State *l, const char *str) size_t begin = std::min(len, all.find_first_not_of(' ', end)); const std::string extraArg(all, begin); - CAnimation *anim = NULL; + CAnimation *anim = nullptr; if (op1 == "frame") { anim = new CAnimation_Frame; } else if (op1 == "exact-frame") { @@ -664,7 +664,7 @@ static CAnimation *ParseAnimation(lua_State *l, int idx) const int args = lua_rawlen(l, idx); if (args == 0) { - return NULL; + return nullptr; } Labels.clear(); LabelsLater.clear(); diff --git a/src/animation/animation_exactframe.cpp b/src/animation/animation_exactframe.cpp index f03bf2790..f36ce9b3c 100644 --- a/src/animation/animation_exactframe.cpp +++ b/src/animation/animation_exactframe.cpp @@ -52,7 +52,7 @@ int CAnimation_ExactFrame::ParseAnimInt(const CUnit *unit) const { - if (unit == NULL) { + if (unit == nullptr) { return atoi(this->frame.c_str()); } else { return ::ParseAnimInt(*unit, this->frame.c_str()); diff --git a/src/animation/animation_frame.cpp b/src/animation/animation_frame.cpp index bc72337a8..8b5418f23 100644 --- a/src/animation/animation_frame.cpp +++ b/src/animation/animation_frame.cpp @@ -58,7 +58,7 @@ int CAnimation_Frame::ParseAnimInt(const CUnit *unit) const { - if (unit == NULL) { + if (unit == nullptr) { return atoi(this->frame.c_str()); } else { return ::ParseAnimInt(*unit, this->frame.c_str()); diff --git a/src/animation/animation_setvar.cpp b/src/animation/animation_setvar.cpp index 46b9d4e18..51a2a7b28 100644 --- a/src/animation/animation_setvar.cpp +++ b/src/animation/animation_setvar.cpp @@ -71,7 +71,7 @@ } char *next = strchr(arg1, '.'); - if (next == NULL) { + if (next == nullptr) { // Special case for non-CVariable variables if (!strcmp(arg1, "DamageType")) { int death = ExtraDeathIndex(this->valueStr.c_str()); diff --git a/src/animation/animation_spawnmissile.cpp b/src/animation/animation_spawnmissile.cpp index b3117c22f..033b1d0ba 100644 --- a/src/animation/animation_spawnmissile.cpp +++ b/src/animation/animation_spawnmissile.cpp @@ -62,7 +62,7 @@ PixelPos start; PixelPos dest; MissileType *mtype = MissileTypeByIdent(this->missileTypeStr); - if (mtype == NULL) { + if (mtype == nullptr) { return; } diff --git a/src/animation/animation_spawnunit.cpp b/src/animation/animation_spawnunit.cpp index c77cc8f42..dedf66259 100644 --- a/src/animation/animation_spawnunit.cpp +++ b/src/animation/animation_spawnunit.cpp @@ -62,7 +62,7 @@ FindNearestDrop(*type, pos, resPos, LookingW); if (SquareDistance(pos, resPos) <= square(range)) { CUnit *target = MakeUnit(*type, &player); - if (target != NULL) { + if (target != nullptr) { target->tilePos = resPos; target->Place(resPos); if (flags & SU_Summoned) { @@ -76,7 +76,7 @@ CommandDefend(*target, unit, FlushCommands); } } - //DropOutOnSide(*target, LookingW, NULL); + //DropOutOnSide(*target, LookingW, nullptr); } else { DebugPrint("Unable to allocate Unit"); } diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp index 64369cc01..3c5b9f91f 100644 --- a/src/editor/editloop.cpp +++ b/src/editor/editloop.cpp @@ -271,12 +271,12 @@ static void EditorActionPlaceUnit(const Vec2i &pos, const CUnitType &type, CPlay // FIXME: vladi: should check place when mirror editing is enabled...? CUnit *unit = MakeUnitAndPlace(pos, type, player); - if (unit == NULL) { + if (unit == nullptr) { DebugPrint("Unable to allocate Unit"); return; } - CBuildRestrictionOnTop *b = OnTopDetails(*unit, NULL); + CBuildRestrictionOnTop *b = OnTopDetails(*unit, nullptr); if (b && b->ReplaceOnBuild) { CUnitCache &unitCache = Map.Field(pos)->UnitCache; CUnitCache::iterator it = std::find_if(unitCache.begin(), unitCache.end(), HasSameTypeAs(*b->Parent)); @@ -287,13 +287,13 @@ static void EditorActionPlaceUnit(const Vec2i &pos, const CUnitType &type, CPlay unit->Variable[GIVERESOURCE_INDEX].Value = replacedUnit.Variable[GIVERESOURCE_INDEX].Value; unit->Variable[GIVERESOURCE_INDEX].Max = replacedUnit.Variable[GIVERESOURCE_INDEX].Max; unit->Variable[GIVERESOURCE_INDEX].Enable = replacedUnit.Variable[GIVERESOURCE_INDEX].Enable; - replacedUnit.Remove(NULL); // Destroy building beneath + replacedUnit.Remove(nullptr); // Destroy building beneath UnitLost(replacedUnit); UnitClearOrders(replacedUnit); replacedUnit.Release(); } } - if (unit != NULL) { + if (unit != nullptr) { if (type.GivesResource) { if (type.StartingResources != 0) { unit->ResourcesHeld = type.StartingResources; @@ -336,7 +336,7 @@ static void EditorPlaceUnit(const Vec2i &pos, CUnitType &type, CPlayer *player) */ static void EditorActionRemoveUnit(CUnit &unit) { - unit.Remove(NULL); + unit.Remove(nullptr); UnitLost(unit); UnitClearOrders(unit); unit.Release(); @@ -429,7 +429,7 @@ static void CalculateMaxIconSize() for (unsigned int i = 0; i < Editor.UnitTypes.size(); ++i) { if (!Editor.UnitTypes[i].empty()) { const CUnitType *type = UnitTypeByIdent(Editor.UnitTypes[i].c_str()); - if (type != NULL && type->Icon.Icon) { + if (type != nullptr && type->Icon.Icon) { const CIcon &icon = *type->Icon.Icon; IconWidth = std::max(IconWidth, icon.G->Width); @@ -451,7 +451,7 @@ static void RecalculateShownUnits(size_t start = 0, size_t stop = INT_MAX) const CUnitType *type = UnitTypeByIdent(Editor.UnitTypes[i].c_str()); Editor.ShownUnitTypes.push_back(type); } else { - Editor.ShownUnitTypes.push_back(NULL); + Editor.ShownUnitTypes.push_back(nullptr); } } @@ -647,7 +647,7 @@ static bool forEachUnitIconArea(std::functionIcon.Icon; @@ -1304,7 +1304,7 @@ static void EditorCallbackButtonDown(unsigned button) // Right click on a resource if (Editor.State == EditorSelecting) { - if ((MouseButtons & RightButton) && (UnitUnderCursor != NULL || !Selected.empty())) { + if ((MouseButtons & RightButton) && (UnitUnderCursor != nullptr || !Selected.empty())) { lua_getglobal(Lua, "EditUnitProperties"); if (lua_isfunction(Lua, -1) == 1) { lua_newtable(Lua); @@ -1331,11 +1331,11 @@ static void EditorCallbackButtonDown(unsigned button) if (MouseButtons & RightButton) { if (Editor.State == EditorEditUnit && Editor.SelectedUnitIndex != -1) { Editor.SelectedUnitIndex = -1; - CursorBuilding = NULL; + CursorBuilding = nullptr; return; } else if (Editor.State == EditorEditTile && Editor.SelectedTileIndex != -1) { Editor.SelectedTileIndex = -1; - CursorBuilding = NULL; + CursorBuilding = nullptr; return; } } @@ -1353,7 +1353,7 @@ static void EditorCallbackButtonDown(unsigned button) EditTiles(tilePos, Editor.SelectedTileIndex != -1 ? Editor.ShownTileTypes[Editor.SelectedTileIndex] : -1, TileCursorSize); } else if (Editor.State == EditorEditUnit) { if (!UnitPlacedThisPress && CursorBuilding) { - if (CanBuildUnitType(NULL, *CursorBuilding, tilePos, 1)) { + if (CanBuildUnitType(nullptr, *CursorBuilding, tilePos, 1)) { PlayGameSound(GameSounds.PlacementSuccess[ThisPlayer->Race].Sound, MaxSampleVolume); EditorPlaceUnit(tilePos, *CursorBuilding, Players + Editor.SelectedPlayer); @@ -1487,7 +1487,7 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar) case SDLK_BACKSPACE: case SDLK_DELETE: // Delete - if (UnitUnderCursor != NULL) { + if (UnitUnderCursor != nullptr) { EditorRemoveUnit(*UnitUnderCursor); } break; @@ -1510,7 +1510,7 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar) break; case '0': if (!(KeyModifiers & ModifierAlt)) { - if (UnitUnderCursor != NULL) { + if (UnitUnderCursor != nullptr) { UnitUnderCursor->ChangeOwner(Players[PlayerNumNeutral]); UI.StatusLine.Set(_("Unit owner modified")); } @@ -1529,7 +1529,7 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar) break; } } - if (UnitUnderCursor != NULL && Map.Info.PlayerType[pnum] != PlayerTypes::PlayerNobody) { + if (UnitUnderCursor != nullptr && Map.Info.PlayerType[pnum] != PlayerTypes::PlayerNobody) { UnitUnderCursor->ChangeOwner(Players[pnum]); UI.StatusLine.Set(_("Unit owner modified")); UpdateMinimap = true; @@ -1645,7 +1645,7 @@ static bool EditorCallbackMouse_EditUnitArea(const PixelPos &screenPos) noHit = forEachUnitIconArea([screenPos](int i, ButtonStyle*, int x, int y, int w, int h) { if (x < screenPos.x && screenPos.x < x + w && y < screenPos.y && screenPos.y < y + h) { - if (Editor.ShownUnitTypes[i] == NULL) { + if (Editor.ShownUnitTypes[i] == nullptr) { return false; } char buf[256]; @@ -1777,7 +1777,7 @@ static void EditorCallbackMouse(const PixelPos &pos) EditTiles(tilePos, Editor.SelectedTileIndex != -1 ? Editor.ShownTileTypes[Editor.SelectedTileIndex] : -1, TileCursorSize); } else if (Editor.State == EditorEditUnit && CursorBuilding) { if (!UnitPlacedThisPress) { - if (CanBuildUnitType(NULL, *CursorBuilding, tilePos, 1)) { + if (CanBuildUnitType(nullptr, *CursorBuilding, tilePos, 1)) { EditorPlaceUnit(tilePos, *CursorBuilding, Players + Editor.SelectedPlayer); UnitPlacedThisPress = true; UI.StatusLine.Clear(); @@ -1839,7 +1839,7 @@ static void EditorCallbackMouse(const PixelPos &pos) } // Map - UnitUnderCursor = NULL; + UnitUnderCursor = nullptr; if (UI.MapArea.Contains(screenPos)) { CViewport *vp = GetViewport(screenPos); Assert(vp); @@ -1854,7 +1854,7 @@ static void EditorCallbackMouse(const PixelPos &pos) const PixelPos cursorMapPos = UI.MouseViewport->ScreenToMapPixelPos(CursorScreenPos); UnitUnderCursor = UnitOnScreen(cursorMapPos.x, cursorMapPos.y); - if (UnitUnderCursor != NULL) { + if (UnitUnderCursor != nullptr) { ShowUnitInfo(*UnitUnderCursor); return; } @@ -1943,9 +1943,9 @@ void CEditor::Init() } } } - if (UI.ButtonPanel.G != NULL) { + if (UI.ButtonPanel.G != nullptr) { ButtonPanelWidth = UI.ButtonPanel.G->Width; - } else if (UI.InfoPanel.G != NULL) { + } else if (UI.InfoPanel.G != nullptr) { ButtonPanelWidth = UI.InfoPanel.G->Width; } else { ButtonPanelWidth = 170; @@ -1957,9 +1957,9 @@ void CEditor::Init() if (!StartUnitName.empty()) { StartUnit = UnitTypeByIdent(StartUnitName); } - Select.Icon = NULL; + Select.Icon = nullptr; Select.Load(); - Units.Icon = NULL; + Units.Icon = nullptr; Units.Load(); Map.Tileset->fillSolidTiles(&Editor.ShownTileTypes); @@ -2280,7 +2280,7 @@ void EditorMainLoop() WaitEventsOneFrame(); } - CursorBuilding = NULL; + CursorBuilding = nullptr; if (!Editor.MapLoaded) { break; } @@ -2318,7 +2318,7 @@ void EditorMainLoop() /** ** Start the editor ** -** @param filename Map to load, NULL to create a new map +** @param filename Map to load, nullptr to create a new map */ void StartEditor(const char *filename) { @@ -2327,7 +2327,7 @@ void StartEditor(const char *filename) GetDefaultTextColors(nc, rc); if (filename) { if (strcpy_s(CurrentMapPath, sizeof(CurrentMapPath), filename) != 0) { - filename = NULL; + filename = nullptr; } } if (!filename) { diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index eaa3c86c7..5bcfa6a0d 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -75,7 +75,7 @@ CEditor::CEditor() : TerrainEditable(true), - StartUnit(NULL), + StartUnit(nullptr), UnitIndex(0), CursorUnitIndex(-1), SelectedUnitIndex(-1), TileIndex(0), CursorTileIndex(-1), SelectedTileIndex(-1), CursorPlayer(-1), SelectedPlayer(PlayerNumNeutral), diff --git a/src/editor/edmap.cpp b/src/editor/edmap.cpp index 30002182e..0fc5ea92a 100644 --- a/src/editor/edmap.cpp +++ b/src/editor/edmap.cpp @@ -367,28 +367,28 @@ static void EditorRandomizeUnit(const char *unit_type, int count, int value, int // FIXME: can overlap units CUnit *unit = MakeUnitAndPlace(rpos, type, &Players[PlayerNumNeutral]); - if (unit == NULL) { + if (unit == nullptr) { DebugPrint("Unable to allocate Unit"); } else { unit->ResourcesHeld = value; } unit = MakeUnitAndPlace(tmirrorh, type, &Players[PlayerNumNeutral]); - if (unit == NULL) { + if (unit == nullptr) { DebugPrint("Unable to allocate Unit"); } else { unit->ResourcesHeld = value; } unit = MakeUnitAndPlace(tmirrorv, type, &Players[PlayerNumNeutral]); - if (unit == NULL) { + if (unit == nullptr) { DebugPrint("Unable to allocate Unit"); } else { unit->ResourcesHeld = value; } unit = MakeUnitAndPlace(tmirror, type, &Players[PlayerNumNeutral]); - if (unit == NULL) { + if (unit == nullptr) { DebugPrint("Unable to allocate Unit"); } else { unit->ResourcesHeld = value; @@ -404,7 +404,7 @@ static void EditorDestroyAllUnits() while (UnitManager->empty() == false) { CUnit &unit = **UnitManager->begin(); - unit.Remove(NULL); + unit.Remove(nullptr); UnitLost(unit); UnitClearOrders(unit); unit.Release(); diff --git a/src/game/game.cpp b/src/game/game.cpp index b9b2ff42e..7c2645848 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -258,7 +258,7 @@ static void WriteMapPreview(const char *mapname, CMap &map) const SDL_PixelFormat *fmt = MinimapSurface->format; SDL_Surface *preview = SDL_CreateRGBSurface(SDL_SWSURFACE, UI.Minimap.W, UI.Minimap.H, 32, fmt->Rmask, fmt->Gmask, fmt->Bmask, 0); - SDL_BlitSurface(MinimapSurface, NULL, preview, NULL); + SDL_BlitSurface(MinimapSurface, nullptr, preview, nullptr); SDL_LockSurface(preview); @@ -291,7 +291,7 @@ std::string PlayerTypeNames[static_cast(PlayerTypes::PlayerRescueActive) + // Write the map presentation file static int WriteMapPresentation(const std::string &mapname, CMap &map, Vec2i newSize) { - FileWriter *f = NULL; + FileWriter *f = nullptr; int numplayers = 0; int topplayer = PlayerMax - 2; @@ -347,7 +347,7 @@ static int WriteMapPresentation(const std::string &mapname, CMap &map, Vec2i new */ int WriteMapSetup(const char *mapSetup, CMap &map, int writeTerrain, Vec2i newSize, Vec2i offset) { - FileWriter *f = NULL; + FileWriter *f = nullptr; try { f = CreateFileWriter(mapSetup); @@ -837,7 +837,7 @@ void CreateGame(const std::string &filename, CMap *map) if (SaveGameLoading) { SaveGameLoading = false; // Load game, already created game with Init/LoadModules - CommandLog(NULL, NoUnitP, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog(nullptr, NoUnitP, FlushCommands, -1, -1, NoUnitP, nullptr, -1); return; } @@ -1090,7 +1090,7 @@ void CreateGame(const std::string &filename, CMap *map) GameResult = GameNoResult; - CommandLog(NULL, NoUnitP, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog(nullptr, NoUnitP, FlushCommands, -1, -1, NoUnitP, nullptr, -1); Video.ClearScreen(); } @@ -1139,8 +1139,8 @@ void CleanGame() Map.Clean(); CleanReplayLog(); FreePathfinder(); - CursorBuilding = NULL; - UnitUnderCursor = NULL; + CursorBuilding = nullptr; + UnitUnderCursor = nullptr; GameEstablishing = false; } diff --git a/src/game/replay.cpp b/src/game/replay.cpp index 98569c42a..a0d95e6bc 100644 --- a/src/game/replay.cpp +++ b/src/game/replay.cpp @@ -73,7 +73,7 @@ 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(nullptr) { UnitNumber = 0; } @@ -99,7 +99,7 @@ class FullReplay { public: FullReplay() : - MapId(0), LocalPlayer(0), Commands(NULL) + MapId(0), LocalPlayer(0), Commands(nullptr) { ReplaySettings.Init(); memset(Engine, 0, sizeof(Engine)); @@ -395,7 +395,7 @@ void CommandLog(const char *action, const CUnit *unit, int flush, // don't retry for each command CommandLogDisabled = false; delete LogFile; - LogFile = NULL; + LogFile = nullptr; return; } LastLogFileName = path; @@ -533,7 +533,7 @@ static int CclReplayLog(lua_State *l) LuaError(l, "incorrect argument"); } - Assert(CurrentReplay == NULL); + Assert(CurrentReplay == nullptr); replay = new FullReplay; @@ -672,13 +672,13 @@ void EndReplayLog() if (LogFile) { LogFile->close(); delete LogFile; - LogFile = NULL; + LogFile = nullptr; } if (CurrentReplay) { DeleteReplay(CurrentReplay); - CurrentReplay = NULL; + CurrentReplay = nullptr; } - ReplayStep = NULL; + ReplayStep = nullptr; } /** @@ -690,7 +690,7 @@ void CleanReplayLog() DeleteReplay(CurrentReplay); CurrentReplay = nullptr; } - ReplayStep = NULL; + ReplayStep = nullptr; // if (DisabledLog) { CommandLogDisabled = false; @@ -720,8 +720,8 @@ static void DoNextReplay() const Vec2i pos(ReplayStep->PosX, ReplayStep->PosY); const int arg1 = ReplayStep->PosX; const int arg2 = ReplayStep->PosY; - CUnit *unit = unitSlot != -1 ? &UnitManager->GetSlotUnit(unitSlot) : NULL; - CUnit *dunit = (ReplayStep->DestUnitNumber != -1 ? &UnitManager->GetSlotUnit(ReplayStep->DestUnitNumber) : NULL); + CUnit *unit = unitSlot != -1 ? &UnitManager->GetSlotUnit(unitSlot) : nullptr; + CUnit *dunit = (ReplayStep->DestUnitNumber != -1 ? &UnitManager->GetSlotUnit(ReplayStep->DestUnitNumber) : nullptr); const char *val = ReplayStep->Value.c_str(); const int num = ReplayStep->Num; @@ -788,7 +788,7 @@ static void DoNextReplay() } else if (!strcmp(action, "train")) { SendCommandTrainUnit(*unit, *UnitTypeByIdent(val), flags); } else if (!strcmp(action, "cancel-train")) { - SendCommandCancelTraining(*unit, num, (val && *val) ? UnitTypeByIdent(val) : NULL); + SendCommandCancelTraining(*unit, num, (val && *val) ? UnitTypeByIdent(val) : nullptr); } else if (!strcmp(action, "upgrade-to")) { SendCommandUpgradeTo(*unit, *UnitTypeByIdent(val), flags); } else if (!strcmp(action, "cancel-upgrade-to")) { diff --git a/src/game/trigger.cpp b/src/game/trigger.cpp index 0c6be58c2..dffa067d3 100644 --- a/src/game/trigger.cpp +++ b/src/game/trigger.cpp @@ -150,7 +150,7 @@ static CompareFunction GetCompareFunction(const char *op) } else if (op[0] == '!' && op[1] == '=' && op[2] == '\0') { return &CompareNEq; } - return NULL; + return nullptr; } /** @@ -708,7 +708,7 @@ void CleanTriggers() Trigger = 0; delete[] ActiveTriggers; - ActiveTriggers = NULL; + ActiveTriggers = nullptr; GameTimer.Reset(); } diff --git a/src/include/action/action_attack.h b/src/include/action/action_attack.h index 192e2b8a6..803e54807 100644 --- a/src/include/action/action_attack.h +++ b/src/include/action/action_attack.h @@ -41,7 +41,7 @@ class COrder_Attack : public COrder friend COrder *COrder::NewActionAttackGround(const CUnit &attacker, const Vec2i &dest); public: explicit COrder_Attack(bool ground) : COrder(ground ? UnitActionAttackGround : UnitActionAttack), - State(0), MinRange(0), Range(0), SkirmishRange(0), offeredTarget(NULL), goalPos(-1, -1), attackMovePos(-1, -1), Sleep(0) {} + State(0), MinRange(0), Range(0), SkirmishRange(0), offeredTarget(nullptr), goalPos(-1, -1), attackMovePos(-1, -1), Sleep(0) {} virtual COrder_Attack *Clone() const { return new COrder_Attack(*this); } diff --git a/src/include/action/action_build.h b/src/include/action/action_build.h index 929ec3ace..96f693e4a 100644 --- a/src/include/action/action_build.h +++ b/src/include/action/action_build.h @@ -38,7 +38,7 @@ 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(nullptr), State(0), Range(0) { goalPos.x = -1; goalPos.y = -1; diff --git a/src/include/action/action_built.h b/src/include/action/action_built.h index abf2797ca..b0cadfb16 100644 --- a/src/include/action/action_built.h +++ b/src/include/action/action_built.h @@ -38,7 +38,7 @@ class COrder_Built : public COrder { friend COrder *COrder::NewActionBuilt(CUnit &builder, CUnit &unit); public: - COrder_Built() : COrder(UnitActionBuilt), ProgressCounter(0), IsCancelled(false), Frame(NULL) {} + COrder_Built() : COrder(UnitActionBuilt), ProgressCounter(0), IsCancelled(false), Frame(nullptr) {} ~COrder_Built(); virtual COrder_Built *Clone() const { return new COrder_Built(*this); } diff --git a/src/include/action/action_research.h b/src/include/action/action_research.h index 4a28b5ff9..616e38704 100644 --- a/src/include/action/action_research.h +++ b/src/include/action/action_research.h @@ -37,7 +37,7 @@ class COrder_Research : public COrder { public: - COrder_Research() : COrder(UnitActionResearch), Upgrade(NULL) {} + COrder_Research() : COrder(UnitActionResearch), Upgrade(nullptr) {} virtual COrder_Research *Clone() const { return new COrder_Research(*this); } diff --git a/src/include/action/action_spellcast.h b/src/include/action/action_spellcast.h index ff8832770..4e969aa52 100644 --- a/src/include/action/action_spellcast.h +++ b/src/include/action/action_spellcast.h @@ -38,7 +38,7 @@ class COrder_SpellCast : public COrder { friend COrder *COrder::NewActionSpellCast(const SpellType &spell, const Vec2i &pos, CUnit *target, bool isAutocast); public: - COrder_SpellCast(bool autocast = false) : COrder(UnitActionSpellCast), Spell(NULL), State(0), Range(0), isAutocast(autocast) + COrder_SpellCast(bool autocast = false) : COrder(UnitActionSpellCast), Spell(nullptr), State(0), Range(0), isAutocast(autocast) { goalPos.x = -1; goalPos.y = -1; diff --git a/src/include/action/action_train.h b/src/include/action/action_train.h index c7544c059..bcc0d1d7a 100644 --- a/src/include/action/action_train.h +++ b/src/include/action/action_train.h @@ -38,7 +38,7 @@ class COrder_Train : public COrder { friend COrder *COrder::NewActionTrain(CUnit &trainer, CUnitType &type); public: - COrder_Train() : COrder(UnitActionTrain), Type(NULL), Ticks(0) {} + COrder_Train() : COrder(UnitActionTrain), Type(nullptr), Ticks(0) {} virtual COrder_Train *Clone() const { return new COrder_Train(*this); } diff --git a/src/include/action/action_upgradeto.h b/src/include/action/action_upgradeto.h index 89e84f4c5..9fb3cb02b 100644 --- a/src/include/action/action_upgradeto.h +++ b/src/include/action/action_upgradeto.h @@ -38,7 +38,7 @@ class COrder_TransformInto : public COrder { friend COrder *COrder::NewActionTransformInto(CUnitType &type); public: - COrder_TransformInto() : COrder(UnitActionTransformInto), Type(NULL) {} + COrder_TransformInto() : COrder(UnitActionTransformInto), Type(nullptr) {} virtual COrder_TransformInto *Clone() const { return new COrder_TransformInto(*this); } @@ -60,7 +60,7 @@ class COrder_UpgradeTo : public COrder { friend COrder *COrder::NewActionUpgradeTo(CUnit &unit, CUnitType &type, bool instant); public: - COrder_UpgradeTo() : COrder(UnitActionUpgradeTo), Type(NULL), Ticks(0) {} + COrder_UpgradeTo() : COrder(UnitActionUpgradeTo), Type(nullptr), Ticks(0) {} virtual COrder_UpgradeTo *Clone() const { return new COrder_UpgradeTo(*this); } diff --git a/src/include/actions.h b/src/include/actions.h index adc26344c..5dba798c2 100644 --- a/src/include/actions.h +++ b/src/include/actions.h @@ -118,7 +118,7 @@ public: virtual void UpdatePathFinderData(PathFinderInput &input) = 0; - bool HasGoal() const { return Goal != NULL; } + bool HasGoal() const { return Goal != nullptr; } CUnit *GetGoal() const { return Goal; }; void SetGoal(CUnit *const new_goal); void ClearGoal(); diff --git a/src/include/animation.h b/src/include/animation.h index 34b0ba08b..849e20b3e 100644 --- a/src/include/animation.h +++ b/src/include/animation.h @@ -94,12 +94,12 @@ enum SetVar_ModifyTypes { class CAnimation { public: - CAnimation(AnimationType type) : Type(type), Next(NULL) {} + CAnimation(AnimationType type) : Type(type), Next(nullptr) {} virtual ~CAnimation() {} virtual void Action(CUnit &unit, int &move, int scale) const = 0; - virtual void Init(const char *s, lua_State *l = NULL) {} + virtual void Init(const char *s, lua_State *l = nullptr) {} const AnimationType Type; CAnimation *Next; @@ -108,9 +108,9 @@ public: class CAnimations { public: - CAnimations() : Attack(NULL), RangedAttack(NULL), Build(NULL), Move(NULL), Repair(NULL), - Research(NULL), SpellCast(NULL), Start(NULL), Still(NULL), - Train(NULL), Upgrade(NULL), hasDeathAnimation(false) + CAnimations() : Attack(nullptr), RangedAttack(nullptr), Build(nullptr), Move(nullptr), Repair(nullptr), + Research(nullptr), SpellCast(nullptr), Start(nullptr), Still(nullptr), + Train(nullptr), Upgrade(nullptr), hasDeathAnimation(false) { memset(Death, 0, sizeof(Death)); memset(Harvest, 0, sizeof(Harvest)); diff --git a/src/include/animation/animation_goto.h b/src/include/animation/animation_goto.h index 2ee8d7ca1..e0c797a9e 100644 --- a/src/include/animation/animation_goto.h +++ b/src/include/animation/animation_goto.h @@ -38,7 +38,7 @@ class CAnimation_Goto : public CAnimation { public: - CAnimation_Goto() : CAnimation(AnimationGoto), gotoLabel(NULL) {} + CAnimation_Goto() : CAnimation(AnimationGoto), gotoLabel(nullptr) {} virtual void Action(CUnit &unit, int &move, int scale) const; virtual void Init(const char *s, lua_State *l); diff --git a/src/include/animation/animation_ifvar.h b/src/include/animation/animation_ifvar.h index a24225691..c23b7fd0a 100644 --- a/src/include/animation/animation_ifvar.h +++ b/src/include/animation/animation_ifvar.h @@ -38,7 +38,7 @@ class CAnimation_IfVar : public CAnimation { public: - CAnimation_IfVar() : CAnimation(AnimationIfVar), binOpFunc(NULL), gotoLabel(NULL) {} + CAnimation_IfVar() : CAnimation(AnimationIfVar), binOpFunc(nullptr), gotoLabel(nullptr) {} virtual void Action(CUnit &unit, int &move, int scale) const; virtual void Init(const char *s, lua_State *l); diff --git a/src/include/animation/animation_luacallback.h b/src/include/animation/animation_luacallback.h index 92f0d7d59..0aee263fd 100644 --- a/src/include/animation/animation_luacallback.h +++ b/src/include/animation/animation_luacallback.h @@ -40,7 +40,7 @@ class CAnimation_LuaCallback : public CAnimation { public: - CAnimation_LuaCallback() : CAnimation(AnimationLuaCallback), cb(NULL) {} + CAnimation_LuaCallback() : CAnimation(AnimationLuaCallback), cb(nullptr) {} ~CAnimation_LuaCallback() { delete cb; } virtual void Action(CUnit &unit, int &move, int scale) const; diff --git a/src/include/animation/animation_randomgoto.h b/src/include/animation/animation_randomgoto.h index 1b47b845c..851a7b083 100644 --- a/src/include/animation/animation_randomgoto.h +++ b/src/include/animation/animation_randomgoto.h @@ -38,7 +38,7 @@ class CAnimation_RandomGoto : public CAnimation { public: - CAnimation_RandomGoto() : CAnimation(AnimationRandomGoto), gotoLabel(NULL) {} + CAnimation_RandomGoto() : CAnimation(AnimationRandomGoto), gotoLabel(nullptr) {} virtual void Action(CUnit &unit, int &move, int scale) const; virtual void Init(const char *s, lua_State *l); diff --git a/src/include/animation/animation_wiggle.h b/src/include/animation/animation_wiggle.h index d77fa3914..217952fba 100644 --- a/src/include/animation/animation_wiggle.h +++ b/src/include/animation/animation_wiggle.h @@ -38,7 +38,7 @@ class CAnimation_Wiggle : public CAnimation { public: - CAnimation_Wiggle() : CAnimation(AnimationWiggle), isHeading(false), isZDisplacement(false), speed(""), ifNotReached(NULL) {} + CAnimation_Wiggle() : CAnimation(AnimationWiggle), isHeading(false), isZDisplacement(false), speed(""), ifNotReached(nullptr) {} virtual void Action(CUnit &unit, int &move, int scale) const; virtual void Init(const char *s, lua_State *l); diff --git a/src/include/construct.h b/src/include/construct.h index 73f5faf2d..e27f2b6d8 100644 --- a/src/include/construct.h +++ b/src/include/construct.h @@ -113,7 +113,7 @@ class CConstructionFrame { public: CConstructionFrame() : Percent(0), File(ConstructionFileConstruction), - Frame(0), Next(NULL) {} + Frame(0), Next(nullptr) {} int Percent; /// Percent complete ConstructionFileType File; /// Graphic to use @@ -125,8 +125,8 @@ public: class CConstruction { public: - CConstruction() : Frames(NULL), Sprite(NULL), Width(0), - Height(0), ShadowSprite(NULL), ShadowWidth(0), ShadowHeight(0) + CConstruction() : Frames(nullptr), Sprite(nullptr), Width(0), + Height(0), ShadowSprite(nullptr), ShadowWidth(0), ShadowHeight(0) { File.Width = 0; File.Height = 0; diff --git a/src/include/cursor.h b/src/include/cursor.h index b530609f2..2b06c196b 100644 --- a/src/include/cursor.h +++ b/src/include/cursor.h @@ -56,7 +56,7 @@ ** CCursor::Race ** ** Owning Race of this cursor ("human", "orc", "alliance", -** "mythical", ...). If NULL, this cursor could be used by any +** "mythical", ...). If nullptr, this cursor could be used by any ** race. ** ** CCursor::HotPos @@ -125,7 +125,7 @@ class CCursor { public: CCursor() : HotPos(0, 0), - SpriteFrame(0), FrameRate(0), G(NULL) {} + SpriteFrame(0), FrameRate(0), G(nullptr) {} ~CCursor(); @@ -153,7 +153,7 @@ private: class CursorConfig { public: - CursorConfig() : Cursor(NULL) {} + CursorConfig() : Cursor(nullptr) {} void Load(); diff --git a/src/include/font.h b/src/include/font.h index 2c6e42116..10df64f47 100644 --- a/src/include/font.h +++ b/src/include/font.h @@ -75,8 +75,8 @@ class CFont : public gcn::Font private: explicit CFont(const std::string &ident) : Ident(ident), - CharWidth(NULL), - G(NULL) + CharWidth(nullptr), + G(nullptr) {} public: diff --git a/src/include/icons.h b/src/include/icons.h index 95f81557b..7683cbb71 100644 --- a/src/include/icons.h +++ b/src/include/icons.h @@ -172,7 +172,7 @@ private: class IconConfig { public: - IconConfig() : Icon(NULL) {} + IconConfig() : Icon(nullptr) {} bool LoadNoLog(); bool Load(); diff --git a/src/include/interface.h b/src/include/interface.h index f9e6a75e1..0169bc856 100644 --- a/src/include/interface.h +++ b/src/include/interface.h @@ -88,8 +88,8 @@ typedef bool (*ButtonCheckFunc)(const CUnit &, const ButtonAction &); class ButtonAction { public: - ButtonAction() : Pos(0), Level(0), AlwaysShow(false), Action(ButtonMove), Value(0), Payload(NULL), - Allowed(NULL), Key(0) {} + ButtonAction() : Pos(0), Level(0), AlwaysShow(false), Action(ButtonMove), Value(0), Payload(nullptr), + Allowed(nullptr), Key(0) {} int Pos; /// button position in the grid int Level; /// requires button level diff --git a/src/include/missile.h b/src/include/missile.h index b23e2562f..e53d48e8a 100644 --- a/src/include/missile.h +++ b/src/include/missile.h @@ -424,7 +424,7 @@ public: void DrawMissile(const CViewport &vp) const; void SaveMissile(CFile &file) const; - void MissileHit(CUnit *unit = NULL); + void MissileHit(CUnit *unit = nullptr); bool NextMissileFrame(char sign, char longAnimation); void NextMissileFrameCycle(); void MissileNewHeadingFromXY(const PixelPos &delta); @@ -566,7 +566,7 @@ public: class BurningBuildingFrame { public: - BurningBuildingFrame() : Percent(0), Missile(NULL) {}; + BurningBuildingFrame() : Percent(0), Missile(nullptr) {}; int Percent; /// HP percent MissileType *Missile; /// Missile to draw diff --git a/src/include/missileconfig.h b/src/include/missileconfig.h index fb2e6ae08..5906a809d 100644 --- a/src/include/missileconfig.h +++ b/src/include/missileconfig.h @@ -44,7 +44,7 @@ class MissileType; class MissileConfig { public: - MissileConfig() : Missile(NULL) {} + MissileConfig() : Missile(nullptr) {} bool MapMissileNoLog(); bool MapMissile(); diff --git a/src/include/movie.h b/src/include/movie.h index b3a92596f..c9c8a1855 100644 --- a/src/include/movie.h +++ b/src/include/movie.h @@ -87,8 +87,8 @@ struct OggData { class Movie : public gcn::Image { public: - Movie() : rect(NULL), yuv_overlay(NULL), surface(NULL), need_data(true), start_time(0), - is_dirty(true), Width(0), Height(0), data(NULL), f(NULL) {}; + Movie() : rect(nullptr), yuv_overlay(nullptr), surface(nullptr), need_data(true), start_time(0), + is_dirty(true), Width(0), Height(0), data(nullptr), f(nullptr) {}; ~Movie(); bool Load(const std::string &filename, int w, int h); bool IsPlaying() const { return is_dirty; } @@ -138,7 +138,7 @@ public: bool Load(const std::string &filename, int w, int h) { return false; }; bool IsPlaying() const { return false; }; //guichan - virtual void *_getData() const { return NULL; }; + virtual void *_getData() const { return nullptr; }; virtual int getWidth() const { return 0; }; virtual int getHeight() const { return 0; }; virtual bool isDirty() const { return false; }; diff --git a/src/include/sound.h b/src/include/sound.h index 8504ab14d..d9ae4f9ff 100644 --- a/src/include/sound.h +++ b/src/include/sound.h @@ -174,7 +174,7 @@ extern void PlayMissileSound(const Missile &missile, CSound *sound); extern void PlayGameSound(CSound *sound, unsigned char volume, bool always = false); /// Play a sound file -extern int PlayFile(const std::string &name, LuaActionListener *listener = NULL); +extern int PlayFile(const std::string &name, LuaActionListener *listener = nullptr); /// Modify the range of a given sound. extern void SetSoundRange(CSound *sound, unsigned char range); diff --git a/src/include/sound_server.h b/src/include/sound_server.h index 0088b596d..e16fa96e7 100644 --- a/src/include/sound_server.h +++ b/src/include/sound_server.h @@ -71,7 +71,7 @@ extern Mix_Music *LoadMusic(const std::string &name); extern Mix_Chunk *LoadSample(const std::string &name); extern void FreeSample(Mix_Chunk *sample); /// Play a sample -extern int PlaySample(Mix_Chunk *sample, Origin *origin = NULL); +extern int PlaySample(Mix_Chunk *sample, Origin *origin = nullptr); /// Play a sample, registering a "finished" callback extern int PlaySample(Mix_Chunk *sample, void (*callback)(int channel)); /// Play a sound file diff --git a/src/include/spell/spell_adjustvariable.h b/src/include/spell/spell_adjustvariable.h index 2e1233547..eb5c5a886 100644 --- a/src/include/spell/spell_adjustvariable.h +++ b/src/include/spell/spell_adjustvariable.h @@ -68,7 +68,7 @@ public: class Spell_AdjustVariable : public SpellActionType { public: - Spell_AdjustVariable() : Var(NULL) {}; + Spell_AdjustVariable() : Var(nullptr) {}; ~Spell_AdjustVariable() { delete [](this->Var); }; virtual int Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos); diff --git a/src/include/spell/spell_areabombardment.h b/src/include/spell/spell_areabombardment.h index e157cb2be..2339135ec 100644 --- a/src/include/spell/spell_areabombardment.h +++ b/src/include/spell/spell_areabombardment.h @@ -42,7 +42,7 @@ class Spell_AreaBombardment : public SpellActionType { public: Spell_AreaBombardment() : Fields(0), Shards(0), Damage(0), - StartOffsetX(0), StartOffsetY(0), Missile(NULL) {}; + StartOffsetX(0), StartOffsetY(0), Missile(nullptr) {}; virtual int Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_luacallback.h b/src/include/spell/spell_luacallback.h index 2253596f2..d5c0bd097 100644 --- a/src/include/spell/spell_luacallback.h +++ b/src/include/spell/spell_luacallback.h @@ -42,7 +42,7 @@ class Spell_LuaCallback : public SpellActionType { public: - Spell_LuaCallback() : Func(NULL) {}; + Spell_LuaCallback() : Func(nullptr) {}; ~Spell_LuaCallback() { delete Func; }; virtual int Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos); diff --git a/src/include/spell/spell_polymorph.h b/src/include/spell/spell_polymorph.h index cc7ec1102..24b2c0d5d 100644 --- a/src/include/spell/spell_polymorph.h +++ b/src/include/spell/spell_polymorph.h @@ -41,7 +41,7 @@ class Spell_Polymorph : public SpellActionType { public: - Spell_Polymorph() : SpellActionType(1), NewForm(NULL), PlayerNeutral(0) {}; + Spell_Polymorph() : SpellActionType(1), NewForm(nullptr), PlayerNeutral(0) {}; virtual int Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_summon.h b/src/include/spell/spell_summon.h index d5bd80525..3927b99a4 100644 --- a/src/include/spell/spell_summon.h +++ b/src/include/spell/spell_summon.h @@ -41,7 +41,7 @@ class Spell_Summon : public SpellActionType { public: - Spell_Summon() : SpellActionType(1), UnitType(NULL), TTL(0), + Spell_Summon() : SpellActionType(1), UnitType(nullptr), TTL(0), RequireCorpse(false), JoinToAiForce(false) {}; virtual int Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos); diff --git a/src/include/spells.h b/src/include/spells.h index a234af63a..a812d94b4 100644 --- a/src/include/spells.h +++ b/src/include/spells.h @@ -137,7 +137,7 @@ class ConditionInfo { public: ConditionInfo() : Alliance(0), Opponent(0), TargetSelf(1), - BoolFlag(NULL), Variable(NULL), CheckFunc(NULL) {}; + BoolFlag(nullptr), Variable(nullptr), CheckFunc(nullptr) {}; ~ConditionInfo() { delete[] BoolFlag; @@ -173,8 +173,8 @@ public: // Special flags for priority sorting #define ACP_NOVALUE -1 #define ACP_DISTANCE -2 - AutoCastInfo() : Range(0), MinRange(0), PriorytyVar(ACP_NOVALUE), ReverseSort(false), Condition(NULL), - Combat(0), Attacker(0), Corpse(CONDITION_FALSE), PositionAutoCast(NULL) {}; + AutoCastInfo() : Range(0), MinRange(0), PriorytyVar(ACP_NOVALUE), ReverseSort(false), Condition(nullptr), + Combat(0), Attacker(0), Corpse(CONDITION_FALSE), PositionAutoCast(nullptr) {}; ~AutoCastInfo() { delete Condition; diff --git a/src/include/st_backtrace.h b/src/include/st_backtrace.h index 92745700d..bde8b3087 100644 --- a/src/include/st_backtrace.h +++ b/src/include/st_backtrace.h @@ -32,8 +32,8 @@ inline void print_backtrace(int sz = 100) { char* name; process = GetCurrentProcess(); - SymInitialize(process, NULL, TRUE); - frames = CaptureStackBackTrace(0, sz, stack, NULL); + SymInitialize(process, nullptr, TRUE); + frames = CaptureStackBackTrace(0, sz, stack, nullptr); fprintf(stderr, "backtrace returned %d addresses\n", frames); symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 1024 * sizeof(char), 1); symbol->MaxNameLen = 1024; diff --git a/src/include/title.h b/src/include/title.h index 2b46e0fd5..e367545ab 100644 --- a/src/include/title.h +++ b/src/include/title.h @@ -55,7 +55,7 @@ public: class TitleScreen { public: - TitleScreen() : StretchImage(true), Timeout(0), Iterations(0), Editor(0), Labels(NULL) {} + TitleScreen() : StretchImage(true), Timeout(0), Iterations(0), Editor(0), Labels(nullptr) {} ~TitleScreen() { if (this->Labels) { diff --git a/src/include/ui.h b/src/include/ui.h index f662baa96..afac06024 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -85,7 +85,7 @@ enum TextAlignment { class ButtonStyleProperties { public: - ButtonStyleProperties() : Sprite(NULL), Frame(0), BorderColor(0), + ButtonStyleProperties() : Sprite(nullptr), Frame(0), BorderColor(0), BorderSize(0), TextAlign(TextAlignUndefined), TextPos(0, 0) {} @@ -124,9 +124,9 @@ public: class CUIButton { public: - CUIButton() : X(0), Y(0), Style(NULL), Callback(NULL) {} //OLD BUTTON STYLE CODE + CUIButton() : X(0), Y(0), Style(nullptr), Callback(nullptr) {} //OLD BUTTON STYLE CODE // NEW CODE BELOW, THANKS TO ANDRETTIN - MODIFIED BY DINKY - // CUIButton() : X(0), Y(0), Clicked(false), HotKeyPressed(false), Style(NULL), Callback(NULL) {} + // CUIButton() : X(0), Y(0), Clicked(false), HotKeyPressed(false), Style(nullptr), Callback(nullptr) {} ~CUIButton() {} bool Contains(const PixelPos &screenPos) const; @@ -186,8 +186,8 @@ class ConditionPanel { public: ConditionPanel() : ShowOnlySelected(false), HideNeutral(false), - HideAllied(false), ShowOpponent(false), BoolFlags(NULL), - Variables(NULL) {} + HideAllied(false), ShowOpponent(false), BoolFlags(nullptr), + Variables(nullptr) {} ~ConditionPanel() { delete[] BoolFlags; @@ -211,7 +211,7 @@ class CUnitInfoPanel { public: CUnitInfoPanel() : PosX(0), PosY(0), DefaultFont(0), - Contents(), Condition(NULL) {} + Contents(), Condition(nullptr) {} ~CUnitInfoPanel(); public: @@ -222,14 +222,14 @@ public: std::vectorContents; /// Array of contents to display. - ConditionPanel *Condition; /// Condition to show the panel; if NULL, no condition. + ConditionPanel *Condition; /// Condition to show the panel; if nullptr, no condition. }; class CFiller { struct bits_map { - bits_map() : Width(0), Height(0), bstore(NULL) {} + bits_map() : Width(0), Height(0), bstore(nullptr) {} ~bits_map(); void Init(CGraphic *g); @@ -253,7 +253,7 @@ class CFiller bits_map map; public: - CFiller() : G(NULL), X(0), Y(0) {} + CFiller() : G(nullptr), X(0), Y(0) {} void Load(); @@ -274,7 +274,7 @@ public: class CButtonPanel { public: - CButtonPanel() : G(NULL), X(0), Y(0), ShowCommandKey(true) + CButtonPanel() : G(nullptr), X(0), Y(0), ShowCommandKey(true) {} void Draw(); @@ -315,7 +315,7 @@ public: class CPieMenu { public: - CPieMenu() : G(NULL), MouseButton(NoButton) + CPieMenu() : G(nullptr), MouseButton(NoButton) { memset(this->X, 0, sizeof(this->X)); memset(this->Y, 0, sizeof(this->Y)); @@ -340,7 +340,7 @@ public: class CResourceInfo { public: - CResourceInfo() : G(NULL), IconFrame(0), IconX(0), IconY(0), IconWidth(-1), + CResourceInfo() : G(nullptr), IconFrame(0), IconX(0), IconY(0), IconWidth(-1), TextX(-1), TextY(-1) {} CGraphic *G; /// icon graphic @@ -356,7 +356,7 @@ public: class CInfoPanel { public: - CInfoPanel() : G(NULL), X(0), Y(0) {} + CInfoPanel() : G(nullptr), X(0), Y(0) {} void Draw(); diff --git a/src/include/ui/contenttype.h b/src/include/ui/contenttype.h index d6cf15531..16a58abe8 100644 --- a/src/include/ui/contenttype.h +++ b/src/include/ui/contenttype.h @@ -47,7 +47,7 @@ class ConditionPanel; class CContentType { public: - CContentType() : Pos(0, 0), Condition(NULL) {} + CContentType() : Pos(0, 0), Condition(nullptr) {} virtual ~CContentType(); /// Tell how show the variable Index. @@ -57,7 +57,7 @@ public: public: PixelPos Pos; /// Coordinate where to display. - ConditionPanel *Condition; /// Condition to show the content; if NULL, no condition. + ConditionPanel *Condition; /// Condition to show the content; if nullptr, no condition. }; /** @@ -66,7 +66,7 @@ public: class CContentTypeText : public CContentType { public: - CContentTypeText() : Text(NULL), Font(NULL), Centered(0), Index(-1), + CContentTypeText() : Text(nullptr), Font(nullptr), Centered(0), Index(-1), Component(VariableValue), ShowName(0), Stat(0) {} virtual ~CContentTypeText() { @@ -93,7 +93,7 @@ private: class CContentTypeFormattedText : public CContentType { public: - CContentTypeFormattedText() : Font(NULL), Centered(false), + CContentTypeFormattedText() : Font(nullptr), Centered(false), Index(-1), Component(VariableValue) {} virtual ~CContentTypeFormattedText() {} @@ -114,7 +114,7 @@ private: class CContentTypeFormattedText2 : public CContentType { public: - CContentTypeFormattedText2() : Font(NULL), Centered(false), + CContentTypeFormattedText2() : Font(nullptr), Centered(false), Index1(-1), Component1(VariableValue), Index2(-1), Component2(VariableValue) {} virtual ~CContentTypeFormattedText2() {} @@ -168,7 +168,7 @@ private: class CContentTypeLifeBar : public CContentType { public: - CContentTypeLifeBar() : Index(-1), ValueFunc(NULL), ValueMax(-1), Width(0), Height(0), hasBorder(1), colors(NULL), values(NULL) {} + CContentTypeLifeBar() : Index(-1), ValueFunc(nullptr), ValueMax(-1), Width(0), Height(0), hasBorder(1), colors(nullptr), values(nullptr) {} virtual ~CContentTypeLifeBar() { FreeNumberDesc(ValueFunc); diff --git a/src/include/ui/popup.h b/src/include/ui/popup.h index a0f928610..e805d79c3 100644 --- a/src/include/ui/popup.h +++ b/src/include/ui/popup.h @@ -53,7 +53,7 @@ class PopupConditionPanel { public: PopupConditionPanel() : HasHint(false), HasDescription(false), HasDependencies(false), - ButtonAction(-1), BoolFlags(NULL), Variables(NULL) {} + ButtonAction(-1), BoolFlags(nullptr), Variables(nullptr) {} ~PopupConditionPanel() { delete[] BoolFlags; @@ -75,7 +75,7 @@ class CPopupContentType public: CPopupContentType() : pos(0, 0), MarginX(MARGIN_X), MarginY(MARGIN_Y), minSize(0, 0), - Wrap(true), Condition(NULL) {} + Wrap(true), Condition(nullptr) {} virtual ~CPopupContentType() { delete Condition; } /// Tell how show the variable Index. @@ -100,7 +100,7 @@ protected: std::string TextColor; /// Color used for plain text in content. std::string HighlightColor; /// Color used for highlighted letters. public: - PopupConditionPanel *Condition; /// Condition to show the content; if NULL, no condition. + PopupConditionPanel *Condition; /// Condition to show the content; if nullptr, no condition. }; enum PopupButtonInfo_Types { @@ -112,7 +112,7 @@ enum PopupButtonInfo_Types { class CPopupContentTypeButtonInfo : public CPopupContentType { public: - CPopupContentTypeButtonInfo() : InfoType(0), MaxWidth(0), Font(NULL) {} + CPopupContentTypeButtonInfo() : InfoType(0), MaxWidth(0), Font(nullptr) {} virtual ~CPopupContentTypeButtonInfo() {} virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const; @@ -131,7 +131,7 @@ private: class CPopupContentTypeText : public CPopupContentType { public: - CPopupContentTypeText() : MaxWidth(0), Font(NULL) {} + CPopupContentTypeText() : MaxWidth(0), Font(nullptr) {} virtual ~CPopupContentTypeText() {} virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const; @@ -150,7 +150,7 @@ private: class CPopupContentTypeCosts : public CPopupContentType { public: - CPopupContentTypeCosts() : Font(NULL), Centered(0) {} + CPopupContentTypeCosts() : Font(nullptr), Centered(0) {} virtual ~CPopupContentTypeCosts() {} virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const; @@ -187,7 +187,7 @@ private: class CPopupContentTypeVariable : public CPopupContentType { public: - CPopupContentTypeVariable() : Text(NULL), Font(NULL), Centered(0), Index(-1) {} + CPopupContentTypeVariable() : Text(nullptr), Font(nullptr), Centered(0), Index(-1) {} virtual ~CPopupContentTypeVariable() { FreeStringDesc(Text); diff --git a/src/include/ui/uitimer.h b/src/include/ui/uitimer.h index ed20fb656..4b4bbbddf 100644 --- a/src/include/ui/uitimer.h +++ b/src/include/ui/uitimer.h @@ -37,7 +37,7 @@ class CFont; class CUITimer { public: - CUITimer() : X(0), Y(0), Font(NULL) {} + CUITimer() : X(0), Y(0), Font(nullptr) {} void Draw(int second) const; diff --git a/src/include/unit.h b/src/include/unit.h index cb6f3ad70..139a24f83 100644 --- a/src/include/unit.h +++ b/src/include/unit.h @@ -135,8 +135,8 @@ enum _directions_ { class CUnit { public: - CUnit() : tilePos(-1, -1), pathFinderData(NULL), SavedOrder(NULL), NewOrder(NULL), CriticalOrder(NULL), Colors(-1), - AutoCastSpell(NULL), SpellCoolDownTimers(NULL), Variable(NULL) { Init(); } + CUnit() : tilePos(-1, -1), pathFinderData(nullptr), SavedOrder(nullptr), NewOrder(nullptr), CriticalOrder(nullptr), Colors(-1), + AutoCastSpell(nullptr), SpellCoolDownTimers(nullptr), Variable(nullptr) { Init(); } ~CUnit(); void Init(); @@ -388,11 +388,11 @@ public: unsigned TeamSelected; /// unit is selected by a team member. CPlayer *RescuedFrom; /// The original owner of a rescued unit. - /// NULL if the unit was not rescued. + /// nullptr if the unit was not rescued. /* Seen stuff. */ int VisCount[PlayerMax]; /// Unit visibility counts struct _seen_stuff_ { - _seen_stuff_() : CFrame(NULL), Type(NULL), tilePos(-1, -1) {} + _seen_stuff_() : CFrame(nullptr), Type(nullptr), tilePos(-1, -1) {} const CConstructionFrame *CFrame; /// Seen construction frame int Frame; /// last seen frame/stage of buildings const CUnitType *Type; /// Pointer to last seen unit-type @@ -455,7 +455,7 @@ public: IconsShift(false), StereoSound(true), MineNotifications(false), DeselectInMine(false), NoStatusLineTooltips(false), SelectionRectangleIndicatesDamage(false), FormationMovement(true), - IconFrameG(NULL), PressedIconFrameG(NULL), HardwareCursor(false), + IconFrameG(nullptr), PressedIconFrameG(nullptr), HardwareCursor(false), ShowOrders(0), ShowNameDelay(0), ShowNameTime(0), AutosaveMinutes(5) {}; bool ShowSightRange; /// Show sight range. @@ -633,7 +633,7 @@ extern Vec2i GetRndPosInDirection(const Vec2i &srcPos, const Vec2i &dirPos, cons /// Hit unit with damage, if destroyed give attacker the points -extern void HitUnit(CUnit *attacker, CUnit &target, int damage, const Missile *missile = NULL); +extern void HitUnit(CUnit *attacker, CUnit &target, int damage, const Missile *missile = nullptr); /// Calculate the distance from current view point to coordinate extern int ViewPointDistance(const Vec2i &pos); diff --git a/src/include/unit_cache.h b/src/include/unit_cache.h index 56b63745d..cf0e88a62 100644 --- a/src/include/unit_cache.h +++ b/src/include/unit_cache.h @@ -80,14 +80,14 @@ public: * @brief Find the first unit in a tile cache for which a predicate is true. * @param pred A predicate object vith bool operator()(const CUnit *). * @return The first unit u in the cache - * such that @p pred(u) is true, or NULL if no such unit exists. + * such that @p pred(u) is true, or nullptr if no such unit exists. */ template CUnit *find(const _T &pred) const { std::vector::const_iterator ret = std::find_if(Units.begin(), Units.end(), pred); - return ret != Units.end() ? (*ret) : NULL; + return ret != Units.end() ? (*ret) : nullptr; } /** diff --git a/src/include/unit_find.h b/src/include/unit_find.h index b3bd15ab8..5af9f0fa3 100644 --- a/src/include/unit_find.h +++ b/src/include/unit_find.h @@ -305,7 +305,7 @@ CUnit *FindUnit_IfFixed(const Vec2i <Pos, const Vec2i &rbPos, Pred pred) } } } - return NULL; + return nullptr; } template @@ -320,7 +320,7 @@ CUnit *FindUnit_If(const Vec2i <Pos, const Vec2i &rbPos, Pred pred) /// Find resource extern CUnit *UnitFindResource(const CUnit &unit, const CUnit &startUnit, int range, - int resource, bool check_usage = false, const CUnit *deposit = NULL); + int resource, bool check_usage = false, const CUnit *deposit = nullptr); /// Find nearest deposit extern CUnit *FindDeposit(const CUnit &unit, int range, int resource); @@ -346,7 +346,7 @@ extern CUnit *ResourceOnMap(const Vec2i &pos, int resource, bool mine_on_top = t extern CUnit *ResourceDepositOnMap(const Vec2i &pos, int resource); /// Check map for obstacles in a line between 2 tiles -extern bool CheckObstaclesBetweenTiles(const Vec2i &unitPos, const Vec2i &goalPos, unsigned short flags, int *distance = NULL); +extern bool CheckObstaclesBetweenTiles(const Vec2i &unitPos, const Vec2i &goalPos, unsigned short flags, int *distance = nullptr); /// Find best enemy in numeric range to attack extern CUnit *AttackUnitsInDistance(const CUnit &unit, int range, CUnitFilter pred); extern CUnit *AttackUnitsInDistance(const CUnit &unit, int range); diff --git a/src/include/unitptr.h b/src/include/unitptr.h index e7bbf32a5..e3a31746c 100644 --- a/src/include/unitptr.h +++ b/src/include/unitptr.h @@ -41,7 +41,7 @@ class CUnit; class CUnitPtr { public: - CUnitPtr() : unit(NULL) {} + CUnitPtr() : unit(nullptr) {} CUnitPtr(CUnit *u); CUnitPtr(const CUnitPtr &u); ~CUnitPtr() { Reset(); } diff --git a/src/include/unitsound.h b/src/include/unitsound.h index 773e3112d..5b0af7a5d 100644 --- a/src/include/unitsound.h +++ b/src/include/unitsound.h @@ -54,8 +54,8 @@ class CSound; class SoundConfig { public: - SoundConfig() : Sound(NULL) {} - SoundConfig(std::string name) : Name(name), Sound(NULL) {} + SoundConfig() : Sound(nullptr) {} + SoundConfig(std::string name) : Name(name), Sound(nullptr) {} bool MapSound(); void SetSoundRange(unsigned char range); diff --git a/src/include/unittype.h b/src/include/unittype.h index 77badcf33..fedf7b488 100644 --- a/src/include/unittype.h +++ b/src/include/unittype.h @@ -89,7 +89,7 @@ public: ResourceInfo() : WaitAtResource(0), ResourceStep(0), ResourceCapacity(0), WaitAtDepot(0), ResourceId(0), FinalResource(0), TerrainHarvester(0), LoseResources(0), HarvestFromOutside(0), - SpriteWhenLoaded(NULL), SpriteWhenEmpty(NULL) + SpriteWhenLoaded(nullptr), SpriteWhenEmpty(nullptr) {} std::string FileWhenLoaded; /// Change the graphic when the unit is loaded. @@ -310,7 +310,7 @@ public: class CDecoVarText : public CDecoVar { public: - CDecoVarText() : Font(NULL) {}; + CDecoVarText() : Font(nullptr) {}; /// function to draw the decorations. virtual void Draw(int x, int y, const CUnitType &type, const CVariable &var) const; @@ -420,7 +420,7 @@ class CBuildRestrictionAddOn : public CBuildRestriction const Vec2i pos; //functor work position }; public: - CBuildRestrictionAddOn() : Offset(0, 0), Parent(NULL) {} + CBuildRestrictionAddOn() : Offset(0, 0), Parent(nullptr) {} virtual ~CBuildRestrictionAddOn() {} virtual void Init() {this->Parent = UnitTypeByIdent(this->ParentName);} virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const; @@ -443,7 +443,7 @@ class CBuildRestrictionOnTop : public CBuildRestriction const Vec2i pos; //functor work position }; public: - CBuildRestrictionOnTop() : Parent(NULL), ReplaceOnDie(0), ReplaceOnBuild(0) {}; + CBuildRestrictionOnTop() : Parent(nullptr), ReplaceOnDie(0), ReplaceOnBuild(0) {}; virtual ~CBuildRestrictionOnTop() {}; virtual void Init() {this->Parent = UnitTypeByIdent(this->ParentName);}; virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const; @@ -457,7 +457,7 @@ public: class CBuildRestrictionDistance : public CBuildRestriction { public: - CBuildRestrictionDistance() : Distance(0), CheckBuilder(false), RestrictType(NULL), Diagonal(true) {}; + CBuildRestrictionDistance() : Distance(0), CheckBuilder(false), RestrictType(nullptr), Diagonal(true) {}; virtual ~CBuildRestrictionDistance() {}; virtual void Init() {this->RestrictType = UnitTypeByIdent(this->RestrictTypeName);}; virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const; @@ -474,7 +474,7 @@ public: class CBuildRestrictionHasUnit : public CBuildRestriction { public: - CBuildRestrictionHasUnit() : Count(0), RestrictType(NULL) {}; + CBuildRestrictionHasUnit() : Count(0), RestrictType(nullptr) {}; virtual ~CBuildRestrictionHasUnit() {}; virtual void Init() { this->RestrictType = UnitTypeByIdent(this->RestrictTypeName); }; virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const; @@ -489,7 +489,7 @@ public: class CBuildRestrictionSurroundedBy : public CBuildRestriction { public: - CBuildRestrictionSurroundedBy() : Count(0), Distance(0), DistanceType(Equal), CountType(Equal), RestrictType(NULL), CheckBuilder(false) {}; + CBuildRestrictionSurroundedBy() : Count(0), Distance(0), DistanceType(Equal), CountType(Equal), RestrictType(nullptr), CheckBuilder(false) {}; virtual ~CBuildRestrictionSurroundedBy() {}; virtual void Init() { this->RestrictType = UnitTypeByIdent(this->RestrictTypeName); }; virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const; @@ -744,7 +744,7 @@ public: return ((*it).first).c_str(); } } - return NULL; + return nullptr; } /** diff --git a/src/include/upgrade_structs.h b/src/include/upgrade_structs.h index 0aa1614a5..fdf6961da 100644 --- a/src/include/upgrade_structs.h +++ b/src/include/upgrade_structs.h @@ -129,7 +129,7 @@ extern int GetResourceIdByName(lua_State *l, const char *resourceName); class CUnitStats { public: - CUnitStats() : Variables(NULL) + CUnitStats() : Variables(nullptr) { memset(Costs, 0, sizeof(Costs)); memset(Storing, 0, sizeof(Storing)); @@ -182,7 +182,7 @@ public: class CUpgradeModifier { public: - CUpgradeModifier() : UpgradeId(0), ModifyPercent(NULL), SpeedResearch(0), ConvertTo(NULL) + CUpgradeModifier() : UpgradeId(0), ModifyPercent(nullptr), SpeedResearch(0), ConvertTo(nullptr) { memset(ChangeUnits, 0, sizeof(ChangeUnits)); memset(ChangeUpgrades, 0, sizeof(ChangeUpgrades)); diff --git a/src/include/video.h b/src/include/video.h index a91a0c038..badc68584 100644 --- a/src/include/video.h +++ b/src/include/video.h @@ -99,11 +99,11 @@ public: }; protected: - CGraphic() : Surface(NULL), SurfaceFlip(NULL), frame_map(NULL), + CGraphic() : Surface(nullptr), SurfaceFlip(nullptr), frame_map(nullptr), Width(0), Height(0), NumFrames(1), GraphicWidth(0), GraphicHeight(0), Refs(1), Resized(false) { - frameFlip_map = NULL; + frameFlip_map = nullptr; } ~CGraphic() {} @@ -177,7 +177,7 @@ public: // minor programmatic editing features void OverlayGraphic(CGraphic *other, bool mask = false); - inline bool IsLoaded(bool flipped = false) const { return Surface != NULL && (!flipped || SurfaceFlip != NULL); } + inline bool IsLoaded(bool flipped = false) const { return Surface != nullptr && (!flipped || SurfaceFlip != nullptr); } //guichan virtual void *_getData() const { return Surface; } @@ -277,14 +277,14 @@ class Mng : public gcn::Image Mng() {}; ~Mng() {}; public: - static Mng *New(const std::string &name) { return NULL; } + static Mng *New(const std::string &name) { return nullptr; } static void Free(Mng *mng) {}; bool Load() { return false; }; void Reset() {}; void Draw(int x, int y) {}; //guichan - virtual void *_getData() const { return NULL; }; + virtual void *_getData() const { return nullptr; }; virtual int getWidth() const { return 0; }; virtual int getHeight() const { return 0; }; virtual bool isDirty() const { return false; }; @@ -536,11 +536,11 @@ inline Uint32 IndexToColor(unsigned int index) { static const char *ColorNames[] = {"red", "yellow", "green", "light-gray", "gray", "dark-gray", "white", "orange", - "light-blue", "blue", "dark-green", "black", NULL}; + "light-blue", "blue", "dark-green", "black", nullptr}; inline int GetColorIndexByName(const char *colorName) { int i = 0; - while (ColorNames[i] != NULL) { + while (ColorNames[i] != nullptr) { if (!strcmp(colorName, ColorNames[i])) { return i; } diff --git a/src/include/widgets.h b/src/include/widgets.h index db5e4d319..e6a729ada 100644 --- a/src/include/widgets.h +++ b/src/include/widgets.h @@ -268,8 +268,8 @@ class ImageTextField : public gcn::TextField { public: - ImageTextField() : TextField(), itemImage(NULL) {} - ImageTextField(const std::string& text) : gcn::TextField(text), itemImage(NULL) {} + ImageTextField() : TextField(), itemImage(nullptr) {} + ImageTextField(const std::string& text) : gcn::TextField(text), itemImage(nullptr) {} virtual void draw(gcn::Graphics *graphics); virtual void drawBorder(gcn::Graphics *graphics); void setItemImage(CGraphic *image) { itemImage = image; } @@ -419,7 +419,7 @@ public: class ImageDropDownWidget : public DropDownWidget { public: - ImageDropDownWidget() : itemImage(NULL) { + ImageDropDownWidget() : itemImage(nullptr) { mListBox.addActionListener(this); setListModel(&listmodel); mScrollArea->setContent(&mListBox); diff --git a/src/map/fov.cpp b/src/map/fov.cpp index 247e73107..88bf93b7b 100644 --- a/src/map/fov.cpp +++ b/src/map/fov.cpp @@ -132,7 +132,7 @@ void CFieldOfView::Refresh(const CPlayer &player, const CUnit &unit, const Vec2i { /// FIXME: sometimes when quit from game this assert is triggered if (unit.ReleaseCycle) return; - Assert(unit.Type != NULL); + Assert(unit.Type != nullptr); // Units under construction have no sight range. if (!range) { return; diff --git a/src/map/fow.cpp b/src/map/fow.cpp index 50ef166c3..a7405ccd8 100644 --- a/src/map/fow.cpp +++ b/src/map/fow.cpp @@ -143,7 +143,7 @@ void CFogOfWar::InitTiled() if (Settings.Type == FogOfWarTypes::cTiledLegacy) { TileOfFogOnly = SDL_CreateRGBSurface(SDL_SWSURFACE, PixelTileSize.x, PixelTileSize.y, 32, RMASK, GMASK, BMASK, AMASK); - SDL_FillRect(TileOfFogOnly, NULL, Settings.FogColorSDL | uint32_t(Settings.ExploredOpacity) << ASHIFT); + SDL_FillRect(TileOfFogOnly, nullptr, Settings.FogColorSDL | uint32_t(Settings.ExploredOpacity) << ASHIFT); } SDL_Surface * const newFogSurface = SDL_ConvertSurfaceFormat(CFogOfWar::TiledFogSrc->Surface, @@ -422,7 +422,7 @@ void CFogOfWar::Draw(CViewport &viewport) if (Settings.Type == FogOfWarTypes::cTiledLegacy) { DrawTiledLegacy(viewport); } else { - SDL_FillRect(viewport.GetFogSurface(), NULL, 0x00); + SDL_FillRect(viewport.GetFogSurface(), nullptr, 0x00); if (Settings.Type == FogOfWarTypes::cTiled) { DrawTiled(viewport); diff --git a/src/map/map.cpp b/src/map/map.cpp index d141b888b..043700b72 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -318,7 +318,7 @@ void CMapInfo::Clear() this->MapUID = 0; } -CMap::CMap() : Fields(NULL), NoFogOfWar(false), TileGraphic(NULL), Tileset(NULL) +CMap::CMap() : Fields(nullptr), NoFogOfWar(false), TileGraphic(nullptr), Tileset(nullptr) { } @@ -363,12 +363,12 @@ void CMap::Clean(const bool isHardClean /* = false*/) // Tileset freed by Tileset? this->Info.Clear(); - this->Fields = NULL; + this->Fields = nullptr; this->NoFogOfWar = false; this->Tileset->clear(); this->TileModelsFileName.clear(); CGraphic::Free(this->TileGraphic); - this->TileGraphic = NULL; + this->TileGraphic = nullptr; FlagRevealMap = MapRevealModes::cHidden; ReplayRevealMap = 0; diff --git a/src/map/map_draw.cpp b/src/map/map_draw.cpp index c79b9bcd7..db7672296 100644 --- a/src/map/map_draw.cpp +++ b/src/map/map_draw.cpp @@ -51,7 +51,7 @@ bool CViewport::ShowGrid = false; -CViewport::CViewport() : MapWidth(0), MapHeight(0), Unit(NULL) +CViewport::CViewport() : MapWidth(0), MapHeight(0), Unit(nullptr) { this->TopLeftPos.x = this->TopLeftPos.y = 0; this->BottomRightPos.x = this->BottomRightPos.y = 0; @@ -429,7 +429,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr * this->DrawMapBackgroundInViewport(highlightChecker); } - Missile *clickMissile = NULL; + Missile *clickMissile = nullptr; CurrentViewport = this; { // Now we need to sort units, missiles, particles by draw level and draw them @@ -454,7 +454,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr * if (i == nunits) { if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) { missiletable[j]->DrawMissile(*this); - if (clickMissile == NULL && missiletable[j]->Type->Ident == ClickMissile) { + if (clickMissile == nullptr && missiletable[j]->Type->Ident == ClickMissile) { clickMissile = missiletable[j]; } ++j; @@ -476,7 +476,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr * ++i; } else { missiletable[j]->DrawMissile(*this); - if (clickMissile == NULL && missiletable[j]->Type->Ident == ClickMissile) { + if (clickMissile == nullptr && missiletable[j]->Type->Ident == ClickMissile) { clickMissile = missiletable[j]; } ++j; @@ -493,7 +493,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr * } else { if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) { missiletable[j]->DrawMissile(*this); - if (clickMissile == NULL && missiletable[j]->Type->Ident == ClickMissile) { + if (clickMissile == nullptr && missiletable[j]->Type->Ident == ClickMissile) { clickMissile = missiletable[j]; } ++j; @@ -509,7 +509,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr * } for (; j < nmissiles; ++j) { missiletable[j]->DrawMissile(*this); - if (clickMissile == NULL && missiletable[j]->Type->Ident == ClickMissile) { + if (clickMissile == nullptr && missiletable[j]->Type->Ident == ClickMissile) { clickMissile = missiletable[j]; } } @@ -523,7 +523,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr * this->DrawMapFogOfWar(); // If there was a click missile, draw it again here above the fog - if (clickMissile != NULL) { + if (clickMissile != nullptr) { Vec2i pos = Map.MapPixelPosToTilePos(clickMissile->position); Map.Clamp(pos); if (Map.Field(pos.x, pos.y)->playerInfo.TeamVisibilityState(*ThisPlayer) != 2) { @@ -557,7 +557,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr * && ((isMapFieldVisile && !UnitUnderCursor->Type->BoolFlag[ISNOTSELECTABLE_INDEX].value) || ReplayRevealMap)) { ShowUnitName(*this, CursorScreenPos, UnitUnderCursor); } else if (!isMapFieldVisile) { - ShowUnitName(*this, CursorScreenPos, NULL, true); + ShowUnitName(*this, CursorScreenPos, nullptr, true); } } diff --git a/src/map/map_fog.cpp b/src/map/map_fog.cpp index a340b8eb6..2b8659258 100644 --- a/src/map/map_fog.cpp +++ b/src/map/map_fog.cpp @@ -72,7 +72,7 @@ class _filter_flags public: _filter_flags(const CPlayer &p, int *fogmask) : player(&p), fogmask(fogmask) { - Assert(fogmask != NULL); + Assert(fogmask != nullptr); } void operator()(const CUnit *const unit) const @@ -436,7 +436,7 @@ void CViewport::AdjustFogSurface() SDL_SetSurfaceBlendMode(this->FogSurface, SDL_BLENDMODE_NONE); const uint32_t fogColorSolid = FogOfWar->GetFogColorSDL() | (uint32_t(0xFF) << ASHIFT); - SDL_FillRect(this->FogSurface, NULL, fogColorSolid); + SDL_FillRect(this->FogSurface, nullptr, fogColorSolid); } void CViewport::Clean() diff --git a/src/map/minimap.cpp b/src/map/minimap.cpp index 35a2b03ae..e2bfd1a36 100644 --- a/src/map/minimap.cpp +++ b/src/map/minimap.cpp @@ -143,7 +143,7 @@ void CMinimap::Create() SDL_SetSurfaceBlendMode(MinimapFogSurface, SDL_BLENDMODE_BLEND); const uint32_t fogColorSolid = FogOfWar->GetFogColorSDL() | (uint32_t(0xFF) << ASHIFT); - SDL_FillRect(MinimapFogSurface, NULL, fogColorSolid); + SDL_FillRect(MinimapFogSurface, nullptr, fogColorSolid); UpdateTerrain(); @@ -377,14 +377,14 @@ void CMinimap::Update() // Clear Minimap background if not transparent if (!Transparent) { - SDL_FillRect(MinimapSurface, NULL, SDL_MapRGB(MinimapSurface->format, 0, 0, 0)); + SDL_FillRect(MinimapSurface, nullptr, SDL_MapRGB(MinimapSurface->format, 0, 0, 0)); } // // Draw the terrain // if (WithTerrain) { - SDL_BlitSurface(MinimapTerrainSurface, NULL, MinimapSurface, NULL); + SDL_BlitSurface(MinimapTerrainSurface, nullptr, MinimapSurface, nullptr); } const uint32_t fogColorSDL = FogOfWar->GetFogColorSDL(); if (!ReplayRevealMap) { @@ -444,7 +444,7 @@ static void DrawEvents() void CMinimap::Draw() const { SDL_Rect drect = {Sint16(X), Sint16(Y), 0, 0}; - SDL_BlitSurface(MinimapSurface, NULL, TheScreen, &drect); + SDL_BlitSurface(MinimapSurface, nullptr, TheScreen, &drect); DrawEvents(); } @@ -487,21 +487,21 @@ void CMinimap::Destroy() if (MinimapTerrainSurface) { VideoPaletteListRemove(MinimapTerrainSurface); SDL_FreeSurface(MinimapTerrainSurface); - MinimapTerrainSurface = NULL; + MinimapTerrainSurface = nullptr; } if (MinimapSurface) { VideoPaletteListRemove(MinimapSurface); SDL_FreeSurface(MinimapSurface); - MinimapSurface = NULL; + MinimapSurface = nullptr; } - if (MinimapFogSurface && MinimapFogSurface->format != NULL) { + if (MinimapFogSurface && MinimapFogSurface->format != nullptr) { SDL_FreeSurface(MinimapFogSurface); - MinimapFogSurface = NULL; + MinimapFogSurface = nullptr; } delete[] Minimap2MapX; - Minimap2MapX = NULL; + Minimap2MapX = nullptr; delete[] Minimap2MapY; - Minimap2MapY = NULL; + Minimap2MapY = nullptr; } /** diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index e23b80e84..2ff28c40f 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -232,7 +232,7 @@ static int CclShowMapLocation(lua_State *l) return 0; } CUnit *target = MakeUnit(*unitType, ThisPlayer); - if (target != NULL) { + if (target != nullptr) { target->Variable[HP_INDEX].Value = 0; target->tilePos.x = LuaToNumber(l, 1); target->tilePos.y = LuaToNumber(l, 2); diff --git a/src/map/script_tileset.cpp b/src/map/script_tileset.cpp index 60801543e..24611cd2d 100644 --- a/src/map/script_tileset.cpp +++ b/src/map/script_tileset.cpp @@ -1455,7 +1455,7 @@ sdl2::SurfacePtr CTilesetGraphicGenerator::composeImage(sequence_of_imagesPtrs & auto dst { newBlankImage() }; for (auto &src : srcSequence) { - SDL_BlitSurface(src, NULL, dst.get(), NULL); + SDL_BlitSurface(src, nullptr, dst.get(), nullptr); } return dst; } diff --git a/src/missile/missile.cpp b/src/missile/missile.cpp index 035085965..2d68f2744 100644 --- a/src/missile/missile.cpp +++ b/src/missile/missile.cpp @@ -118,13 +118,13 @@ void LoadMissileSprites() MissileType *MissileTypeByIdent(const std::string &ident) { if (ident.empty()) { - return NULL; + return nullptr; } MissileTypeMap::iterator it = MissileTypes.find(ident); if (it != MissileTypes.end()) { return it->second; } - return NULL; + return nullptr; } /** @@ -146,7 +146,7 @@ MissileType *NewMissileTypeSlot(const std::string &ident) ** Constructor */ Missile::Missile() : - Type(NULL), SpriteFrame(0), State(0), AnimWait(0), Wait(0), + Type(nullptr), SpriteFrame(0), State(0), AnimWait(0), Wait(0), Delay(0), SourceUnit(), TargetUnit(), Damage(0), TTL(-1), Hidden(0), DestroyMissile(0), CurrentStep(0), TotalStep(0), @@ -172,7 +172,7 @@ Missile::Missile() : */ /* static */ Missile *Missile::Init(const MissileType &mtype, const PixelPos &startPos, const PixelPos &destPos) { - Missile *missile = NULL; + Missile *missile = nullptr; switch (mtype.Class) { case MissileClassNone : @@ -335,8 +335,8 @@ int CalculateDamage(const CUnit &attacker, const CUnit &goal, const NumberDesc * TriggerData.Attacker = const_cast(&attacker); TriggerData.Defender = const_cast(&goal); const int res = EvalNumber(formula); - TriggerData.Attacker = NULL; - TriggerData.Defender = NULL; + TriggerData.Attacker = nullptr; + TriggerData.Defender = nullptr; return res; } @@ -361,7 +361,7 @@ void FireMissile(CUnit &unit, CUnit *goal, const Vec2i &goalPos) if (goal->CurrentAction() == UnitActionDie) { if (unit.Type->Missile.Missile->AlwaysFire) { newgoalPos = goal->tilePos; - goal = NULL; + goal = nullptr; } else { return; } @@ -751,7 +751,7 @@ bool PointToPointMissile(Missile &missile) if (missile.TotalStep == 0) { return true; } - Assert(missile.Type != NULL); + Assert(missile.Type != nullptr); Assert(missile.TotalStep != 0); const PixelPos diff = (missile.destination - missile.source); @@ -838,12 +838,12 @@ static void MissileHitsGoal(const Missile &missile, CUnit &goal, int splash) int damage; if (missile.Type->Damage) { // custom formula - Assert(missile.SourceUnit != NULL); + Assert(missile.SourceUnit != nullptr); damage = CalculateDamage(*missile.SourceUnit, goal, missile.Type->Damage) / splash; } else if (missile.Damage) { // direct damage, spells mostly damage = missile.Damage / splash; } else { - Assert(missile.SourceUnit != NULL); + Assert(missile.SourceUnit != nullptr); damage = CalculateDamage(*missile.SourceUnit, goal, Damage) / splash; } if (missile.Type->Pierce) { // Handle pierce factor @@ -877,7 +877,7 @@ static void MissileHitsWall(const Missile &missile, const Vec2i &tilePos, int sp return; } - Assert(missile.SourceUnit != NULL); + Assert(missile.SourceUnit != nullptr); if (Map.HumanWallOnMap(tilePos)) { stats = UnitTypeHumanWall->Stats; } else { @@ -983,7 +983,7 @@ void Missile::MissileHit(CUnit *unit) } } if (goal.Destroyed) { - this->TargetUnit = NULL; + this->TargetUnit = nullptr; return; } MissileHitsGoal(*this, goal, 1); @@ -1000,7 +1000,7 @@ void Missile::MissileHit(CUnit *unit) const Vec2i range(mtype.Range - 1, mtype.Range - 1); std::vector table; Select(pos - range, pos + range, table); - Assert(this->SourceUnit != NULL); + Assert(this->SourceUnit != nullptr); for (size_t i = 0; i != table.size(); ++i) { CUnit &goal = *table[i]; // @@ -1022,7 +1022,7 @@ void Missile::MissileHit(CUnit *unit) if (mtype.CorrectSphashDamage == true) { bool isPosition = false; - if (this->TargetUnit == NULL) { + if (this->TargetUnit == nullptr) { if (this->SourceUnit->CurrentAction() == UnitActionSpellCast) { const COrder_SpellCast &order = *static_cast(this->SourceUnit->CurrentOrder()); if (order.GetSpell().Target == TargetPosition) { @@ -1037,7 +1037,7 @@ void Missile::MissileHit(CUnit *unit) shouldHit = false; } } else { - if (this->TargetUnit == NULL || goal.Type->UnitType != this->TargetUnit->Type->UnitType) { + if (this->TargetUnit == nullptr || goal.Type->UnitType != this->TargetUnit->Type->UnitType) { shouldHit = false; } } @@ -1235,7 +1235,7 @@ MissileType *MissileBurningBuilding(int percent) return (*i)->Missile; } } - return NULL; + return nullptr; } /** @@ -1264,10 +1264,10 @@ void Missile::SaveMissile(CFile &file) const SavePixelPos(file, this->destination); 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); - if (this->SourceUnit != NULL) { + if (this->SourceUnit != nullptr) { file.printf(" \"source\", \"%s\",", UnitReference(this->SourceUnit).c_str()); } - if (this->TargetUnit != NULL) { + if (this->TargetUnit != nullptr) { file.printf(" \"target\", \"%s\",", UnitReference(this->TargetUnit).c_str()); } file.printf(" \"damage\", %d,", this->Damage); @@ -1337,9 +1337,9 @@ MissileType::MissileType(const std::string &ident) : AlwaysFire(false), Pierce(false), PierceOnce(false), IgnoreWalls(true), KillFirstUnit(false), Class(), NumBounces(0), ParabolCoefficient(2048), StartDelay(0), Sleep(0), Speed(0), BlizzardSpeed(0), TTL(-1), ReduceFactor(100), SmokePrecision(0), - MissileStopFlags(0), Damage(NULL), Range(0), SplashFactor(0), - ImpactParticle(NULL), SmokeParticle(NULL), OnImpact(NULL), - G(NULL) + MissileStopFlags(0), Damage(nullptr), Range(0), SplashFactor(0), + ImpactParticle(nullptr), SmokeParticle(nullptr), OnImpact(nullptr), + G(nullptr) { size.x = 0; size.y = 0; diff --git a/src/missile/missile_cliptotarget.cpp b/src/missile/missile_cliptotarget.cpp index 5a92e9b28..30fe66e56 100644 --- a/src/missile/missile_cliptotarget.cpp +++ b/src/missile/missile_cliptotarget.cpp @@ -47,7 +47,7 @@ void MissileClipToTarget::Action() { this->Wait = this->Type->Sleep; - if (this->TargetUnit != NULL) { + if (this->TargetUnit != nullptr) { const PixelPos halfSize = this->Type->size / 2; this->position.x = this->TargetUnit->tilePos.x * PixelTileSize.x + this->TargetUnit->IX - halfSize.x; this->position.y = this->TargetUnit->tilePos.y * PixelTileSize.y + this->TargetUnit->IY - halfSize.y; diff --git a/src/missile/missile_deathcoil.cpp b/src/missile/missile_deathcoil.cpp index bc7f332a2..0fc174ba4 100644 --- a/src/missile/missile_deathcoil.cpp +++ b/src/missile/missile_deathcoil.cpp @@ -56,7 +56,7 @@ void MissileDeathCoil::Action() if (this->NextMissileFrame(1, 0) == false) { return; } - Assert(this->SourceUnit != NULL); + Assert(this->SourceUnit != nullptr); CUnit &source = *this->SourceUnit; if (source.Destroyed) { diff --git a/src/missile/missile_landmine.cpp b/src/missile/missile_landmine.cpp index db3259c4e..78cdc9294 100644 --- a/src/missile/missile_landmine.cpp +++ b/src/missile/missile_landmine.cpp @@ -67,7 +67,7 @@ void MissileLandMine::Action() { const Vec2i pos = Map.MapPixelPosToTilePos(this->position); - if (LandMineTargetFinder(this->SourceUnit, this->Type->CanHitOwner).FindOnTile(Map.Field(pos)) != NULL) { + if (LandMineTargetFinder(this->SourceUnit, this->Type->CanHitOwner).FindOnTile(Map.Field(pos)) != nullptr) { DebugPrint("Landmine explosion at %d,%d.\n" _C_ pos.x _C_ pos.y); this->MissileHit(); this->TTL = 0; diff --git a/src/missile/missile_parabolic.cpp b/src/missile/missile_parabolic.cpp index 9cdd7964c..dbfcb414e 100644 --- a/src/missile/missile_parabolic.cpp +++ b/src/missile/missile_parabolic.cpp @@ -64,7 +64,7 @@ static bool ParabolicMissile(Missile &missile) if (missile.TotalStep == 0) { return true; } - Assert(missile.Type != NULL); + Assert(missile.Type != nullptr); const PixelPos orig_pos = missile.position; Assert(missile.TotalStep != 0); const PixelPos diff = (missile.destination - missile.source); diff --git a/src/missile/missile_tracer.cpp b/src/missile/missile_tracer.cpp index 5b9667ef5..f0664f281 100644 --- a/src/missile/missile_tracer.cpp +++ b/src/missile/missile_tracer.cpp @@ -58,7 +58,7 @@ static bool TracerMissile(Missile &missile) return true; } - Assert(missile.Type != NULL); + Assert(missile.Type != nullptr); Assert(missile.TotalStep != 0); if (missile.TargetUnit) { missile.destination = missile.TargetUnit->GetMapPixelPosTopLeft(); diff --git a/src/missile/missileconfig.cpp b/src/missile/missileconfig.cpp index eb7cd729f..209d4ee23 100644 --- a/src/missile/missileconfig.cpp +++ b/src/missile/missileconfig.cpp @@ -40,11 +40,11 @@ bool MissileConfig::MapMissileNoLog() { if (this->Name.empty()) { - this->Missile = NULL; + this->Missile = nullptr; return true; } this->Missile = MissileTypeByIdent(this->Name); - return this->Missile != NULL; + return this->Missile != nullptr; } bool MissileConfig::MapMissile() diff --git a/src/missile/script_missile.cpp b/src/missile/script_missile.cpp index 6f93e77bf..dd9ea6064 100644 --- a/src/missile/script_missile.cpp +++ b/src/missile/script_missile.cpp @@ -70,7 +70,7 @@ static const char *MissileClassNames[] = { "missile-class-clip-to-target", "missile-class-continious", "missile-class-straight-fly", - NULL + nullptr }; /*---------------------------------------------------------------------------- @@ -246,11 +246,11 @@ static int CclDefineMissileType(lua_State *l) */ static int CclMissile(lua_State *l) { - MissileType *type = NULL; + MissileType *type = nullptr; PixelPos position(-1, -1); PixelPos destination(-1, -1); PixelPos source(-1, -1); - Missile *missile = NULL; + Missile *missile = nullptr; DebugPrint("FIXME: not finished\n"); @@ -399,14 +399,14 @@ static int CclCreateMissile(lua_State *l) const int destUnitId = LuaToNumber(l, 5); const bool dealDamage = LuaToBoolean(l, 6); const bool mapRelative = arg == 7 ? LuaToBoolean(l, 7) : false; - CUnit *sourceUnit = sourceUnitId != -1 ? &UnitManager->GetSlotUnit(sourceUnitId) : NULL; - CUnit *destUnit = destUnitId != -1 ? &UnitManager->GetSlotUnit(destUnitId) : NULL; + CUnit *sourceUnit = sourceUnitId != -1 ? &UnitManager->GetSlotUnit(sourceUnitId) : nullptr; + CUnit *destUnit = destUnitId != -1 ? &UnitManager->GetSlotUnit(destUnitId) : nullptr; if (mapRelative == false) { - if (sourceUnit != NULL) { + if (sourceUnit != nullptr) { startpos += sourceUnit->GetMapPixelPosTopLeft(); } - if (destUnit != NULL) { + if (destUnit != nullptr) { endpos += destUnit->GetMapPixelPosTopLeft(); } } diff --git a/src/network/commands.cpp b/src/network/commands.cpp index 68b671cd1..7813d6fa7 100644 --- a/src/network/commands.cpp +++ b/src/network/commands.cpp @@ -59,7 +59,7 @@ void SendCommandStopUnit(CUnit &unit) { if (IsReplayGame()) { - CommandLog("stop", &unit, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog("stop", &unit, FlushCommands, -1, -1, NoUnitP, nullptr, -1); CommandStopUnit(unit); } else { NetworkSendCommand(MessageCommandStop, unit, 0, 0, NoUnitP, 0, FlushCommands); @@ -75,7 +75,7 @@ void SendCommandStopUnit(CUnit &unit) void SendCommandStandGround(CUnit &unit, int flush) { if (IsReplayGame()) { - CommandLog("stand-ground", &unit, flush, -1, -1, NoUnitP, NULL, -1); + CommandLog("stand-ground", &unit, flush, -1, -1, NoUnitP, nullptr, -1); CommandStandGround(unit, flush); } else { NetworkSendCommand(MessageCommandStand, unit, 0, 0, NoUnitP, 0, flush); @@ -92,7 +92,7 @@ void SendCommandStandGround(CUnit &unit, int flush) void SendCommandDefend(CUnit &unit, CUnit &dest, int flush) { if (IsReplayGame()) { - CommandLog("defend", &unit, flush, -1, -1, &dest, NULL, -1); + CommandLog("defend", &unit, flush, -1, -1, &dest, nullptr, -1); CommandDefend(unit, dest, flush); } else { NetworkSendCommand(MessageCommandDefend, unit, 0, 0, &dest, 0, flush); @@ -109,7 +109,7 @@ void SendCommandDefend(CUnit &unit, CUnit &dest, int flush) void SendCommandFollow(CUnit &unit, CUnit &dest, int flush) { if (IsReplayGame()) { - CommandLog("follow", &unit, flush, -1, -1, &dest, NULL, -1); + CommandLog("follow", &unit, flush, -1, -1, &dest, nullptr, -1); CommandFollow(unit, dest, flush); } else { NetworkSendCommand(MessageCommandFollow, unit, 0, 0, &dest, 0, flush); @@ -126,7 +126,7 @@ void SendCommandFollow(CUnit &unit, CUnit &dest, int flush) void SendCommandMove(CUnit &unit, const Vec2i &pos, int flush) { if (IsReplayGame()) { - CommandLog("move", &unit, flush, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("move", &unit, flush, pos.x, pos.y, NoUnitP, nullptr, -1); CommandMove(unit, pos, flush); } else { NetworkSendCommand(MessageCommandMove, unit, pos.x, pos.y, NoUnitP, 0, flush); @@ -144,7 +144,7 @@ void SendCommandMove(CUnit &unit, const Vec2i &pos, int flush) void SendCommandRepair(CUnit &unit, const Vec2i &pos, CUnit *dest, int flush) { if (IsReplayGame()) { - CommandLog("repair", &unit, flush, pos.x, pos.y, dest, NULL, -1); + CommandLog("repair", &unit, flush, pos.x, pos.y, dest, nullptr, -1); CommandRepair(unit, pos, dest, flush); } else { NetworkSendCommand(MessageCommandRepair, unit, pos.x, pos.y, dest, 0, flush); @@ -160,10 +160,10 @@ void SendCommandRepair(CUnit &unit, const Vec2i &pos, CUnit *dest, int flush) void SendCommandAutoRepair(CUnit &unit, int on) { if (IsReplayGame()) { - CommandLog("auto-repair", &unit, FlushCommands, on, -1, NoUnitP, NULL, 0); + CommandLog("auto-repair", &unit, FlushCommands, on, -1, NoUnitP, nullptr, 0); CommandAutoRepair(unit, on); } else { - NetworkSendCommand(MessageCommandAutoRepair, unit, on, -1, NoUnitP, NULL, FlushCommands); + NetworkSendCommand(MessageCommandAutoRepair, unit, on, -1, NoUnitP, nullptr, FlushCommands); } } @@ -178,7 +178,7 @@ void SendCommandAutoRepair(CUnit &unit, int on) void SendCommandAttack(CUnit &unit, const Vec2i &pos, CUnit *attack, int flush) { if (IsReplayGame()) { - CommandLog("attack", &unit, flush, pos.x, pos.y, attack, NULL, -1); + CommandLog("attack", &unit, flush, pos.x, pos.y, attack, nullptr, -1); CommandAttack(unit, pos, attack, flush); } else { NetworkSendCommand(MessageCommandAttack, unit, pos.x, pos.y, attack, 0, flush); @@ -195,7 +195,7 @@ void SendCommandAttack(CUnit &unit, const Vec2i &pos, CUnit *attack, int flush) void SendCommandAttackGround(CUnit &unit, const Vec2i &pos, int flush) { if (IsReplayGame()) { - CommandLog("attack-ground", &unit, flush, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("attack-ground", &unit, flush, pos.x, pos.y, NoUnitP, nullptr, -1); CommandAttackGround(unit, pos, flush); } else { NetworkSendCommand(MessageCommandGround, unit, pos.x, pos.y, NoUnitP, 0, flush); @@ -212,7 +212,7 @@ void SendCommandAttackGround(CUnit &unit, const Vec2i &pos, int flush) void SendCommandPatrol(CUnit &unit, const Vec2i &pos, int flush) { if (IsReplayGame()) { - CommandLog("patrol", &unit, flush, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("patrol", &unit, flush, pos.x, pos.y, NoUnitP, nullptr, -1); CommandPatrolUnit(unit, pos, flush); } else { NetworkSendCommand(MessageCommandPatrol, unit, pos.x, pos.y, NoUnitP, 0, flush); @@ -229,7 +229,7 @@ void SendCommandPatrol(CUnit &unit, const Vec2i &pos, int flush) void SendCommandBoard(CUnit &unit, CUnit &dest, int flush) { if (IsReplayGame()) { - CommandLog("board", &unit, flush, -1, -1, &dest, NULL, -1); + CommandLog("board", &unit, flush, -1, -1, &dest, nullptr, -1); CommandBoard(unit, dest, flush); } else { NetworkSendCommand(MessageCommandBoard, unit, -1, -1, &dest, 0, flush); @@ -247,7 +247,7 @@ void SendCommandBoard(CUnit &unit, CUnit &dest, int flush) void SendCommandUnload(CUnit &unit, const Vec2i &pos, CUnit *what, int flush) { if (IsReplayGame()) { - CommandLog("unload", &unit, flush, pos.x, pos.y, what, NULL, -1); + CommandLog("unload", &unit, flush, pos.x, pos.y, what, nullptr, -1); CommandUnload(unit, pos, what, flush); } else { NetworkSendCommand(MessageCommandUnload, unit, pos.x, pos.y, what, 0, flush); @@ -281,7 +281,7 @@ void SendCommandBuildBuilding(CUnit &unit, const Vec2i &pos, CUnitType &what, in void SendCommandExplore(CUnit &unit, int flush) { if (IsReplayGame()) { - CommandLog("explore", &unit, flush, -1, -1, NoUnitP, NULL, -1); + CommandLog("explore", &unit, flush, -1, -1, NoUnitP, nullptr, -1); CommandExplore(unit, flush); } else { NetworkSendCommand(MessageCommandExplore, unit, 0, 0, NoUnitP, 0, flush); @@ -297,10 +297,10 @@ void SendCommandDismiss(CUnit &unit) { // FIXME: currently unit and worker are same? if (IsReplayGame()) { - CommandLog("dismiss", &unit, FlushCommands, -1, -1, NULL, NULL, -1); + CommandLog("dismiss", &unit, FlushCommands, -1, -1, nullptr, nullptr, -1); CommandDismiss(unit); } else { - NetworkSendCommand(MessageCommandDismiss, unit, 0, 0, NULL, 0, FlushCommands); + NetworkSendCommand(MessageCommandDismiss, unit, 0, 0, nullptr, 0, FlushCommands); } } @@ -314,7 +314,7 @@ void SendCommandDismiss(CUnit &unit) void SendCommandResourceLoc(CUnit &unit, const Vec2i &pos, int flush) { if (IsReplayGame()) { - CommandLog("resource-loc", &unit, flush, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("resource-loc", &unit, flush, pos.x, pos.y, NoUnitP, nullptr, -1); CommandResourceLoc(unit, pos, flush); } else { NetworkSendCommand(MessageCommandResourceLoc, unit, pos.x, pos.y, NoUnitP, 0, flush); @@ -331,7 +331,7 @@ void SendCommandResourceLoc(CUnit &unit, const Vec2i &pos, int flush) void SendCommandResource(CUnit &unit, CUnit &dest, int flush) { if (IsReplayGame()) { - CommandLog("resource", &unit, flush, -1, -1, &dest, NULL, -1); + CommandLog("resource", &unit, flush, -1, -1, &dest, nullptr, -1); CommandResource(unit, dest, flush); } else { NetworkSendCommand(MessageCommandResource, unit, 0, 0, &dest, 0, flush); @@ -342,13 +342,13 @@ void SendCommandResource(CUnit &unit, CUnit &dest, int flush) ** Send command: Unit return goods. ** ** @param unit pointer to unit. -** @param goal pointer to destination of the goods. (NULL=search best) +** @param goal pointer to destination of the goods. (nullptr=search best) ** @param flush Flag flush all pending commands. */ void SendCommandReturnGoods(CUnit &unit, CUnit *goal, int flush) { if (IsReplayGame()) { - CommandLog("return", &unit, flush, -1, -1, goal, NULL, -1); + CommandLog("return", &unit, flush, -1, -1, goal, nullptr, -1); CommandReturnGoods(unit, goal, flush); } else { NetworkSendCommand(MessageCommandReturn, unit, 0, 0, goal, 0, flush); @@ -383,7 +383,7 @@ void SendCommandCancelTraining(CUnit &unit, int slot, const CUnitType *type) { if (IsReplayGame()) { CommandLog("cancel-train", &unit, FlushCommands, -1, -1, NoUnitP, - type ? type->Ident.c_str() : NULL, slot); + type ? type->Ident.c_str() : nullptr, slot); CommandCancelTraining(unit, slot, type); } else { NetworkSendCommand(MessageCommandCancelTrain, unit, slot, 0, NoUnitP, @@ -416,11 +416,11 @@ void SendCommandUpgradeTo(CUnit &unit, CUnitType &what, int flush) void SendCommandCancelUpgradeTo(CUnit &unit) { if (IsReplayGame()) { - CommandLog("cancel-upgrade-to", &unit, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog("cancel-upgrade-to", &unit, FlushCommands, -1, -1, NoUnitP, nullptr, -1); CommandCancelUpgradeTo(unit); } else { NetworkSendCommand(MessageCommandCancelUpgrade, unit, - 0, 0, NoUnitP, NULL, FlushCommands); + 0, 0, NoUnitP, nullptr, FlushCommands); } } @@ -438,7 +438,7 @@ void SendCommandResearch(CUnit &unit, CUpgrade &what, int flush) CommandResearch(unit, what, flush); } else { NetworkSendCommand(MessageCommandResearch, unit, - what.ID, 0, NoUnitP, NULL, flush); + what.ID, 0, NoUnitP, nullptr, flush); } } @@ -450,11 +450,11 @@ void SendCommandResearch(CUnit &unit, CUpgrade &what, int flush) void SendCommandCancelResearch(CUnit &unit) { if (IsReplayGame()) { - CommandLog("cancel-research", &unit, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog("cancel-research", &unit, FlushCommands, -1, -1, NoUnitP, nullptr, -1); CommandCancelResearch(unit); } else { NetworkSendCommand(MessageCommandCancelResearch, unit, - 0, 0, NoUnitP, NULL, FlushCommands); + 0, 0, NoUnitP, nullptr, FlushCommands); } } @@ -470,11 +470,11 @@ void SendCommandCancelResearch(CUnit &unit) void SendCommandSpellCast(CUnit &unit, const Vec2i &pos, CUnit *dest, int spellid, int flush) { if (IsReplayGame()) { - CommandLog("spell-cast", &unit, flush, pos.x, pos.y, dest, NULL, spellid); + CommandLog("spell-cast", &unit, flush, pos.x, pos.y, dest, nullptr, spellid); CommandSpellCast(unit, pos, dest, *SpellTypeTable[spellid], flush); } else { NetworkSendCommand(MessageCommandSpellCast + spellid, - unit, pos.x, pos.y, dest, NULL, flush); + unit, pos.x, pos.y, dest, nullptr, flush); } } @@ -488,11 +488,11 @@ void SendCommandSpellCast(CUnit &unit, const Vec2i &pos, CUnit *dest, int spelli void SendCommandAutoSpellCast(CUnit &unit, int spellid, int on) { if (IsReplayGame()) { - CommandLog("auto-spell-cast", &unit, FlushCommands, on, -1, NoUnitP, NULL, spellid); + CommandLog("auto-spell-cast", &unit, FlushCommands, on, -1, NoUnitP, nullptr, spellid); CommandAutoSpellCast(unit, spellid, on); } else { NetworkSendCommand(MessageCommandSpellCast + spellid, - unit, on, -1, NoUnitP, NULL, FlushCommands); + unit, on, -1, NoUnitP, nullptr, FlushCommands); } } @@ -601,18 +601,18 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, return; case MessageCommandStop: - CommandLog("stop", &unit, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog("stop", &unit, FlushCommands, -1, -1, NoUnitP, nullptr, -1); CommandStopUnit(unit); break; case MessageCommandStand: - CommandLog("stand-ground", &unit, status, -1, -1, NoUnitP, NULL, -1); + CommandLog("stand-ground", &unit, status, -1, -1, NoUnitP, nullptr, -1); CommandStandGround(unit, status); break; case MessageCommandDefend: { if (dstnr != (unsigned short)0xFFFF) { CUnit &dest = UnitManager->GetSlotUnit(dstnr); Assert(dest.Type); - CommandLog("defend", &unit, status, -1, -1, &dest, NULL, -1); + CommandLog("defend", &unit, status, -1, -1, &dest, nullptr, -1); CommandDefend(unit, dest, status); } break; @@ -621,13 +621,13 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, if (dstnr != (unsigned short)0xFFFF) { CUnit &dest = UnitManager->GetSlotUnit(dstnr); Assert(dest.Type); - CommandLog("follow", &unit, status, -1, -1, &dest, NULL, -1); + CommandLog("follow", &unit, status, -1, -1, &dest, nullptr, -1); CommandFollow(unit, dest, status); } break; } case MessageCommandMove: - CommandLog("move", &unit, status, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("move", &unit, status, pos.x, pos.y, NoUnitP, nullptr, -1); CommandMove(unit, pos, status); break; case MessageCommandRepair: { @@ -636,12 +636,12 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, dest = &UnitManager->GetSlotUnit(dstnr); Assert(dest && dest->Type); } - CommandLog("repair", &unit, status, pos.x, pos.y, dest, NULL, -1); + CommandLog("repair", &unit, status, pos.x, pos.y, dest, nullptr, -1); CommandRepair(unit, pos, dest, status); break; } case MessageCommandAutoRepair: - CommandLog("auto-repair", &unit, status, arg1, arg2, NoUnitP, NULL, 0); + CommandLog("auto-repair", &unit, status, arg1, arg2, NoUnitP, nullptr, 0); CommandAutoRepair(unit, arg1); break; case MessageCommandAttack: { @@ -650,34 +650,34 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, dest = &UnitManager->GetSlotUnit(dstnr); Assert(dest && dest->Type); } - CommandLog("attack", &unit, status, pos.x, pos.y, dest, NULL, -1); + CommandLog("attack", &unit, status, pos.x, pos.y, dest, nullptr, -1); CommandAttack(unit, pos, dest, status); break; } case MessageCommandGround: - CommandLog("attack-ground", &unit, status, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("attack-ground", &unit, status, pos.x, pos.y, NoUnitP, nullptr, -1); CommandAttackGround(unit, pos, status); break; case MessageCommandPatrol: - CommandLog("patrol", &unit, status, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("patrol", &unit, status, pos.x, pos.y, NoUnitP, nullptr, -1); CommandPatrolUnit(unit, pos, status); break; case MessageCommandBoard: { if (dstnr != (unsigned short)0xFFFF) { CUnit &dest = UnitManager->GetSlotUnit(dstnr); Assert(dest.Type); - CommandLog("board", &unit, status, arg1, arg2, &dest, NULL, -1); + CommandLog("board", &unit, status, arg1, arg2, &dest, nullptr, -1); CommandBoard(unit, dest, status); } break; } case MessageCommandUnload: { - CUnit *dest = NULL; + CUnit *dest = nullptr; if (dstnr != (unsigned short)0xFFFF) { dest = &UnitManager->GetSlotUnit(dstnr); Assert(dest && dest->Type); } - CommandLog("unload", &unit, status, pos.x, pos.y, dest, NULL, -1); + CommandLog("unload", &unit, status, pos.x, pos.y, dest, nullptr, -1); CommandUnload(unit, pos, dest, status); break; } @@ -686,29 +686,29 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, CommandBuildBuilding(unit, pos, *UnitTypes[dstnr], status); break; case MessageCommandExplore: - CommandLog("explore", &unit, status, -1, -1, NoUnitP, NULL, -1); + CommandLog("explore", &unit, status, -1, -1, NoUnitP, nullptr, -1); CommandExplore(unit, status); break; case MessageCommandDismiss: - CommandLog("dismiss", &unit, FlushCommands, -1, -1, NULL, NULL, -1); + CommandLog("dismiss", &unit, FlushCommands, -1, -1, nullptr, nullptr, -1); CommandDismiss(unit); break; case MessageCommandResourceLoc: - CommandLog("resource-loc", &unit, status, pos.x, pos.y, NoUnitP, NULL, -1); + CommandLog("resource-loc", &unit, status, pos.x, pos.y, NoUnitP, nullptr, -1); CommandResourceLoc(unit, pos, status); break; case MessageCommandResource: { if (dstnr != (unsigned short)0xFFFF) { CUnit &dest = UnitManager->GetSlotUnit(dstnr); Assert(dest.Type); - CommandLog("resource", &unit, status, -1, -1, &dest, NULL, -1); + CommandLog("resource", &unit, status, -1, -1, &dest, nullptr, -1); CommandResource(unit, dest, status); } break; } case MessageCommandReturn: { - CUnit *dest = (dstnr != (unsigned short)0xFFFF) ? &UnitManager->GetSlotUnit(dstnr) : NULL; - CommandLog("return", &unit, status, -1, -1, dest, NULL, -1); + CUnit *dest = (dstnr != (unsigned short)0xFFFF) ? &UnitManager->GetSlotUnit(dstnr) : nullptr; + CommandLog("return", &unit, status, -1, -1, dest, nullptr, -1); CommandReturnGoods(unit, dest, status); break; } @@ -723,8 +723,8 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, UnitTypes[dstnr]->Ident.c_str(), (short)x); CommandCancelTraining(unit, (short)x, UnitTypes[dstnr]); } else { - CommandLog("cancel-train", &unit, FlushCommands, -1, -1, NoUnitP, NULL, (short)x); - CommandCancelTraining(unit, (short)x, NULL); + CommandLog("cancel-train", &unit, FlushCommands, -1, -1, NoUnitP, nullptr, (short)x); + CommandCancelTraining(unit, (short)x, nullptr); } break; case MessageCommandUpgrade: @@ -733,7 +733,7 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, CommandUpgradeTo(unit, *UnitTypes[dstnr], status); break; case MessageCommandCancelUpgrade: - CommandLog("cancel-upgrade-to", &unit, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog("cancel-upgrade-to", &unit, FlushCommands, -1, -1, NoUnitP, nullptr, -1); CommandCancelUpgradeTo(unit); break; case MessageCommandResearch: @@ -742,21 +742,21 @@ void ExecCommand(unsigned char msgnr, UnitRef unum, CommandResearch(unit, *AllUpgrades[arg1], status); break; case MessageCommandCancelResearch: - CommandLog("cancel-research", &unit, FlushCommands, -1, -1, NoUnitP, NULL, -1); + CommandLog("cancel-research", &unit, FlushCommands, -1, -1, NoUnitP, nullptr, -1); CommandCancelResearch(unit); break; default: { int id = (msgnr & 0x7f) - MessageCommandSpellCast; if (arg2 != (unsigned short)0xFFFF) { - CUnit *dest = NULL; + CUnit *dest = nullptr; if (dstnr != (unsigned short)0xFFFF) { dest = &UnitManager->GetSlotUnit(dstnr); Assert(dest && dest->Type); } - CommandLog("spell-cast", &unit, status, pos.x, pos.y, dest, NULL, id); + CommandLog("spell-cast", &unit, status, pos.x, pos.y, dest, nullptr, id); CommandSpellCast(unit, pos, dest, *SpellTypeTable[id], status); } else { - CommandLog("auto-spell-cast", &unit, status, arg1, -1, NoUnitP, NULL, id); + CommandLog("auto-spell-cast", &unit, status, arg1, -1, NoUnitP, nullptr, id); CommandAutoSpellCast(unit, id, arg1); } break; diff --git a/src/network/mdns.cpp b/src/network/mdns.cpp index b447a3a65..923a2c08d 100644 --- a/src/network/mdns.cpp +++ b/src/network/mdns.cpp @@ -54,8 +54,8 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle mdns_query_answer(sock, from, addrlen, buffer, sizeof(buffer), query_id, offeredService.c_str(), offeredService.size(), hostname.c_str(), hostname.size(), - ips[i], NULL, CNetworkParameter::Instance.localPort, - NULL, 0); + ips[i], nullptr, CNetworkParameter::Instance.localPort, + nullptr, 0); } } } @@ -81,7 +81,7 @@ void MDNS::AnswerServerQueries() { } char buffer[1024]; - mdns_socket_listen(serviceSocket, buffer, sizeof(buffer), service_callback, NULL); + mdns_socket_listen(serviceSocket, buffer, sizeof(buffer), service_callback, nullptr); } static int query_callback(int sock, const struct sockaddr* from, size_t addrlen, mdns_entry_type_t entry, diff --git a/src/network/net_lowlevel.cpp b/src/network/net_lowlevel.cpp index b3401af64..bd115a1d6 100644 --- a/src/network/net_lowlevel.cpp +++ b/src/network/net_lowlevel.cpp @@ -242,15 +242,15 @@ std::string NetGetHostname() int NetSocketAddr(unsigned long *ips, int maxAddr) { int idx = 0; - PIP_ADAPTER_ADDRESSES pFirstAddresses, pAddresses = NULL; + PIP_ADAPTER_ADDRESSES pFirstAddresses, pAddresses = nullptr; ULONG outBufLen = 0; GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER, - NULL, pAddresses, &outBufLen); + nullptr, pAddresses, &outBufLen); pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(outBufLen); if (GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER, - NULL, pAddresses, &outBufLen) == NO_ERROR) { + nullptr, pAddresses, &outBufLen) == NO_ERROR) { pFirstAddresses = pAddresses; for (pAddresses; pAddresses; pAddresses = pAddresses->Next) { if (idx == maxAddr) break; @@ -269,12 +269,12 @@ int NetSocketAddr(unsigned long *ips, int maxAddr) #elif defined(USE_LINUX) || defined(USE_MAC) int NetSocketAddr(unsigned long *ips, int maxAddr) { - struct ifaddrs *ifAddrStruct = NULL; - struct ifaddrs *ifa = NULL; - void *tmpAddrPtr = NULL; + struct ifaddrs *ifAddrStruct = nullptr; + struct ifaddrs *ifa = nullptr; + void *tmpAddrPtr = nullptr; int idx = 0; getifaddrs(&ifAddrStruct); - for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { + for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next) { if (idx == maxAddr) break; if (!ifa->ifa_addr) continue; if (ifa->ifa_addr->sa_family != AF_INET) continue; @@ -283,7 +283,7 @@ int NetSocketAddr(unsigned long *ips, int maxAddr) if ((ifa->ifa_flags & IFF_UP) == 0) continue; ips[idx++] = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; } - if (ifAddrStruct != NULL) { + if (ifAddrStruct != nullptr) { freeifaddrs(ifAddrStruct); } return idx; @@ -435,7 +435,7 @@ int NetSocketReady(Socket sockfd, int timeout) tv.tv_usec = (timeout % 1000) * 1000; // Data available? - retval = select(sockfd + 1, &mask, NULL, NULL, &tv); + retval = select(sockfd + 1, &mask, nullptr, nullptr, &tv); #ifdef USE_WINSOCK } while (retval == SOCKET_ERROR && WSAGetLastError() == WSAEINTR); #else @@ -471,7 +471,7 @@ int SocketSet::Select(int timeout) tv.tv_usec = (timeout % 1000) * 1000; // Data available? - retval = select(this->MaxSockFD + 1, &mask, NULL, NULL, &tv); + retval = select(this->MaxSockFD + 1, &mask, nullptr, nullptr, &tv); #ifdef USE_WINSOCK } while (retval == SOCKET_ERROR && WSAGetLastError() == WSAEINTR); #else diff --git a/src/network/net_message.cpp b/src/network/net_message.cpp index 69c508f29..73fbb8dc6 100644 --- a/src/network/net_message.cpp +++ b/src/network/net_message.cpp @@ -727,7 +727,7 @@ size_t CNetworkChat::Deserialize(const unsigned char *buf) size_t CNetworkChat::Size() const { size_t size = 0; - size += serialize(NULL, this->Text); + size += serialize(nullptr, this->Text); return size; } @@ -816,7 +816,7 @@ size_t CNetworkSelection::Size() const size_t CNetworkPacketHeader::Serialize(unsigned char *p) const { - if (p != NULL) { + if (p != nullptr) { for (int i = 0; i != MaxNetworkCommands; ++i) { p += serialize8(p, this->Type[i]); } @@ -870,9 +870,9 @@ size_t CNetworkPacket::Size(int numcommands) const { size_t size = 0; - size += this->Header.Serialize(NULL); + size += this->Header.Serialize(nullptr); for (int i = 0; i != numcommands; ++i) { - size += serialize(NULL, this->Command[i]); + size += serialize(nullptr, this->Command[i]); } return size; } diff --git a/src/network/network.cpp b/src/network/network.cpp index b27da1311..2873ce22e 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -417,7 +417,7 @@ void InitNetwork1() // Our communication port const int port = CNetworkParameter::Instance.localPort; - const char *NetworkAddr = NULL; // FIXME : bad use + const char *NetworkAddr = nullptr; // FIXME : bad use const CHost host(NetworkAddr, port); NetworkFildes.Open(host); if (NetworkFildes.IsValid() == false) { @@ -749,7 +749,7 @@ static bool IsAValidCommand_Command(const CNetworkPacket &packet, int index, con CNetworkCommand nc; nc.Deserialize(&packet.Command[index][0]); const unsigned int slot = nc.Unit; - const CUnit *unit = slot < UnitManager->GetUsedSlotCount() ? &UnitManager->GetSlotUnit(slot) : NULL; + const CUnit *unit = slot < UnitManager->GetUsedSlotCount() ? &UnitManager->GetSlotUnit(slot) : nullptr; if (unit && (unit->Player->Index == player || Players[player].IsTeamed(*unit) || unit->Player->Type == PlayerTypes::PlayerNeutral)) { @@ -764,7 +764,7 @@ static bool IsAValidCommand_Dismiss(const CNetworkPacket &packet, int index, con CNetworkCommand nc; nc.Deserialize(&packet.Command[index][0]); const unsigned int slot = nc.Unit; - const CUnit *unit = slot < UnitManager->GetUsedSlotCount() ? &UnitManager->GetSlotUnit(slot) : NULL; + const CUnit *unit = slot < UnitManager->GetUsedSlotCount() ? &UnitManager->GetSlotUnit(slot) : nullptr; if (unit && unit->Type->ClicksToExplode) { return true; @@ -1004,7 +1004,7 @@ static void NetworkExecCommand_Quit(const CNetworkCommandQueue &ncq) nc.Deserialize(&ncq.Data[0]); NetworkRemovePlayer(nc.player); - CommandLog("quit", NoUnitP, FlushCommands, nc.player, -1, NoUnitP, NULL, -1); + CommandLog("quit", NoUnitP, FlushCommands, nc.player, -1, NoUnitP, nullptr, -1); CommandQuit(nc.player); } diff --git a/src/network/online_service.cpp b/src/network/online_service.cpp index ffe76052f..da3f18ea0 100644 --- a/src/network/online_service.cpp +++ b/src/network/online_service.cpp @@ -383,7 +383,7 @@ public: serialize32(value); }; void serialize(const char* str) { - int len = strlen(str) + 1; // include NULL byte + int len = strlen(str) + 1; // include nullptr byte ensureSpace(len); memcpy(buf + pos, str, len); pos += len; @@ -825,7 +825,7 @@ public: Context() { this->tcpSocket = new CTCPSocket(); this->istream = new BNCSInputStream(tcpSocket); - this->state = NULL; + this->state = nullptr; this->host = new CHost("127.0.0.1", 6112); this->clientToken = MyRand(); this->username = ""; @@ -841,7 +841,7 @@ public: } ~Context() { - if (state != NULL) { + if (state != nullptr) { delete state; } delete tcpSocket; @@ -849,7 +849,7 @@ public: } bool isConnected() { - return state != NULL && !getCurrentChannel().empty(); + return state != nullptr && !getCurrentChannel().empty(); } bool isConnecting() { @@ -857,7 +857,7 @@ public: } bool isDisconnected() { - return state == NULL; + return state == nullptr; } // User and UI actions @@ -875,7 +875,7 @@ public: ExitNetwork1(); } tcpSocket->Close(); - state = NULL; + state = nullptr; clientToken = MyRand(); username = ""; setPassword(""); @@ -1171,7 +1171,7 @@ public: channelList.push_back(name); setChannels(channelList); } - if (SetActiveChannel != NULL) { + if (SetActiveChannel != nullptr) { SetActiveChannel->pushPreamble(); SetActiveChannel->pushString(name); SetActiveChannel->run(); @@ -1201,7 +1201,7 @@ public: } } this->games = games; - if (SetGames != NULL) { + if (SetGames != nullptr) { SetGames->pushPreamble(); for (const auto value : games) { if (value->isValid()) { @@ -1228,7 +1228,7 @@ public: delete value; } this->friends = friends; - if (SetFriends != NULL) { + if (SetFriends != nullptr) { SetFriends->pushPreamble(); for (const auto value : friends) { SetFriends->pushTable({ { "Name", value->getName() }, @@ -1242,7 +1242,7 @@ public: std::vector getFriends() { return friends; } void reportUserdata(uint32_t id, std::vector values) { - if (ShowUserInfo != NULL) { + if (ShowUserInfo != nullptr) { ShowUserInfo->pushPreamble(); std::map> m; m["User"] = extendedInfoNames.at(id); @@ -1259,7 +1259,7 @@ public: void showInfo(std::string arg) { std::string infoStr = arg; info.push(infoStr); - if (ShowInfo != NULL) { + if (ShowInfo != nullptr) { ShowInfo->pushPreamble(); ShowInfo->pushString(infoStr); ShowInfo->run(); @@ -1268,7 +1268,7 @@ public: void showError(std::string arg) { info.push("!!! " + arg + " !!!"); - if (ShowError != NULL) { + if (ShowError != nullptr) { ShowError->pushPreamble(); ShowError->pushString(arg); ShowError->run(); @@ -1277,7 +1277,7 @@ public: void showChat(std::string arg) { info.push(arg); - if (ShowChat != NULL) { + if (ShowChat != nullptr) { ShowChat->pushPreamble(); ShowChat->pushString(arg); ShowChat->run(); @@ -1286,7 +1286,7 @@ public: void addUser(std::string name) { userList.insert(name); - if (AddUser != NULL) { + if (AddUser != nullptr) { AddUser->pushPreamble(); AddUser->pushString(name); AddUser->run(); @@ -1295,7 +1295,7 @@ public: void removeUser(std::string name) { userList.erase(name); - if (RemoveUser != NULL) { + if (RemoveUser != nullptr) { RemoveUser->pushPreamble(); RemoveUser->pushString(name); RemoveUser->run(); @@ -1306,7 +1306,7 @@ public: void setChannels(std::vector channels) { this->channelList = channels; - if (SetChannels != NULL) { + if (SetChannels != nullptr) { SetChannels->pushPreamble(); for (const auto& value : channels) { SetChannels->pushString(value); @@ -1329,7 +1329,7 @@ public: return password; } } - return NULL; + return nullptr; } void setPassword(std::string pw) { @@ -1354,7 +1354,7 @@ public: CHost *getHost() { return host; } void setHost(CHost *arg) { - if (host != NULL) { + if (host != nullptr) { delete host; } host = arg; @@ -1380,7 +1380,7 @@ public: BNCSInputStream *getMsgIStream() { return istream; } - virtual void doOneStep() { if (this->state != NULL) this->state->doOneStep(this); } + virtual void doOneStep() { if (this->state != nullptr) this->state->doOneStep(this); } virtual bool handleUDP(const unsigned char *buffer, int len, CHost host) { if (host.getIp() != getHost()->getIp() || host.getPort() != getHost()->getPort()) { @@ -1415,7 +1415,7 @@ public: void setState(OnlineState* newState) { assert (newState != this->state); - if (this->state != NULL) { + if (this->state != nullptr) { delete this->state; } this->state = newState; @@ -1425,16 +1425,16 @@ public: uint32_t serverToken; uint32_t udpToken; - LuaCallback *AddUser = NULL; - LuaCallback *RemoveUser = NULL; - LuaCallback *SetFriends = NULL; - LuaCallback *SetGames = NULL; - LuaCallback *SetChannels = NULL; - LuaCallback *SetActiveChannel = NULL; - LuaCallback *ShowError = NULL; - LuaCallback *ShowInfo = NULL; - LuaCallback *ShowChat = NULL; - LuaCallback *ShowUserInfo = NULL; + LuaCallback *AddUser = nullptr; + LuaCallback *RemoveUser = nullptr; + LuaCallback *SetFriends = nullptr; + LuaCallback *SetGames = nullptr; + LuaCallback *SetChannels = nullptr; + LuaCallback *SetActiveChannel = nullptr; + LuaCallback *ShowError = nullptr; + LuaCallback *ShowInfo = nullptr; + LuaCallback *ShowChat = nullptr; + LuaCallback *ShowUserInfo = nullptr; private: std::string gameNameFromUsername(std::string username) { @@ -1475,7 +1475,7 @@ int OnlineState::send(Context *ctx, BNCSOutputStream *buf) { void OnlineState::handleNull(Context *ctx) { BNCSOutputStream buffer(0x00); send(ctx, &buffer); - DebugPrint("TCP Sent: 0x00 NULL\n"); + DebugPrint("TCP Sent: 0x00 nullptr\n"); } void OnlineState::handleChannelList(Context *ctx) { @@ -2152,9 +2152,9 @@ class C2S_SID_AUTH_INFO : public OnlineState { } // (UINT32) Time zone bias uint32_t bias = 0; - std::time_t systemtime = std::time(NULL); + std::time_t systemtime = std::time(nullptr); struct std::tm *utc = std::gmtime(&systemtime); - if (utc != NULL) { + if (utc != nullptr) { std::time_t utctime_since_epoch = std::mktime(utc); if (utctime_since_epoch != -1) { struct std::tm *localtime = std::localtime(&systemtime); diff --git a/src/network/xsha1.h b/src/network/xsha1.h index 5b4d31c0a..df37a34ab 100644 --- a/src/network/xsha1.h +++ b/src/network/xsha1.h @@ -387,7 +387,7 @@ namespace pvpgn if (!hash) { - return NULL; + return nullptr; } for (i = 0; i < 5; i++) diff --git a/src/particle/particlemanager.cpp b/src/particle/particlemanager.cpp index 8e1e12270..f4d44a203 100644 --- a/src/particle/particlemanager.cpp +++ b/src/particle/particlemanager.cpp @@ -41,7 +41,7 @@ CParticleManager ParticleManager; CParticleManager::CParticleManager() : - vp(NULL), lastTicks(0) + vp(nullptr), lastTicks(0) { } @@ -93,7 +93,7 @@ void CParticleManager::prepareToDraw(const CViewport &vp, std::vectorvp = NULL; + this->vp = nullptr; } void CParticleManager::update() diff --git a/src/pathfinder/astar.cpp b/src/pathfinder/astar.cpp index 799c2af99..8ea568019 100644 --- a/src/pathfinder/astar.cpp +++ b/src/pathfinder/astar.cpp @@ -380,12 +380,12 @@ void InitAStar(int mapWidth, int mapHeight) void FreeAStar() { aligned_free(AStarMatrix); - AStarMatrix = NULL; + AStarMatrix = nullptr; aligned_free(OpenSet); - OpenSet = NULL; + OpenSet = nullptr; OpenSetSize = 0; aligned_free(CostMoveToCache); - CostMoveToCache = NULL; + CostMoveToCache = nullptr; ProfilePrint(); } diff --git a/src/pathfinder/pathfinder.cpp b/src/pathfinder/pathfinder.cpp index 3e86c8276..6c3b3ff90 100644 --- a/src/pathfinder/pathfinder.cpp +++ b/src/pathfinder/pathfinder.cpp @@ -288,7 +288,7 @@ int CalcPathLengthToUnit(const CUnit &src, const CUnit &dst, const int minrange, dst.Type->TileWidth, dst.Type->TileHeight, src.Type->TileWidth, src.Type->TileHeight, minrange, range, - NULL, 0, src); + nullptr, 0, src); SetAStarFixedEnemyUnitsUnpassable(false); /// restore Path Finder setting switch (length) { case PF_FAILED: @@ -306,7 +306,7 @@ int CalcPathLengthToUnit(const CUnit &src, const CUnit &dst, const int minrange, -- REAL PATH-FINDER ----------------------------------------------------------------------------*/ -PathFinderInput::PathFinderInput() : unit(NULL), minRange(0), maxRange(0), +PathFinderInput::PathFinderInput() : unit(nullptr), minRange(0), maxRange(0), isRecalculatePathNeeded(true) { unitSize.x = 0; @@ -412,7 +412,7 @@ static int NewPath(PathFinderInput &input, PathFinderOutput &output) // Update path if it was requested. Otherwise we may only want // to know if there exists a path. - if (path != NULL) { + if (path != nullptr) { output.Length = std::min(i, PathFinderOutput::MAX_PATH_LENGTH); output.OverflowLength = std::min(i - output.Length, PathFinderOutput::MAX_OVERFLOW); if (output.Length == 0) { diff --git a/src/sound/script_sound.cpp b/src/sound/script_sound.cpp index 851d886de..30946c150 100644 --- a/src/sound/script_sound.cpp +++ b/src/sound/script_sound.cpp @@ -98,7 +98,7 @@ static CSound *CclGetSound(lua_State *l) } } LuaError(l, "CclGetSound: not a sound"); - return NULL; + return nullptr; } /** @@ -231,7 +231,7 @@ static void SetSoundConfigRace(lua_State *l, int j, SoundConfig soundConfigs[]) LuaError(l, "Unknown race: %s" _C_ raceName); } lua_rawgeti(l, j + 1, 2); - LuaUserData *data = NULL; + LuaUserData *data = nullptr; if (!lua_isuserdata(l, -1) || (data = (LuaUserData *)lua_touserdata(l, -1))->Type != LuaSoundType) { LuaError(l, "Sound id expected"); @@ -255,7 +255,7 @@ static int CclDefineGameSounds(lua_State *l) const char *value = LuaToString(l, j + 1); ++j; - LuaUserData *data = NULL; + LuaUserData *data = nullptr; // let's handle now the different cases if (!strcmp(value, "click")) { diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index 1a16bf2b0..cfcf80b82 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -94,15 +94,15 @@ static Mix_Chunk *SimpleChooseSample(const CSound &sound) */ static Mix_Chunk *ChooseSample(CSound *sound, bool selection, Origin &source) { - Mix_Chunk *result = NULL; + Mix_Chunk *result = nullptr; if (!sound || !SoundEnabled()) { - return NULL; + return nullptr; } if (sound->Number == TWO_GROUPS) { // handle a special sound (selection) - if (SelectionHandler.Sound != NULL && (SelectionHandler.Source.Base == source.Base && SelectionHandler.Source.Id == source.Id)) { + if (SelectionHandler.Sound != nullptr && (SelectionHandler.Source.Base == source.Base && SelectionHandler.Source.Id == source.Id)) { if (SelectionHandler.Sound == sound->Sound.TwoGroups.First) { result = SimpleChooseSample(*SelectionHandler.Sound); SelectionHandler.HowMany++; @@ -137,7 +137,7 @@ static Mix_Chunk *ChooseSample(CSound *sound, bool selection, Origin &source) result = SimpleChooseSample(*sound); if (SelectionHandler.Source.Base == source.Base && SelectionHandler.Source.Id == source.Id) { SelectionHandler.HowMany = 0; - SelectionHandler.Sound = NULL; + SelectionHandler.Sound = nullptr; } if (selection) { SelectionHandler.Source = source; @@ -183,7 +183,7 @@ static CSound *ChooseUnitVoiceSound(const CUnit &unit, UnitVoiceGroup voice) case VoiceWorkCompleted: { CSound *workCompleteSound = unit.Type->MapSound.WorkComplete.Sound; - if (workCompleteSound == NULL) { + if (workCompleteSound == nullptr) { workCompleteSound = GameSounds.WorkComplete[ThisPlayer->Race].Sound; } return workCompleteSound; @@ -357,7 +357,7 @@ void PlayMissileSound(const Missile &missile, CSound *sound) ((UI.SelectedViewport->MapWidth - 1) * PixelTileSize.x)) - 128; clamp(&stereo, -128, 127); - Origin source = {NULL, 0}; + Origin source = {nullptr, 0}; unsigned char volume = CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range); if (volume == 0) { return; @@ -382,7 +382,7 @@ void PlayGameSound(CSound *sound, unsigned char volume, bool always) if (!sound) { return; } - Origin source = {NULL, 0}; + Origin source = {nullptr, 0}; Mix_Chunk *sample = ChooseSample(sound, false, source); @@ -406,13 +406,13 @@ static std::map SampleMap; static void PlaySoundFileCallback(int channel) { LuaActionListener *listener = ChannelMap[channel]; - ChannelMap[channel] = NULL; + ChannelMap[channel] = nullptr; // free any previously loaded sample that was playing on this channel before if (SampleMap[channel]) { FreeSample(SampleMap[channel]); - SampleMap[channel] = NULL; + SampleMap[channel] = nullptr; } - if (listener != NULL) { + if (listener != nullptr) { listener->action(""); } } @@ -603,7 +603,7 @@ CSound::~CSound() if (this->Sound.OneGroup[i]) { FreeSample(this->Sound.OneGroup[i]); } - this->Sound.OneGroup[i] = NULL; + this->Sound.OneGroup[i] = nullptr; } delete[] this->Sound.OneGroup; } diff --git a/src/sound/sound_id.cpp b/src/sound/sound_id.cpp index cd99cc076..52123dfdc 100644 --- a/src/sound/sound_id.cpp +++ b/src/sound/sound_id.cpp @@ -58,7 +58,7 @@ static CSound *FindSound(const std::string &name) if (ret != SoundMap.end()) { return (*ret).second; } - return NULL; + return nullptr; } /** @@ -93,7 +93,7 @@ CSound *SoundForName(const std::string &name) return sound; } DebugPrint("Can't find sound '%s' in sound table\n" _C_ name.c_str()); - return NULL; + return nullptr; } /** diff --git a/src/sound/sound_server.cpp b/src/sound/sound_server.cpp index 0a2b25efe..fc930c9b9 100644 --- a/src/sound/sound_server.cpp +++ b/src/sound/sound_server.cpp @@ -77,7 +77,7 @@ static DWORD WINAPI StatusThreadFunction(LPVOID lpParam) { CHAR chStatus; DWORD dwRead = 1; while (1) { - if (!ReadFile((HANDLE)lpParam, &chStatus, 1, &dwRead, NULL) || dwRead == 0) { + if (!ReadFile((HANDLE)lpParam, &chStatus, 1, &dwRead, nullptr) || dwRead == 0) { CloseHandle((HANDLE)lpParam); break; } @@ -94,7 +94,7 @@ static DWORD WINAPI DebugThreadFunction(LPVOID lpParam) { DWORD dwRead = 1; while (1) { char *chStatus[1024] = {'\0'}; - if (!ReadFile((HANDLE)lpParam, &chStatus, 1024, &dwRead, NULL) || dwRead == 0) { + if (!ReadFile((HANDLE)lpParam, &chStatus, 1024, &dwRead, nullptr) || dwRead == 0) { CloseHandle((HANDLE)lpParam); break; } @@ -108,7 +108,7 @@ static void KillPlayingProcess() { if (g_hChildStd_IN_Wr) { TerminateProcess(pi.hProcess, 0); CloseHandle(g_hChildStd_IN_Wr); - g_hChildStd_IN_Wr = NULL; + g_hChildStd_IN_Wr = nullptr; WaitForSingleObject(StatusThreadFunction, 0); WaitForSingleObject(DebugThreadFunction, 0); } @@ -128,7 +128,7 @@ static bool External_Play(const std::string &file) { std::string full_filename = LibraryFileName(file.c_str()); // try to communicate with the running midiplayer if we can - if (g_hChildStd_IN_Wr != NULL) { + if (g_hChildStd_IN_Wr != nullptr) { // already playing, just send the new song // XXX: timfel: disabled, since the midiplayer behaves weirdly when it receives the next file, just kill and restart KillPlayingProcess(); @@ -139,11 +139,11 @@ static bool External_Play(const std::string &file) { char hiSize = (fileSize >> 8) & 0xff; char buf[2] = {loSize, hiSize}; externalPlayerIsPlaying = true; - if (!WriteFile(g_hChildStd_IN_Wr, buf, 2, NULL, NULL)) { + if (!WriteFile(g_hChildStd_IN_Wr, buf, 2, nullptr, nullptr)) { KillPlayingProcess(); } else { // then write the filename - if (!WriteFile(g_hChildStd_IN_Wr, full_filename.c_str(), fileSize, NULL, NULL)) { + if (!WriteFile(g_hChildStd_IN_Wr, full_filename.c_str(), fileSize, nullptr, nullptr)) { KillPlayingProcess(); } else { return true; @@ -154,15 +154,15 @@ static bool External_Play(const std::string &file) { // need to start an external player first // setup pipes to player - HANDLE hChildStd_IN_Rd = NULL; - HANDLE hChildStd_OUT_Rd = NULL; - HANDLE hChildStd_OUT_Wr = NULL; - HANDLE hChildStd_ERR_Rd = NULL; - HANDLE hChildStd_ERR_Wr = NULL; + HANDLE hChildStd_IN_Rd = nullptr; + HANDLE hChildStd_OUT_Rd = nullptr; + HANDLE hChildStd_OUT_Wr = nullptr; + HANDLE hChildStd_ERR_Rd = nullptr; + HANDLE hChildStd_ERR_Wr = nullptr; SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; - saAttr.lpSecurityDescriptor = NULL; + saAttr.lpSecurityDescriptor = nullptr; CreatePipe(&hChildStd_OUT_Rd, &hChildStd_OUT_Wr, &saAttr, 0); CreatePipe(&hChildStd_ERR_Rd, &hChildStd_ERR_Wr, &saAttr, 0); CreatePipe(&hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0); @@ -182,13 +182,13 @@ static bool External_Play(const std::string &file) { ZeroMemory(&pi, sizeof(pi)); bool result = true; char* cmdline = strdup(cmd.c_str()); - if (CreateProcess(NULL, cmdline, NULL, NULL, TRUE, /* Handles are inherited */ CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { + if (CreateProcess(nullptr, cmdline, nullptr, nullptr, TRUE, /* Handles are inherited */ CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi)) { CloseHandle(hChildStd_OUT_Wr); CloseHandle(hChildStd_ERR_Wr); CloseHandle(hChildStd_IN_Rd); externalPlayerIsPlaying = true; - g_hStatusThread = CreateThread(NULL, 0, StatusThreadFunction, hChildStd_OUT_Rd, 0, NULL); - g_hDebugThread = CreateThread(NULL, 0, DebugThreadFunction, hChildStd_ERR_Rd, 0, NULL); + g_hStatusThread = CreateThread(nullptr, 0, StatusThreadFunction, hChildStd_OUT_Rd, 0, nullptr); + g_hDebugThread = CreateThread(nullptr, 0, DebugThreadFunction, hChildStd_ERR_Rd, 0, nullptr); } else { result = false; DebugPrint("CreateProcess failed (%d).\n" _C_ GetLastError()); @@ -215,7 +215,7 @@ static bool External_Stop() { static bool External_Volume(int volume, int oldVolume) { if (External_IsPlaying()) { char buf[2] = {0, volume & 0xFF}; - if (!WriteFile(g_hChildStd_IN_Wr, buf, 2, NULL, NULL)) { + if (!WriteFile(g_hChildStd_IN_Wr, buf, 2, nullptr, nullptr)) { External_Stop(); return false; } @@ -232,8 +232,8 @@ static bool External_Volume(int volume, int oldVolume) { /// Channels for sound effects and unit speech struct SoundChannel { - Origin *Unit = NULL; /// pointer to unit, who plays the sound, if any - void (*FinishedCallback)(int channel) = NULL; /// Callback for when a sample finishes playing + Origin *Unit = nullptr; /// pointer to unit, who plays the sound, if any + void (*FinishedCallback)(int channel) = nullptr; /// Callback for when a sample finishes playing }; #define MaxChannels 64 /// How many channels are supported @@ -275,7 +275,7 @@ static void ChannelFinished(int channel) fprintf(stderr, "ERROR: Out of bounds channel (how?)\n"); return; } - if (Channels[channel].FinishedCallback != NULL) { + if (Channels[channel].FinishedCallback != nullptr) { SDL_Event event; SDL_zero(event); event.type = SDL_SOUND_FINISHED; @@ -284,7 +284,7 @@ static void ChannelFinished(int channel) SDL_PeepEvents(&event, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); } delete Channels[channel].Unit; - Channels[channel].Unit = NULL; + Channels[channel].Unit = nullptr; } void HandleSoundEvent(SDL_Event &event) @@ -338,7 +338,7 @@ Mix_Chunk *GetChannelSample(int channel) if (Mix_Playing(channel)) { return Mix_GetChunk(channel); } - return NULL; + return nullptr; } /** @@ -359,7 +359,7 @@ void StopAllChannels() Mix_HaltChannel(-1); } -static Mix_Music *currentMusic = NULL; +static Mix_Music *currentMusic = nullptr; static Mix_Music *LoadMusic(const char *name) { @@ -376,7 +376,7 @@ static Mix_Music *LoadMusic(const char *name) if (f->open(name, CL_OPEN_READ) == -1) { printf("Can't open file '%s'\n", name); delete f; - return NULL; + return nullptr; } currentMusic = Mix_LoadMUS_RW(f->as_SDL_RWops(), 1); return currentMusic; @@ -392,7 +392,7 @@ static Mix_Chunk *ForceLoadSample(const char *name) if (f->open(name, CL_OPEN_READ) == -1) { printf("Can't open file '%s'\n", name); delete f; - return NULL; + return nullptr; } return Mix_LoadWAV_RW(f->as_SDL_RWops(), 1); } @@ -421,7 +421,7 @@ Mix_Music *LoadMusic(const std::string &name) const std::string filename = LibraryFileName(name.c_str()); Mix_Music *music = LoadMusic(filename.c_str()); - if (music == NULL) { + if (music == nullptr) { fprintf(stderr, "Can't load the music '%s'\n", name.c_str()); } return music; @@ -441,7 +441,7 @@ Mix_Chunk *LoadSample(const std::string &name) const std::string filename = LibraryFileName(name.c_str()); Mix_Chunk *sample = LoadSample(filename.c_str()); - if (sample == NULL) { + if (sample == nullptr) { fprintf(stderr, "Can't load the sound '%s': %s\n", name.c_str(), Mix_GetError()); } return sample; @@ -505,12 +505,12 @@ static int PlaySample(Mix_Chunk *sample, Origin *origin, void (*callback)(int ch int PlaySample(Mix_Chunk *sample, Origin *origin) { - return PlaySample(sample, origin, NULL); + return PlaySample(sample, origin, nullptr); } int PlaySample(Mix_Chunk *sample, void (*callback)(int channel)) { - return PlaySample(sample, NULL, callback); + return PlaySample(sample, nullptr, callback); } /** diff --git a/src/sound/unitsound.cpp b/src/sound/unitsound.cpp index 69fac0a8c..e329f1e15 100644 --- a/src/sound/unitsound.cpp +++ b/src/sound/unitsound.cpp @@ -64,7 +64,7 @@ bool SoundConfig::MapSound() if (!this->Name.empty()) { this->Sound = SoundForName(this->Name); } - return this->Sound != NULL; + return this->Sound != nullptr; } void SoundConfig::SetSoundRange(unsigned char range) @@ -99,7 +99,7 @@ static void MapAnimSound(CAnimation &anim) */ static void MapAnimSounds2(CAnimation *anim) { - if (anim == NULL) { + if (anim == nullptr) { return ; } MapAnimSound(*anim); diff --git a/src/spell/script_spell.cpp b/src/spell/script_spell.cpp index 1c8494cbd..2221c070a 100644 --- a/src/spell/script_spell.cpp +++ b/src/spell/script_spell.cpp @@ -73,7 +73,7 @@ static SpellActionType *CclSpellAction(lua_State *l) const char *value = LuaToString(l, -1, 1); - SpellActionType *spellaction = NULL; + SpellActionType *spellaction = nullptr; if (!strcmp(value, "adjust-variable")) { spellaction = new Spell_AdjustVariable; } else if (!strcmp(value, "adjust-vitals")) { @@ -307,7 +307,7 @@ static int CclDefineSpell(lua_State *l) const int args = lua_gettop(l); const std::string identname = LuaToString(l, 1); SpellType *spell = SpellTypeByIdent(identname); - if (spell != NULL) { + if (spell != nullptr) { DebugPrint("Redefining spell-type '%s'\n" _C_ identname.c_str()); } else { spell = new SpellType(SpellTypeTable.size(), identname); diff --git a/src/spell/spell_areabombardment.cpp b/src/spell/spell_areabombardment.cpp index f89fb78fc..f7c92ba02 100644 --- a/src/spell/spell_areabombardment.cpp +++ b/src/spell/spell_areabombardment.cpp @@ -58,7 +58,7 @@ } else if (!strcmp(value, "missile")) { value = LuaToString(l, -1, j + 1); this->Missile = MissileTypeByIdent(value); - if (this->Missile == NULL) { + if (this->Missile == nullptr) { DebugPrint("in area-bombardement : missile %s does not exist\n" _C_ value); } } else { @@ -66,7 +66,7 @@ } } // Now, checking value. - if (this->Missile == NULL) { + if (this->Missile == nullptr) { LuaError(l, "Use a missile for area-bombardment (with missile)"); } } diff --git a/src/spell/spell_capture.cpp b/src/spell/spell_capture.cpp index 27b86e10c..c71f437af 100644 --- a/src/spell/spell_capture.cpp +++ b/src/spell/spell_capture.cpp @@ -83,7 +83,7 @@ HitUnit(&caster, *target, this->Damage); if (this->SacrificeEnable) { // No corpse. - caster.Remove(NULL); + caster.Remove(nullptr); caster.Release(); } return 1; @@ -118,7 +118,7 @@ } if (this->SacrificeEnable) { // No corpse. - caster.Remove(NULL); + caster.Remove(nullptr); caster.Release(); } else { caster.Variable[MANA_INDEX].Value -= spell.ManaCost; diff --git a/src/spell/spell_polymorph.cpp b/src/spell/spell_polymorph.cpp index 8d8a09a58..f49d7c402 100644 --- a/src/spell/spell_polymorph.cpp +++ b/src/spell/spell_polymorph.cpp @@ -63,7 +63,7 @@ } } // Now, checking value. - if (this->NewForm == NULL) { + if (this->NewForm == nullptr) { LuaError(l, "Use a unittype for polymorph (with new-form)"); } } @@ -105,7 +105,7 @@ } // as said somewhere else -- no corpses :) - target->Remove(NULL); + target->Remove(nullptr); Vec2i offset; caster.Variable[MANA_INDEX].Value -= spell.ManaCost; Vec2i resPos; diff --git a/src/spell/spell_spawnmissile.cpp b/src/spell/spell_spawnmissile.cpp index 30d6eb7d6..5ae02c558 100644 --- a/src/spell/spell_spawnmissile.cpp +++ b/src/spell/spell_spawnmissile.cpp @@ -68,7 +68,7 @@ struct CompareUnitDistance { */ static void CclSpellMissileLocation(lua_State *l, SpellActionMissileLocation *location) { - Assert(location != NULL); + Assert(location != nullptr); if (!lua_istable(l, -1)) { LuaError(l, "incorrect argument"); @@ -125,7 +125,7 @@ static void CclSpellMissileLocation(lua_State *l, SpellActionMissileLocation *lo } else if (!strcmp(value, "missile")) { value = LuaToString(l, -1, j + 1); this->Missile = MissileTypeByIdent(value); - if (this->Missile == NULL) { + if (this->Missile == nullptr) { DebugPrint("in spawn-missile : missile %s does not exist\n" _C_ value); } } else { @@ -133,7 +133,7 @@ static void CclSpellMissileLocation(lua_State *l, SpellActionMissileLocation *lo } } // Now, checking value. - if (this->Missile == NULL) { + if (this->Missile == nullptr) { LuaError(l, "Use a missile for spawn-missile (with missile)"); } } diff --git a/src/spell/spell_spawnportal.cpp b/src/spell/spell_spawnportal.cpp index 895f0a062..4a4e06304 100644 --- a/src/spell/spell_spawnportal.cpp +++ b/src/spell/spell_spawnportal.cpp @@ -59,7 +59,7 @@ } } // Now, checking value. - if (this->PortalType == NULL) { + if (this->PortalType == nullptr) { LuaError(l, "Use a unittype for spawn-portal (with portal-type)"); } } diff --git a/src/spell/spell_summon.cpp b/src/spell/spell_summon.cpp index a85e73646..55f1ffe9a 100644 --- a/src/spell/spell_summon.cpp +++ b/src/spell/spell_summon.cpp @@ -69,7 +69,7 @@ } } // Now, checking value. - if (this->UnitType == NULL) { + if (this->UnitType == nullptr) { LuaError(l, "Use a unittype for summon (with unit-type)"); } } @@ -109,9 +109,9 @@ public: CUnit *unit = FindUnit_If(minPos, maxPos, IsDyingAndNotABuilding()); cansummon = false; - if (unit != NULL) { // Found a corpse. eliminate it and proceed to summoning. + if (unit != nullptr) { // Found a corpse. eliminate it and proceed to summoning. pos = unit->tilePos; - unit->Remove(NULL); + unit->Remove(nullptr); unit->Release(); cansummon = true; } @@ -127,9 +127,9 @@ public: // FIXME: do summoned units count on food? // target = MakeUnit(unittype, caster.Player); - if (target != NULL) { + if (target != nullptr) { target->tilePos = pos; - DropOutOnSide(*target, LookingW, NULL); + DropOutOnSide(*target, LookingW, nullptr); // To avoid defending summoned unit for AI // we also use this value to store when this // unit was summoned diff --git a/src/spell/spell_teleport.cpp b/src/spell/spell_teleport.cpp index 07abe0f1b..fa1427485 100644 --- a/src/spell/spell_teleport.cpp +++ b/src/spell/spell_teleport.cpp @@ -60,9 +60,9 @@ { if (Map.Info.IsPointOnMap(goalPos)) { unsigned int selected = caster.Selected; - caster.Remove(NULL); + caster.Remove(nullptr); caster.tilePos = goalPos; - DropOutNearest(caster, goalPos, NULL); + DropOutNearest(caster, goalPos, nullptr); if (selected) { SelectUnit(caster); } diff --git a/src/spell/spells.cpp b/src/spell/spells.cpp index fd8b43c08..b107d3222 100644 --- a/src/spell/spells.cpp +++ b/src/spell/spells.cpp @@ -130,7 +130,7 @@ static bool PassCondition(const CUnit &caster, const SpellType &spell, const CUn unit = (condition->Variable[i].ConditionApplyOnCaster) ? &caster : target; // Spell should target location and have unit condition. - if (unit == NULL) { + if (unit == nullptr) { continue; } if (condition->Variable[i].Enable != CONDITION_TRUE) { @@ -286,7 +286,7 @@ static Target *SelectTargetUnitsOfAutoCast(CUnit &caster, const SpellType &spell } } if ((autocast->Combat == CONDITION_ONLY) ^ (inCombat)) { - return NULL; + return nullptr; } } @@ -296,7 +296,7 @@ static Target *SelectTargetUnitsOfAutoCast(CUnit &caster, const SpellType &spell && PassCondition(caster, spell, &caster, pos, autocast->Condition)) { return NewTargetUnit(caster); } - return NULL; + return nullptr; case TargetPosition: { if (autocast->PositionAutoCast && table.empty() == false) { size_t count = 0; @@ -331,7 +331,7 @@ static Target *SelectTargetUnitsOfAutoCast(CUnit &caster, const SpellType &spell autocast->PositionAutoCast->run(2); Vec2i resPos(autocast->PositionAutoCast->popInteger(), autocast->PositionAutoCast->popInteger()); if (Map.Info.IsPointOnMap(resPos)) { - Target *target = new Target(TargetPosition, NULL, resPos); + Target *target = new Target(TargetPosition, nullptr, resPos); return target; } } @@ -387,10 +387,10 @@ static Target *SelectTargetUnitsOfAutoCast(CUnit &caster, const SpellType &spell // Something is wrong DebugPrint("Spell is screwed up, unknown target type\n"); Assert(0); - return NULL; + return nullptr; break; } - return NULL; // Can't spell the auto-cast. + return nullptr; // Can't spell the auto-cast. } // **************************************************************************** @@ -422,7 +422,7 @@ SpellType *SpellTypeByIdent(const std::string &ident) return *i; } } - return NULL; + return nullptr; } // **************************************************************************** @@ -457,7 +457,7 @@ bool SpellIsAvailable(const CPlayer &player, int spellid) bool CanCastSpell(const CUnit &caster, const SpellType &spell, const CUnit *target, const Vec2i &goalPos) { - if (spell.Target == TargetUnit && target == NULL) { + if (spell.Target == TargetUnit && target == nullptr) { return false; } return PassCondition(caster, spell, target, goalPos, spell.Condition); @@ -480,18 +480,18 @@ int AutoCastSpell(CUnit &caster, const SpellType &spell) return 0; } Target *target = SelectTargetUnitsOfAutoCast(caster, spell); - if (target == NULL) { + if (target == nullptr) { return 0; } else { // Save previous order - COrder *savedOrder = NULL; + COrder *savedOrder = nullptr; if (caster.CurrentAction() != UnitActionStill && caster.CanStoreOrder(caster.CurrentOrder())) { savedOrder = caster.CurrentOrder()->Clone(); } // Must move before ? CommandSpellCast(caster, target->targetPos, target->Unit, spell, FlushCommands, true); delete target; - if (savedOrder != NULL) { + if (savedOrder != nullptr) { caster.SavedOrder = savedOrder; } } @@ -574,8 +574,8 @@ int SpellCast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i SpellType::SpellType(int slot, const std::string &ident) : Ident(ident), Slot(slot), Target(), Action(), Range(0), ManaCost(0), RepeatCast(0), CoolDown(0), - DependencyId(-1), Condition(NULL), - AutoCast(NULL), AICast(NULL), ForceUseAnimation(false) + DependencyId(-1), Condition(nullptr), + AutoCast(nullptr), AICast(nullptr), ForceUseAnimation(false) { memset(Costs, 0, sizeof(Costs)); } diff --git a/src/stratagus/construct.cpp b/src/stratagus/construct.cpp index 96efae3bb..2d2b15f6c 100644 --- a/src/stratagus/construct.cpp +++ b/src/stratagus/construct.cpp @@ -65,11 +65,11 @@ CConstruction::~CConstruction() void CConstruction::Clean() { CGraphic::Free(this->Sprite); - this->Sprite = NULL; + this->Sprite = nullptr; CGraphic::Free(this->ShadowSprite); - this->ShadowSprite = NULL; + this->ShadowSprite = nullptr; CConstructionFrame *cframe = this->Frames; - this->Frames = NULL; + this->Frames = nullptr; while (cframe) { CConstructionFrame *next = cframe->Next; delete cframe; @@ -170,7 +170,7 @@ CConstruction *ConstructionByIdent(const std::string &name) return *it; } } - return NULL; + return nullptr; } /** @@ -192,7 +192,7 @@ static int CclDefineConstruction(lua_State *l) CConstruction *construction = ConstructionByIdent(str); std::vector::iterator i; - if (construction == NULL) { + if (construction == nullptr) { construction = new CConstruction; Constructions.push_back(construction); } else { // redefine completely. @@ -280,7 +280,7 @@ static int CclDefineConstruction(lua_State *l) (*cframe)->Percent = percent; (*cframe)->File = file; (*cframe)->Frame = frame; - (*cframe)->Next = NULL; + (*cframe)->Next = nullptr; } } else { LuaError(l, "Unsupported tag: %s" _C_ value); diff --git a/src/stratagus/groups.cpp b/src/stratagus/groups.cpp index bbccf5eac..5bd11ec97 100644 --- a/src/stratagus/groups.cpp +++ b/src/stratagus/groups.cpp @@ -260,7 +260,7 @@ static int CclGroup(lua_State *l) const int args = lua_rawlen(l, 3); for (int j = 0; j < args; ++j) { const char *str = LuaToString(l, 3, j + 1); - grp.add(UnitManager->GetSlotUnit(strtol(str + 1, NULL, 16)), grpNum); + grp.add(UnitManager->GetSlotUnit(strtol(str + 1, nullptr, 16)), grpNum); } return 0; } diff --git a/src/stratagus/iolib.cpp b/src/stratagus/iolib.cpp index ffed3021b..92a43ead6 100644 --- a/src/stratagus/iolib.cpp +++ b/src/stratagus/iolib.cpp @@ -164,7 +164,7 @@ int CFile::printf(const char *format, ...) { int size = 500; char *p = new char[size]; - if (p == NULL) { + if (p == nullptr) { return -1; } while (1) { @@ -185,7 +185,7 @@ int CFile::printf(const char *format, ...) } delete[] p; p = new char[size]; - if (p == NULL) { + if (p == nullptr) { return -1; } } @@ -728,7 +728,7 @@ int ReadDataDirectory(const char *dirname, std::vector &fl) struct dirent *dp; if (dirp) { - while ((dp = readdir(dirp)) != NULL) { + while ((dp = readdir(dirp)) != nullptr) { filename = dp->d_name; #else strcat_s(buffer, sizeof(buffer), "*.*"); diff --git a/src/stratagus/mainloop.cpp b/src/stratagus/mainloop.cpp index a3d8886a2..870da5361 100644 --- a/src/stratagus/mainloop.cpp +++ b/src/stratagus/mainloop.cpp @@ -164,7 +164,7 @@ void DrawMapArea(const fieldHighlightChecker highlightChecker = nullptr) // Center viewport on tracked unit if (vp->Unit) { if (vp->Unit->Destroyed || vp->Unit->CurrentAction() == UnitActionDie) { - vp->Unit = NULL; + vp->Unit = nullptr; } else { vp->Center(vp->Unit->GetMapPixelPosCenter()); } diff --git a/src/stratagus/parameters.cpp b/src/stratagus/parameters.cpp index c0402b8a9..4f63d702b 100644 --- a/src/stratagus/parameters.cpp +++ b/src/stratagus/parameters.cpp @@ -65,7 +65,7 @@ void Parameters::SetDefaultUserDirectory(bool noPortable) } } char data_path[4096] = {'\0'}; - SHGetFolderPathA(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0, data_path); + SHGetFolderPathA(nullptr, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, nullptr, 0, data_path); if (data_path[0]) { userDirectory = std::string(data_path) + "/Stratagus"; } else if (getenv("APPDATA")) { @@ -90,7 +90,7 @@ void Parameters::SetDefaultUserDirectory(bool noPortable) static std::string GetLocalPlayerNameFromEnv() { - const char *userName = NULL; + const char *userName = nullptr; #ifdef USE_WIN32 userName = getenv("USERNAME"); diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp index 8dc90fc2e..b4da1ad8d 100644 --- a/src/stratagus/player.cpp +++ b/src/stratagus/player.cpp @@ -383,7 +383,7 @@ void InitPlayers() */ void CleanPlayers() { - ThisPlayer = NULL; + ThisPlayer = nullptr; CPlayer::RevealedPlayers.clear(); for (unsigned int i = 0; i < PlayerMax; ++i) { Players[i].Clear(); @@ -842,7 +842,7 @@ void CPlayer::RemoveUnit(CUnit &unit) Assert(unit.Player == this); Assert(this->Units[unit.PlayerSlot] == &unit); - // unit.Player = NULL; // we can remove dying unit... + // unit.Player = nullptr; // we can remove dying unit... CUnit *last = this->Units.back(); this->Units[unit.PlayerSlot] = last; diff --git a/src/stratagus/script.cpp b/src/stratagus/script.cpp index 61fcec1b3..14995dcc7 100644 --- a/src/stratagus/script.cpp +++ b/src/stratagus/script.cpp @@ -105,7 +105,7 @@ int lua_isstring_strict(lua_State *luaStack, int idx) { static void lstop(lua_State *l, lua_Debug *ar) { (void)ar; // unused arg. - lua_sethook(l, NULL, 0, 0); + lua_sethook(l, nullptr, 0, 0); luaL_error(l, "interrupted!"); } @@ -133,7 +133,7 @@ static int report(int status, bool exitOnError) { if (status) { const char *msg = lua_tostring(Lua, -1); - if (msg == NULL) { + if (msg == nullptr) { msg = "(error with no message)"; } fprintf(stderr, "%s\n", msg); @@ -509,7 +509,7 @@ static CUnit **Str2UnitRef(lua_State *l, const char *s) Assert(l); Assert(s); - res = NULL; + res = nullptr; if (!strcmp(s, "Attacker")) { res = &TriggerData.Attacker; } else if (!strcmp(s, "Defender")) { @@ -535,7 +535,7 @@ static CUnit **Str2UnitRef(lua_State *l, const char *s) */ static CUnitType **Str2TypeRef(lua_State *l, const char *s) { - CUnitType **res = NULL; // Result. + CUnitType **res = nullptr; // Result. Assert(l); if (!strcmp(s, "Type")) { @@ -578,7 +578,7 @@ UnitDesc *CclParseUnitDesc(lua_State *l) */ CUnitType **CclParseTypeDesc(lua_State *l) { - CUnitType **res = NULL; + CUnitType **res = nullptr; if (lua_isstring(l, -1)) { res = Str2TypeRef(l, LuaToString(l, -1)); @@ -938,7 +938,7 @@ StringDesc *CclParseStringDesc(lua_State *l) lua_rawgeti(l, -1, 3); // Length. res->D.Line.MaxLen = CclParseNumberDesc(l); } - res->D.Line.Font = NULL; + res->D.Line.Font = nullptr; if (lua_rawlen(l, -1) >= 4) { lua_rawgeti(l, -1, 4); // Font. res->D.Line.Font = CFont::Get(LuaToString(l, -1)); @@ -982,7 +982,7 @@ CUnit *EvalUnit(const UnitDesc *unitdesc) case EUnit_Ref : return *unitdesc->D.AUnit; } - return NULL; + return nullptr; } /** @@ -992,7 +992,7 @@ CUnit *EvalUnit(const UnitDesc *unitdesc) ** ** @return the result number. ** -** @todo Manage better the error (div/0, unit==NULL, ...). +** @todo Manage better the error (div/0, unit==nullptr, ...). */ int EvalNumber(const NumberDesc *number) { @@ -1059,7 +1059,7 @@ int EvalNumber(const NumberDesc *number) return SyncRand() % a; case ENumber_UnitStat : // property of unit. unit = EvalUnit(number->D.UnitStat.Unit); - if (unit != NULL) { + if (unit != nullptr) { return GetComponent(*unit, number->D.UnitStat.Index, number->D.UnitStat.Component, number->D.UnitStat.Loc).i; } else { // ERROR. @@ -1067,21 +1067,21 @@ int EvalNumber(const NumberDesc *number) } case ENumber_TypeStat : // property of unit type. type = number->D.TypeStat.Type; - if (type != NULL) { + if (type != nullptr) { return GetComponent(**type, number->D.TypeStat.Index, number->D.TypeStat.Component, number->D.TypeStat.Loc).i; } else { // ERROR. return 0; } case ENumber_VideoTextLength : // VideoTextLength(font, s) - if (number->D.VideoTextLength.String != NULL + if (number->D.VideoTextLength.String != nullptr && !(s = EvalString(number->D.VideoTextLength.String)).empty()) { return number->D.VideoTextLength.Font->Width(s); } else { // ERROR. return 0; } case ENumber_StringFind : // s.find(c) - if (number->D.StringFind.String != NULL + if (number->D.StringFind.String != nullptr && !(s = EvalString(number->D.StringFind.String)).empty()) { size_t pos = s.find(number->D.StringFind.C); return pos != std::string::npos ? (int)pos : -1; @@ -1144,7 +1144,7 @@ std::string EvalString(const StringDesc *s) return res; case EString_UnitName : // name of the UnitType unit = EvalUnit(s->D.Unit); - if (unit != NULL) { + if (unit != nullptr) { return unit->Type->Name; } else { // ERROR. return std::string(""); @@ -1158,7 +1158,7 @@ std::string EvalString(const StringDesc *s) return std::string(""); } case EString_SubString : // substring(s, begin, end) - if (s->D.SubString.String != NULL + if (s->D.SubString.String != nullptr && !(tmp1 = EvalString(s->D.SubString.String)).empty()) { int begin; int end; @@ -1181,7 +1181,7 @@ std::string EvalString(const StringDesc *s) return std::string(""); } case EString_Line : // line n of the string - if (s->D.Line.String == NULL || (tmp1 = EvalString(s->D.Line.String)).empty()) { + if (s->D.Line.String == nullptr || (tmp1 = EvalString(s->D.Line.String)).empty()) { return std::string(""); // ERROR. } else { int line; @@ -1404,18 +1404,18 @@ static int AliasTypeVar(lua_State *l, const char *s) if (nargs >= 3) { // Warning: type is for unit->Stats->Var... // and Initial is for unit->Type->Var... (no upgrade modification) - const char *sloc[] = {"Unit", "Initial", "Type", NULL}; + const char *sloc[] = {"Unit", "Initial", "Type", nullptr}; int i; const char *key; key = LuaToString(l, 3); - for (i = 0; sloc[i] != NULL; i++) { + for (i = 0; sloc[i] != nullptr; i++) { if (!strcmp(key, sloc[i])) { lua_pushnumber(l, i); break ; } } - if (sloc[i] == NULL) { + if (sloc[i] == nullptr) { LuaError(l, "Bad loc :'%s'" _C_ key); } } else { @@ -1466,18 +1466,18 @@ static int AliasUnitVar(lua_State *l, const char *s) if (nargs >= 3) { // Warning: type is for unit->Stats->Var... // and Initial is for unit->Type->Var... (no upgrade modification) - const char *sloc[] = {"Unit", "Initial", "Type", NULL}; + const char *sloc[] = {"Unit", "Initial", "Type", nullptr}; int i; const char *key; key = LuaToString(l, 3); - for (i = 0; sloc[i] != NULL; i++) { + for (i = 0; sloc[i] != nullptr; i++) { if (!strcmp(key, sloc[i])) { lua_pushnumber(l, i); break ; } } - if (sloc[i] == NULL) { + if (sloc[i] == nullptr) { LuaError(l, "Bad loc :'%s'" _C_ key); } } else { @@ -2224,7 +2224,7 @@ void InitLua() {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, - {NULL, NULL} + {nullptr, nullptr} }; Lua = luaL_newstate(); @@ -2549,8 +2549,8 @@ void LoadCcl(const std::string &filename, const std::string &luaArgStr) fs::path GetAVolumePath(__in PWCHAR VolumeName) { DWORD CharCount = MAX_PATH + 1; - PWCHAR Names = NULL; - PWCHAR NameIdx = NULL; + PWCHAR Names = nullptr; + PWCHAR NameIdx = nullptr; BOOL Success = FALSE; for (;;) { @@ -2570,13 +2570,13 @@ fs::path GetAVolumePath(__in PWCHAR VolumeName) } delete [] Names; - Names = NULL; + Names = nullptr; } for (NameIdx = Names; NameIdx[0] != L'\0'; NameIdx += wcslen(NameIdx) + 1) { fs::path result(NameIdx); delete [] Names; - Names = NULL; + Names = nullptr; return result; } diff --git a/src/stratagus/selection.cpp b/src/stratagus/selection.cpp index e77c823bc..0bbeedb9b 100644 --- a/src/stratagus/selection.cpp +++ b/src/stratagus/selection.cpp @@ -112,7 +112,7 @@ void UnSelectAll() Selected[i]->Selected = 0; } Selected.clear(); - UI.SelectedViewport->Unit = NULL; + UI.SelectedViewport->Unit = nullptr; } /** @@ -292,7 +292,7 @@ void UnSelectUnit(CUnit &unit) unit.Selected = 0; //Turn track unit mode off - UI.SelectedViewport->Unit = NULL; + UI.SelectedViewport->Unit = nullptr; } /** @@ -1135,7 +1135,7 @@ static int CclSelection(lua_State *l) const int args = lua_rawlen(l, 2); for (int j = 0; j < args; ++j) { const char *str = LuaToString(l, 2, j + 1); - Selected.push_back(&UnitManager->GetSlotUnit(strtol(str + 1, NULL, 16))); + Selected.push_back(&UnitManager->GetSlotUnit(strtol(str + 1, nullptr, 16))); } return 0; } diff --git a/src/stratagus/stratagus.cpp b/src/stratagus/stratagus.cpp index a1fbad569..d70768292 100644 --- a/src/stratagus/stratagus.cpp +++ b/src/stratagus/stratagus.cpp @@ -675,12 +675,12 @@ void ParseCommandLine(int argc, char **argv, Parameters ¶meters) static LONG WINAPI CreateDumpFile(EXCEPTION_POINTERS *ExceptionInfo) { HANDLE hFile = CreateFile("crash.dmp", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); MINIDUMP_EXCEPTION_INFORMATION mei; mei.ThreadId = GetCurrentThreadId(); mei.ClientPointers = TRUE; mei.ExceptionPointers = ExceptionInfo; - MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &mei, NULL, NULL); + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &mei, nullptr, nullptr); fprintf(stderr, "Stratagus crashed!\n"); fprintf(stderr, "A mini dump file \"crash.dmp\" has been created in the Stratagus folder.\n"); fprintf(stderr, "Please send it to our bug tracker: https://github.com/Wargus/stratagus/issues\n"); @@ -719,7 +719,7 @@ int stratagusMain(int argc, char **argv) // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), - CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); + CFSTR(MAC_BUNDLE_DATADIR), nullptr, nullptr); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); @@ -772,7 +772,7 @@ int stratagusMain(int argc, char **argv) PrintLicense(); #ifndef DEBUG // For debug it's better not to have: - srand(time(NULL)); // Random counter = random each start + srand(time(nullptr)); // Random counter = random each start #endif // Show title screens. @@ -785,7 +785,7 @@ int stratagusMain(int argc, char **argv) } // Init player data - ThisPlayer = NULL; + ThisPlayer = nullptr; //Don't clear the Players structure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; diff --git a/src/stratagus/title.cpp b/src/stratagus/title.cpp index 5db0f2deb..4852c9612 100644 --- a/src/stratagus/title.cpp +++ b/src/stratagus/title.cpp @@ -139,7 +139,7 @@ void TitleScreen::ShowTitleImage() callbacks.KeyReleased = WaitCallbackKeyReleased; callbacks.KeyRepeated = WaitCallbackKeyRepeated; //callbacks.NetworkEvent = NetworkEvent; - callbacks.NetworkEvent = NULL; + callbacks.NetworkEvent = nullptr; SetCallbacks(&callbacks); diff --git a/src/stratagus/translate.cpp b/src/stratagus/translate.cpp index bc14e8896..88e1f4857 100644 --- a/src/stratagus/translate.cpp +++ b/src/stratagus/translate.cpp @@ -92,7 +92,7 @@ void LoadPO(const char *file) enum { MSGNONE, MSGID, MSGSTR } state = MSGNONE; char msgid[16 * 1024]; char msgstr[16 * 1024]; - char *currmsg = NULL; + char *currmsg = nullptr; msgid[0] = msgstr[0] = '\0'; diff --git a/src/stratagus/util.cpp b/src/stratagus/util.cpp index f00f58054..72f78fd64 100644 --- a/src/stratagus/util.cpp +++ b/src/stratagus/util.cpp @@ -218,7 +218,7 @@ uint32_t fletcher32(const std::string &content) #ifndef HAVE_STRCPYS errno_t strcpy_s(char *dst, size_t dstsize, const char *src) { - if (dst == NULL || src == NULL) { + if (dst == nullptr || src == nullptr) { return EINVAL; } if (strlen(src) >= dstsize) { @@ -247,7 +247,7 @@ size_t strnlen(const char *str, size_t strsize) noexcept #ifndef HAVE_STRNCPYS errno_t strncpy_s(char *dst, size_t dstsize, const char *src, size_t count) { - if (dst == NULL || src == NULL || dstsize == 0) { + if (dst == nullptr || src == nullptr || dstsize == 0) { return EINVAL; } @@ -276,7 +276,7 @@ errno_t strncpy_s(char *dst, size_t dstsize, const char *src, size_t count) #ifndef HAVE_STRCATS errno_t strcat_s(char *dst, size_t dstsize, const char *src) { - if (dst == NULL || src == NULL) { + if (dst == nullptr || src == nullptr) { return EINVAL; } char *enddst = dst; @@ -303,14 +303,14 @@ errno_t strcat_s(char *dst, size_t dstsize, const char *src) ** @param a String to search in ** @param b Substring to search for ** -** @return Pointer to first occurrence of b or NULL if not found. +** @return Pointer to first occurrence of b or nullptr if not found. */ const char *strcasestr(const char *a, const char *b) noexcept { int x; if (!a || !*a || !b || !*b || strlen(a) < strlen(b)) { - return NULL; + return nullptr; } x = 0; @@ -325,7 +325,7 @@ const char *strcasestr(const char *a, const char *b) noexcept } } - return NULL; + return nullptr; } #endif // !HAVE_STRCASESTR @@ -371,7 +371,7 @@ int getopt(int argc, char *const *argv, const char *opts) noexcept int c; const char *cp; - optarg = NULL; + optarg = nullptr; if (sp == 1) { if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') { @@ -382,7 +382,7 @@ int getopt(int argc, char *const *argv, const char *opts) noexcept } } optopt = c = argv[optind][sp]; - if (c == ':' || (cp = strchr(opts, c)) == NULL) { + if (c == ':' || (cp = strchr(opts, c)) == nullptr) { getopt_err(argv[0], ": illegal option -", (char)c); cp = "xx"; /* make the next if false */ c = '?'; @@ -657,7 +657,7 @@ std::string GetExecutablePath() #ifdef WIN32 char executable_path[MAX_PATH]; memset(executable_path, 0, sizeof(executable_path)); - GetModuleFileName(NULL, executable_path, sizeof(executable_path)-1); + GetModuleFileName(nullptr, executable_path, sizeof(executable_path)-1); #else char *executable_path = const_cast(OriginalArgv[0].c_str()); #endif diff --git a/src/ui/botpanel.cpp b/src/ui/botpanel.cpp index 8188ed8fa..a26335114 100644 --- a/src/ui/botpanel.cpp +++ b/src/ui/botpanel.cpp @@ -181,7 +181,7 @@ int AddButton(int pos, int level, const std::string &icon_ident, ba->UnitMask = buf; UnitButtonTable.push_back(ba); // FIXME: check if already initited - //Assert(ba->Icon.Icon != NULL);// just checks, that's why at the end + //Assert(ba->Icon.Icon != nullptr);// just checks, that's why at the end return 1; } @@ -198,7 +198,7 @@ void CleanButtons() UnitButtonTable.clear(); CurrentButtonLevel = 0; - LastDrawnButtonPopup = NULL; + LastDrawnButtonPopup = nullptr; CurrentButtons.clear(); } @@ -644,7 +644,7 @@ void DrawPopup(const ButtonAction &button, const CUIButton &uibutton, int x, int CLabel label(font, "white", "red"); // FIXME: hardcoded image!!! const int IconID = GoldCost; - //SetCosts(SpellTypeTable[button->Value]->ManaCost, 0, NULL); + //SetCosts(SpellTypeTable[button->Value]->ManaCost, 0, nullptr); const CGraphic *G = UI.Resources[IconID].G; const SpellType *spell = SpellTypeTable[button->Value]; @@ -1233,7 +1233,7 @@ void CButtonPanel::DoClicked_StandGround() void CButtonPanel::DoClicked_Button(int button) { CurrentButtonLevel = CurrentButtons[button].Value; - LastDrawnButtonPopup = NULL; + LastDrawnButtonPopup = nullptr; UI.ButtonPanel.Update(); } @@ -1256,14 +1256,14 @@ void CButtonPanel::DoClicked_CancelUpgrade() CurrentButtonLevel = 0; UI.ButtonPanel.Update(); GameCursor = UI.Point.Cursor; - CursorBuilding = NULL; + CursorBuilding = nullptr; CursorState = CursorStatePoint; } void CButtonPanel::DoClicked_CancelTrain() { Assert(Selected[0]->CurrentAction() == UnitActionTrain); - SendCommandCancelTraining(*Selected[0], -1, NULL); + SendCommandCancelTraining(*Selected[0], -1, nullptr); UI.StatusLine.Clear(); UI.StatusLine.ClearCosts(); } diff --git a/src/ui/button_checks.cpp b/src/ui/button_checks.cpp index 4bdd9bc6e..608e2d363 100644 --- a/src/ui/button_checks.cpp +++ b/src/ui/button_checks.cpp @@ -116,10 +116,10 @@ bool ButtonCheckUnitVariable(const CUnit &unit, const ButtonAction &button) { char *buf = new_strdup(button.AllowStr.c_str()); - for (const char *var = strtok(buf, ","); var; var = strtok(NULL, ",")) { - const char *type = strtok(NULL, ","); - const char *binop = strtok(NULL, ","); - const char *value = strtok(NULL, ","); + for (const char *var = strtok(buf, ","); var; var = strtok(nullptr, ",")) { + const char *type = strtok(nullptr, ","); + const char *binop = strtok(nullptr, ","); + const char *value = strtok(nullptr, ","); const int index = UnitTypeVar.VariableNameLookup[var];// User variables if (index == -1) { fprintf(stderr, "Bad variable name '%s'\n", var); @@ -183,7 +183,7 @@ bool ButtonCheckUnitsOr(const CUnit &unit, const ButtonAction &button) CPlayer *player = unit.Player; char *buf = new_strdup(button.AllowStr.c_str()); - for (const char *s = strtok(buf, ","); s; s = strtok(NULL, ",")) { + for (const char *s = strtok(buf, ","); s; s = strtok(nullptr, ",")) { if (player->HaveUnitTypeByIdent(s)) { delete[] buf; return true; @@ -206,7 +206,7 @@ bool ButtonCheckUnitsAnd(const CUnit &unit, const ButtonAction &button) CPlayer *player = unit.Player; char *buf = new_strdup(button.AllowStr.c_str()); - for (const char *s = strtok(buf, ","); s; s = strtok(NULL, ",")) { + for (const char *s = strtok(buf, ","); s; s = strtok(nullptr, ",")) { if (!player->HaveUnitTypeByIdent(s)) { delete[] buf; return false; diff --git a/src/ui/contenttype.cpp b/src/ui/contenttype.cpp index 3da104a2b..1baaae228 100644 --- a/src/ui/contenttype.cpp +++ b/src/ui/contenttype.cpp @@ -157,7 +157,7 @@ extern UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e); } char *pos; - if ((pos = strstr(buf, "~|")) != NULL) { + if ((pos = strstr(buf, "~|")) != nullptr) { std::string buf2(buf); label.Draw(this->Pos.x - font.getWidth(buf2.substr(0, pos - buf)), this->Pos.y, buf); } else if (this->Centered) { @@ -202,7 +202,7 @@ extern UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e); } } char *pos; - if ((pos = strstr(buf, "~|")) != NULL) { + if ((pos = strstr(buf, "~|")) != nullptr) { std::string buf2(buf); label.Draw(this->Pos.x - font.getWidth(buf2.substr(0, pos - buf)), this->Pos.y, buf); } else if (this->Centered) { @@ -236,14 +236,14 @@ static const CUnit *GetUnitRef(const CUnit &unit, EnumUnit e) return order.GetWorkerPtr(); } else { - return NULL; + return nullptr; } case UnitRefGoal: return unit.Goal; default: Assert(0); } - return NULL; + return nullptr; } /** @@ -596,7 +596,7 @@ static EnumUnit Str2EnumUnit(lua_State *l, const char *s) if (this->ValueMax == -1) { this->ValueMax = 100; } - if (this->ValueFunc == NULL) { + if (this->ValueFunc == nullptr) { LuaError(l, "didn't set a value function"); } } @@ -654,10 +654,10 @@ static EnumUnit Str2EnumUnit(lua_State *l, const char *s) if (this->Width <= 0) { this->Width = 50; // Default value. } - if (this->Index == -1 && this->ValueFunc == NULL) { + if (this->Index == -1 && this->ValueFunc == nullptr) { LuaError(l, "variable undefined for LifeBar"); } - if (this->colors == NULL || this->values == NULL) { + if (this->colors == nullptr || this->values == nullptr) { this->colors = new unsigned int[4]; this->values = new unsigned int[4]; diff --git a/src/ui/icons.cpp b/src/ui/icons.cpp index 1c96d9945..8067ca96e 100644 --- a/src/ui/icons.cpp +++ b/src/ui/icons.cpp @@ -61,7 +61,7 @@ static IconMap Icons; /// Map of ident to icon. /** ** CIcon constructor */ -CIcon::CIcon(const std::string &ident) : G(NULL), GScale(NULL), Frame(0), Ident(ident) +CIcon::CIcon(const std::string &ident) : G(nullptr), GScale(nullptr), Frame(0), Ident(ident) { this->PaletteSwaps.clear(); } @@ -87,7 +87,7 @@ CIcon::~CIcon() { CIcon *&icon = Icons[ident]; - if (icon == NULL) { + if (icon == nullptr) { icon = new CIcon(ident); } return icon; @@ -367,7 +367,7 @@ bool IconConfig::LoadNoLog() } Icon = CIcon::Get(Name); - return Icon != NULL; + return Icon != nullptr; } /** diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 40cac1853..81572092a 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -150,7 +150,7 @@ static void UiBeginInput() static void UiUnselectAll() { UnSelectAll(); - NetworkSendSelection((CUnit **)NULL, 0); + NetworkSendSelection((CUnit **)nullptr, 0); SelectionChanged(); } @@ -457,7 +457,7 @@ void UiFindIdleWorker() } } - if (unit != NULL) { + if (unit != nullptr) { LastIdleWorker = unit; SelectSingleUnit(*unit); UI.StatusLine.Clear(); @@ -486,11 +486,11 @@ void UiTrackUnit() { //Check if player has selected at least 1 unit if (Selected.empty()) { - UI.SelectedViewport->Unit = NULL; + UI.SelectedViewport->Unit = nullptr; return; } if (UI.SelectedViewport->Unit == Selected[0]) { - UI.SelectedViewport->Unit = NULL; + UI.SelectedViewport->Unit = nullptr; } else { UI.SelectedViewport->Unit = Selected[0]; } diff --git a/src/ui/mainscr.cpp b/src/ui/mainscr.cpp index 944a2d21c..d53b96d3a 100644 --- a/src/ui/mainscr.cpp +++ b/src/ui/mainscr.cpp @@ -1260,7 +1260,7 @@ void CInfoPanel::Draw() } else { switch (Selected.size()) { case 0: { InfoPanel_draw_no_selection(); break; } - case 1: { InfoPanel_draw_single_selection(NULL); break; } + case 1: { InfoPanel_draw_single_selection(nullptr); break; } default: { InfoPanel_draw_multiple_selection(); break; } } } diff --git a/src/ui/mouse.cpp b/src/ui/mouse.cpp index 9fbd9a189..8c0554857 100644 --- a/src/ui/mouse.cpp +++ b/src/ui/mouse.cpp @@ -100,7 +100,7 @@ CUnit *GetUnitUnderCursor() */ void CancelBuildingMode() { - CursorBuilding = NULL; + CursorBuilding = nullptr; UI.StatusLine.Clear(); UI.StatusLine.ClearCosts(); CurrentButtonLevel = 0; @@ -124,7 +124,7 @@ static void DoRightButton_ForForeignUnit(CUnit *dest) { CUnit &unit = *Selected[0]; - if (unit.Player->Index != PlayerNumNeutral || dest == NULL + if (unit.Player->Index != PlayerNumNeutral || dest == nullptr || !(dest->Player == ThisPlayer || dest->IsTeamed(*ThisPlayer))) { return; } @@ -146,7 +146,7 @@ static void DoRightButton_ForForeignUnit(CUnit *dest) static bool DoRightButton_Transporter(CUnit &unit, CUnit *dest, int flush, int &acknowledged) { // Enter transporters ? - if (dest == NULL) { + if (dest == nullptr) { return false; } // dest is the transporter @@ -285,7 +285,7 @@ static bool DoRightButton_Worker(CUnit &unit, CUnit *dest, const Vec2i &pos, int const CUnitType &type = *unit.Type; // Go and repair - if (type.RepairRange && dest != NULL + if (type.RepairRange && dest != nullptr && dest->Type->RepairHP && dest->Variable[HP_INDEX].Value < dest->Variable[HP_INDEX].Max && (dest->Player == unit.Player || unit.IsAllied(*dest))) { @@ -299,7 +299,7 @@ static bool DoRightButton_Worker(CUnit &unit, CUnit *dest, const Vec2i &pos, int } // Harvest if (type.BoolFlag[HARVESTER_INDEX].value) { - if (dest != NULL) { + if (dest != nullptr) { if (DoRightButton_Harvest_Unit(unit, *dest, flush, acknowledged)) { return true; } @@ -310,7 +310,7 @@ static bool DoRightButton_Worker(CUnit &unit, CUnit *dest, const Vec2i &pos, int } } // Follow another unit - if (UnitUnderCursor != NULL && dest != NULL && dest != &unit + if (UnitUnderCursor != nullptr && dest != nullptr && dest != &unit && (dest->Player == unit.Player || unit.IsAllied(*dest) || dest->Player->Index == PlayerNumNeutral)) { dest->Blink = 4; if (!acknowledged) { @@ -378,7 +378,7 @@ static bool DoRightButton_AttackUnit(CUnit &unit, CUnit &dest, const Vec2i &pos, static void DoRightButton_Attack(CUnit &unit, CUnit *dest, const Vec2i &pos, int flush, int &acknowledged) { - if (dest != NULL && unit.CurrentAction() != UnitActionBuilt) { + if (dest != nullptr && unit.CurrentAction() != UnitActionBuilt) { if (DoRightButton_AttackUnit(unit, *dest, pos, flush, acknowledged)) { return; } @@ -479,7 +479,7 @@ static bool DoRightButton_Harvest_Reverse(CUnit &unit, CUnit &dest, int flush, i static bool DoRightButton_NewOrder(CUnit &unit, CUnit *dest, const Vec2i &pos, int flush, int &acknowledged) { // Go and harvest from a unit - if (dest != NULL && dest->Type->GivesResource && dest->Type->BoolFlag[CANHARVEST_INDEX].value + if (dest != nullptr && dest->Type->GivesResource && dest->Type->BoolFlag[CANHARVEST_INDEX].value && (dest->Player == unit.Player || dest->Player->Index == PlayerNumNeutral)) { dest->Blink = 4; if (!acknowledged) { @@ -566,14 +566,14 @@ static void DoRightButton_ForSelectedUnit(CUnit &unit, CUnit *dest, const Vec2i } // FIXME: attack/follow/board ... - if (dest != NULL && (action == MouseActionMove || action == MouseActionSail)) { + if (dest != nullptr && (action == MouseActionMove || action == MouseActionSail)) { if (DoRightButton_Follow(unit, *dest, flush, acknowledged)) { return; } } // Manage harvester from the destination side. - if (dest != NULL && dest->Type->BoolFlag[HARVESTER_INDEX].value) { + if (dest != nullptr && dest->Type->BoolFlag[HARVESTER_INDEX].value) { if (DoRightButton_Harvest_Reverse(unit, *dest, flush, acknowledged)) { return; } @@ -606,10 +606,10 @@ void DoRightButton(const PixelPos &mapPixelPos) const Vec2i pos = Map.MapPixelPosToTilePos(mapPixelPos); CUnit *dest; // unit under the cursor if any. - if (UnitUnderCursor != NULL && !UnitUnderCursor->Type->BoolFlag[DECORATION_INDEX].value) { + if (UnitUnderCursor != nullptr && !UnitUnderCursor->Type->BoolFlag[DECORATION_INDEX].value) { dest = UnitUnderCursor; } else { - dest = NULL; + dest = nullptr; } // Unit selected isn't owned by the player. @@ -620,7 +620,7 @@ void DoRightButton(const PixelPos &mapPixelPos) return; } - if (dest != NULL && dest->Type->CanTransport()) { + if (dest != nullptr && dest->Type->CanTransport()) { for (size_t i = 0; i != Selected.size(); ++i) { if (CanTransport(*dest, *Selected[i])) { // We are clicking on a transporter. We have to: @@ -639,7 +639,7 @@ void DoRightButton(const PixelPos &mapPixelPos) int acknowledged = 0; // to play sound auto sz = Selected.size(); - if (dest == NULL && sz < 12 && Preference.FormationMovement) { + if (dest == nullptr && sz < 12 && Preference.FormationMovement) { const short magicBoxSize = 7 << Map.Tileset->getLogicalToGraphicalTileSizeShift(); std::vector targetPositions(sz); Vec2i max, min, center; @@ -1004,7 +1004,7 @@ void UIHandleMouseMove(const PixelPos &cursorPos) return; } - UnitUnderCursor = NULL; + UnitUnderCursor = nullptr; GameCursor = UI.Point.Cursor; // Reset HandleMouseOn(cursorPos); @@ -1111,9 +1111,9 @@ void UIHandleMouseMove(const PixelPos &cursorPos) } // NOTE: If unit is not selectable as a goal, you can't get a cursor hint - if (UnitUnderCursor != NULL && !UnitUnderCursor->IsVisibleAsGoal(*ThisPlayer) && + if (UnitUnderCursor != nullptr && !UnitUnderCursor->IsVisibleAsGoal(*ThisPlayer) && !ReplayRevealMap) { - UnitUnderCursor = NULL; + UnitUnderCursor = nullptr; } // Selecting target. @@ -1124,7 +1124,7 @@ void UIHandleMouseMove(const PixelPos &cursorPos) } else { GameCursor = UI.YellowHair.Cursor; } - if (UnitUnderCursor != NULL && !UnitUnderCursor->Type->BoolFlag[DECORATION_INDEX].value) { + if (UnitUnderCursor != nullptr && !UnitUnderCursor->Type->BoolFlag[DECORATION_INDEX].value) { if (UnitUnderCursor->Player == ThisPlayer || ThisPlayer->IsAllied(*UnitUnderCursor)) { if (CustomCursor.length() && CursorByIdent(CustomCursor)) { @@ -1153,7 +1153,7 @@ void UIHandleMouseMove(const PixelPos &cursorPos) // Cursor pointing. if (CursorOn == CursorOnMap) { // Map - if (UnitUnderCursor != NULL && !UnitUnderCursor->Type->BoolFlag[DECORATION_INDEX].value + if (UnitUnderCursor != nullptr && !UnitUnderCursor->Type->BoolFlag[DECORATION_INDEX].value && (UnitUnderCursor->IsVisible(*ThisPlayer) || ReplayRevealMap)) { GameCursor = UI.Glass.Cursor; } @@ -1237,10 +1237,10 @@ static int SendMove(const Vec2i &tilePos) } } if (i == Selected.size()) { - goal = NULL; + goal = nullptr; } } else { - goal = NULL; + goal = nullptr; } for (size_t i = 0; i != Selected.size(); ++i) { @@ -1282,7 +1282,7 @@ static int SendAttack(const Vec2i &tilePos) int ret = 0; if (dest && dest->Type->BoolFlag[DECORATION_INDEX].value) { - dest = NULL; + dest = nullptr; } for (size_t i = 0; i != Selected.size(); ++i) { CUnit &unit = *Selected[i]; @@ -1468,7 +1468,7 @@ static int SendSpellCast(const Vec2i &tilePos) // Only spells with explicit 'self: true' allows self targetting continue; } - SendCommandSpellCast(unit, tilePos, spell->Target == TargetPosition ? NULL : dest , CursorValue, flush); + SendCommandSpellCast(unit, tilePos, spell->Target == TargetPosition ? nullptr : dest , CursorValue, flush); ret = 1; } return ret; @@ -1668,7 +1668,7 @@ static void UISelectStateButtonDown(unsigned) const Vec2i tilePos = unit.tilePos; UnitUnderCursor = &unit; SendSpellCast(tilePos); - UnitUnderCursor = NULL; + UnitUnderCursor = nullptr; } if (ButtonAreaUnderCursor == ButtonAreaButton) { OldButtonUnderCursor = ButtonUnderCursor; @@ -1728,7 +1728,7 @@ static void UIHandleButtonDown_OnMap(unsigned button) } if (MouseButtons & UI.PieMenu.MouseButton) { // enter pie menu - UnitUnderCursor = NULL; + UnitUnderCursor = nullptr; GameCursor = UI.Point.Cursor; // Reset CursorStartScreenPos = CursorScreenPos; if (!Selected.empty() && Selected[0]->Player == ThisPlayer && CursorState == CursorStatePoint) { @@ -1741,7 +1741,7 @@ static void UIHandleButtonDown_OnMap(unsigned button) // FIXME: Johns: Perhaps we should use a pixel map coordinates const Vec2i tilePos = UI.MouseViewport->ScreenToTilePos(CursorScreenPos); - if (UnitUnderCursor != NULL && (unit = UnitOnMapTile(tilePos, -1)) + if (UnitUnderCursor != nullptr && (unit = UnitOnMapTile(tilePos, -1)) && !UnitUnderCursor->Type->BoolFlag[DECORATION_INDEX].value) { unit->Blink = 4; // if right click on building -- blink } else { // if not not click on building -- green cross @@ -1888,7 +1888,7 @@ static void UIHandleButtonDown_OnButton(unsigned button) if (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0 && Selected.size() == 1) { PlayGameSound(GameSounds.Click.Sound, MaxSampleVolume); if (UI.SelectedViewport->Unit == Selected[0]) { - UI.SelectedViewport->Unit = NULL; + UI.SelectedViewport->Unit = nullptr; } else { UI.SelectedViewport->Unit = Selected[0]; } @@ -2123,7 +2123,7 @@ void UIHandleButtonUp(unsigned button) // cade: cannot select unit on invisible space // FIXME: johns: only complete invisibile units const Vec2i cursorTilePos = UI.MouseViewport->ScreenToTilePos(CursorScreenPos); - CUnit *unit = NULL; + CUnit *unit = nullptr; if (ReplayRevealMap || Map.Field(cursorTilePos)->playerInfo.IsTeamVisible(*ThisPlayer)) { const PixelPos cursorMapPos = UI.MouseViewport->ScreenToMapPixelPos(CursorScreenPos); diff --git a/src/ui/popup.cpp b/src/ui/popup.cpp index d7924e546..441630f61 100644 --- a/src/ui/popup.cpp +++ b/src/ui/popup.cpp @@ -376,7 +376,7 @@ CPopupContentTypeLine::CPopupContentTypeLine() : Color(ColorWhite), Width(0), He CFont &font = this->Font ? *this->Font : GetSmallFont(); TriggerData.Type = UnitTypes[button.Value]; std::string text = EvalString(this->Text); - TriggerData.Type = NULL; + TriggerData.Type = nullptr; return font.getWidth(text); } @@ -398,7 +398,7 @@ CPopupContentTypeLine::CPopupContentTypeLine() : Color(ColorWhite), Width(0), He if (this->Text) { TriggerData.Type = UnitTypes[button.Value]; text = EvalString(this->Text); - TriggerData.Type = NULL; + TriggerData.Type = nullptr; if (this->Centered) { x += (label.DrawCentered(x, y, text) * 2); } else { @@ -557,8 +557,8 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l) int minHeight = 0; std::string textColor("white"); std::string highColor("red"); - CPopupContentType *content = NULL; - PopupConditionPanel *condition = NULL; + CPopupContentType *content = nullptr; + PopupConditionPanel *condition = nullptr; for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { const char *key = LuaToString(l, -2); @@ -613,7 +613,7 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l) CPopup::CPopup() : Contents(), MarginX(MARGIN_X), MarginY(MARGIN_Y), MinWidth(0), MinHeight(0), - DefaultFont(NULL), BackgroundColor(ColorBlue), BorderColor(ColorWhite) + DefaultFont(nullptr), BackgroundColor(ColorBlue), BorderColor(ColorWhite) {} CPopup::~CPopup() diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp index 1987af27a..c37f838ac 100644 --- a/src/ui/script_ui.cpp +++ b/src/ui/script_ui.cpp @@ -367,7 +367,7 @@ static int CclSetTitleScreens(lua_State *l) delete TitleScreens[i]; } delete[] TitleScreens; - TitleScreens = NULL; + TitleScreens = nullptr; } const int args = lua_gettop(l); @@ -529,8 +529,8 @@ static CContentType *CclParseContent(lua_State *l) { Assert(lua_istable(l, -1)); - CContentType *content = NULL; - ConditionPanel *condition = NULL; + CContentType *content = nullptr; + ConditionPanel *condition = nullptr; PixelPos pos(0, 0); for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { @@ -766,7 +766,7 @@ static int CclSetFancyBuildings(lua_State *l) ** ** @param style Name of the style to find. ** -** @return Button style, NULL if not found. +** @return Button style, nullptr if not found. */ ButtonStyle *FindButtonStyle(const std::string &style) { @@ -1195,11 +1195,11 @@ void SelectionChanged() UI.StatusLine.Clear(); UI.StatusLine.ClearCosts(); CurrentButtonLevel = 0; - LastDrawnButtonPopup = NULL; + LastDrawnButtonPopup = nullptr; UI.ButtonPanel.Update(); GameCursor = UI.Point.Cursor; - CursorBuilding = NULL; + CursorBuilding = nullptr; CursorState = CursorStatePoint; UI.ButtonPanel.Update(); } diff --git a/src/ui/statusline.cpp b/src/ui/statusline.cpp index 7182451b8..c9c753b56 100644 --- a/src/ui/statusline.cpp +++ b/src/ui/statusline.cpp @@ -73,7 +73,7 @@ void CStatusLine::Set(const std::string &status) ** ** @param mana Mana costs. ** @param food Food costs. -** @param costs Resource costs, NULL pointer if all are zero. +** @param costs Resource costs, nullptr pointer if all are zero. */ void CStatusLine::SetCosts(int mana, int food, const int *costs) { @@ -91,7 +91,7 @@ void CStatusLine::SetCosts(int mana, int food, const int *costs) */ void CStatusLine::ClearCosts() { - SetCosts(0, 0, NULL); + SetCosts(0, 0, nullptr); } /** diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index eb3639960..09207ddc2 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -131,17 +131,17 @@ CUserInterface::CUserInterface() : MouseScroll(false), KeyScroll(false), KeyScrollSpeed(1), MouseScrollSpeed(1), MouseScrollSpeedDefault(0), MouseScrollSpeedControl(0), NormalFontColor("yellow"), ReverseFontColor("white"), - SingleSelectedButton(NULL), - MaxSelectedFont(NULL), MaxSelectedTextX(0), MaxSelectedTextY(0), - SingleTrainingButton(NULL), - SingleTrainingFont(NULL), SingleTrainingTextX(0), SingleTrainingTextY(0), - TrainingFont(NULL), TrainingTextX(0), TrainingTextY(0), + SingleSelectedButton(nullptr), + MaxSelectedFont(nullptr), MaxSelectedTextX(0), MaxSelectedTextY(0), + SingleTrainingButton(nullptr), + SingleTrainingFont(nullptr), SingleTrainingTextX(0), SingleTrainingTextY(0), + TrainingFont(nullptr), TrainingTextX(0), TrainingTextY(0), CompletedBarColor(0), CompletedBarShadow(0), - ViewportMode(VIEWPORT_SINGLE), MouseViewport(NULL), - SelectedViewport(NULL), NumViewports(0), - MessageFont(NULL), MessageScrollSpeed(5), + ViewportMode(VIEWPORT_SINGLE), MouseViewport(nullptr), + SelectedViewport(nullptr), NumViewports(0), + MessageFont(nullptr), MessageScrollSpeed(5), ViewportCursorColor(0), Offset640X(0), Offset480Y(0), - VictoryBackgroundG(NULL), DefeatBackgroundG(NULL) + VictoryBackgroundG(nullptr), DefeatBackgroundG(nullptr) { MouseWarpPos.x = MouseWarpPos.y = -1; @@ -194,7 +194,7 @@ CPopup *PopupByIdent(const std::string &ident) return *i; } } - return NULL; + return nullptr; } /** @@ -250,7 +250,7 @@ void CursorConfig::Load() { Assert(!Name.empty()); Cursor = CursorByIdent(Name); - if (Cursor == NULL) { + if (Cursor == nullptr) { return ; } Assert(Name == Cursor->Ident); @@ -418,7 +418,7 @@ void CleanUserInterface() delete TitleScreens[i]; } delete[] TitleScreens; - TitleScreens = NULL; + TitleScreens = nullptr; } } @@ -437,7 +437,7 @@ void FreeButtonStyles() ** ** @param screenPos pixel coordinate with origin at UL corner of screen ** -** @return viewport pointer or NULL if this pixel is not inside +** @return viewport pointer or nullptr if this pixel is not inside ** any of the viewports. ** ** @note This functions only works with rectangular viewports, when @@ -450,7 +450,7 @@ CViewport *GetViewport(const PixelPos &screenPos) return vp; } } - return NULL; + return nullptr; } /** diff --git a/src/ui/widgets.cpp b/src/ui/widgets.cpp index 51c9121a5..843fd7029 100644 --- a/src/ui/widgets.cpp +++ b/src/ui/widgets.cpp @@ -106,7 +106,7 @@ void initGuichan() Gui = new gcn::Gui(); Gui->setGraphics(graphics); Gui->setInput(Input); - Gui->setTop(NULL); + Gui->setTop(nullptr); Gui->setUseDirtyDrawing(1); @@ -128,11 +128,11 @@ void freeGuichan() if (Gui) { delete Gui->getGraphics(); delete Gui; - Gui = NULL; + Gui = nullptr; } delete Input; - Input = NULL; + Input = nullptr; } /** @@ -291,8 +291,8 @@ LuaActionListener::~LuaActionListener() ** ImageButton constructor */ ImageButton::ImageButton() : - Button(), normalImage(NULL), pressedImage(NULL), - disabledImage(NULL) + Button(), normalImage(nullptr), pressedImage(nullptr), + disabledImage(nullptr) { setForegroundColor(0xffffff); } @@ -303,8 +303,8 @@ ImageButton::ImageButton() : ** @param caption Caption text */ ImageButton::ImageButton(const std::string &caption) : - Button(caption), normalImage(NULL), pressedImage(NULL), - disabledImage(NULL) + Button(caption), normalImage(nullptr), pressedImage(nullptr), + disabledImage(nullptr) { setForegroundColor(0xffffff); } @@ -329,7 +329,7 @@ void ImageButton::draw(gcn::Graphics *graphics) img = pressedImage ? pressedImage : normalImage; } else if (0 && hasMouse()) { // FIXME: add mouse-over image - img = NULL; + img = nullptr; } else { img = normalImage; } @@ -398,8 +398,8 @@ void ImageButton::adjustSize() ** ImageRadioButton constructor */ ImageRadioButton::ImageRadioButton() : gcn::RadioButton(), - uncheckedNormalImage(NULL), uncheckedPressedImage(NULL), uncheckedDisabledImage(NULL), - checkedNormalImage(NULL), checkedPressedImage(NULL), checkedDisabledImage(NULL), + uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), + checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), mMouseDown(false) { } @@ -410,8 +410,8 @@ ImageRadioButton::ImageRadioButton() : gcn::RadioButton(), ImageRadioButton::ImageRadioButton(const std::string &caption, const std::string &group, bool marked) : gcn::RadioButton(caption, group, marked), - uncheckedNormalImage(NULL), uncheckedPressedImage(NULL), uncheckedDisabledImage(NULL), - checkedNormalImage(NULL), checkedPressedImage(NULL), checkedDisabledImage(NULL), + uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), + checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), mMouseDown(false) { } @@ -421,7 +421,7 @@ ImageRadioButton::ImageRadioButton(const std::string &caption, */ void ImageRadioButton::drawBox(gcn::Graphics *graphics) { - gcn::Image *img = NULL; + gcn::Image *img = nullptr; if (isMarked()) { if (isEnabled() == false) { @@ -537,8 +537,8 @@ void ImageRadioButton::adjustSize() ** Image checkbox constructor */ ImageCheckBox::ImageCheckBox() : gcn::CheckBox(), - uncheckedNormalImage(NULL), uncheckedPressedImage(NULL), uncheckedDisabledImage(NULL), - checkedNormalImage(NULL), checkedPressedImage(NULL), checkedDisabledImage(NULL), + uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), + checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), mMouseDown(false) { } @@ -548,8 +548,8 @@ ImageCheckBox::ImageCheckBox() : gcn::CheckBox(), */ ImageCheckBox::ImageCheckBox(const std::string &caption, bool marked) : gcn::CheckBox(caption, marked), - uncheckedNormalImage(NULL), uncheckedPressedImage(NULL), uncheckedDisabledImage(NULL), - checkedNormalImage(NULL), checkedPressedImage(NULL), checkedDisabledImage(NULL), + uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), + checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), mMouseDown(false) { } @@ -585,7 +585,7 @@ void ImageCheckBox::draw(gcn::Graphics *graphics) */ void ImageCheckBox::drawBox(gcn::Graphics *graphics) { - gcn::Image *img = NULL; + gcn::Image *img = nullptr; if (mMarked) { if (isEnabled() == false) { @@ -674,7 +674,7 @@ void ImageCheckBox::adjustSize() ** Image slider constructor */ ImageSlider::ImageSlider(double scaleEnd) : - Slider(scaleEnd), markerImage(NULL), backgroundImage(NULL), disabledBackgroundImage(NULL) + Slider(scaleEnd), markerImage(nullptr), backgroundImage(nullptr), disabledBackgroundImage(nullptr) { } @@ -682,7 +682,7 @@ ImageSlider::ImageSlider(double scaleEnd) : ** Image slider constructor */ ImageSlider::ImageSlider(double scaleStart, double scaleEnd) : - Slider(scaleStart, scaleEnd), markerImage(NULL), backgroundImage(NULL), disabledBackgroundImage(NULL) + Slider(scaleStart, scaleEnd), markerImage(nullptr), backgroundImage(nullptr), disabledBackgroundImage(nullptr) { } @@ -715,7 +715,7 @@ void ImageSlider::drawMarker(gcn::Graphics *graphics) */ void ImageSlider::draw(gcn::Graphics *graphics) { - gcn::Image *img = NULL; + gcn::Image *img = nullptr; if (isEnabled()) { img = backgroundImage; @@ -1040,7 +1040,7 @@ void MultiLineLabel::wordWrap() ** @param height Height of the widget. */ ScrollingWidget::ScrollingWidget(int width, int height) : - gcn::ScrollArea(NULL, gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER), + gcn::ScrollArea(nullptr, gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER), speedY(1.f), containerY(0.f), finished(false) { container.setDimension(gcn::Rectangle(0, 0, width, height)); @@ -1330,17 +1330,17 @@ void LuaListModel::setList(lua_State *lua, lua_Object *lo) -- ImageListBox ----------------------------------------------------------------------------*/ -ImageListBox::ImageListBox() : gcn::ListBox(), itemImage(NULL) +ImageListBox::ImageListBox() : gcn::ListBox(), itemImage(nullptr) { } -ImageListBox::ImageListBox(gcn::ListModel *listModel) : gcn::ListBox(listModel), itemImage(NULL) +ImageListBox::ImageListBox(gcn::ListModel *listModel) : gcn::ListBox(listModel), itemImage(nullptr) { } void ImageListBox::draw(gcn::Graphics *graphics) { - if (mListModel == NULL) { + if (mListModel == nullptr) { return; } @@ -1396,7 +1396,7 @@ void ImageListBox::drawBorder(gcn::Graphics *graphics) void ImageListBox::adjustSize() { - if (mListModel != NULL) + if (mListModel != nullptr) { setHeight((itemImage ? std::max(getFont()->getHeight(), itemImage->getHeight()) : getFont()->getHeight()) * mListModel->getNumberOfElements()); } @@ -1418,7 +1418,7 @@ void ImageListBox::mousePress(int, int y, int button) void ImageListBox::setSelected(int selected) { - if (mListModel == NULL) + if (mListModel == nullptr) { mSelected = -1; } @@ -1438,13 +1438,13 @@ void ImageListBox::setSelected(int selected) } Widget *par = this; - while (par != NULL) { + while (par != nullptr) { par->setDirty(true); par = par->getParent(); } gcn::ScrollArea* scrollArea = dynamic_cast(getParent()); - if (scrollArea != NULL) + if (scrollArea != nullptr) { gcn::Rectangle scroll; scroll.y = (itemImage ? std::max(getFont()->getHeight(), itemImage->getHeight()) : getFont()->getHeight()) * mSelected; @@ -1485,8 +1485,8 @@ ListBoxWidget::ListBoxWidget(unsigned int width, unsigned int height) ** @todo Size should be parametrable, maybe remove default constructor? */ ImageListBoxWidget::ImageListBoxWidget(unsigned int width, unsigned int height) : ListBoxWidget(width, height), - upButtonImage(NULL), downButtonImage(NULL), leftButtonImage(NULL), rightButtonImage(NULL), hBarButtonImage(NULL), - vBarButtonImage(NULL), markerImage(NULL) + upButtonImage(nullptr), downButtonImage(nullptr), leftButtonImage(nullptr), rightButtonImage(nullptr), hBarButtonImage(nullptr), + vBarButtonImage(nullptr), markerImage(nullptr) { setDimension(gcn::Rectangle(0, 0, width, height)); setContent(&listbox); @@ -1682,7 +1682,7 @@ void ImageListBoxWidget::addActionListener(gcn::ActionListener *actionListener) */ void ImageListBoxWidget::draw(gcn::Graphics *graphics) { - CGraphic *img = NULL; + CGraphic *img = nullptr; // Check if we have all required graphics if (!this->upButtonImage || !this->downButtonImage || !this->leftButtonImage || !this->rightButtonImage @@ -1790,7 +1790,7 @@ void ImageListBoxWidget::drawUpButton(gcn::Graphics* graphics) gcn::Rectangle dim = getUpButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = upButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1802,7 +1802,7 @@ void ImageListBoxWidget::drawDownButton(gcn::Graphics* graphics) gcn::Rectangle dim = getDownButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = downButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1814,7 +1814,7 @@ void ImageListBoxWidget::drawLeftButton(gcn::Graphics* graphics) gcn::Rectangle dim = getLeftButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = leftButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1826,7 +1826,7 @@ void ImageListBoxWidget::drawRightButton(gcn::Graphics* graphics) gcn::Rectangle dim = getRightButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = rightButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1838,7 +1838,7 @@ void ImageListBoxWidget::drawUpPressedButton(gcn::Graphics* graphics) gcn::Rectangle dim = getUpButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = upPressedButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1850,7 +1850,7 @@ void ImageListBoxWidget::drawDownPressedButton(gcn::Graphics* graphics) gcn::Rectangle dim = getDownButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = downPressedButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1862,7 +1862,7 @@ void ImageListBoxWidget::drawLeftPressedButton(gcn::Graphics* graphics) gcn::Rectangle dim = getLeftButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = leftPressedButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1874,7 +1874,7 @@ void ImageListBoxWidget::drawRightPressedButton(gcn::Graphics* graphics) gcn::Rectangle dim = getRightButtonDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = rightPressedButtonImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1886,7 +1886,7 @@ void ImageListBoxWidget::drawHBar(gcn::Graphics *graphics) gcn::Rectangle dim = getHorizontalBarDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = hBarButtonImage; img->Resize(dim.width, dim.height); @@ -1901,7 +1901,7 @@ void ImageListBoxWidget::drawVBar(gcn::Graphics *graphics) gcn::Rectangle dim = getVerticalBarDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = vBarButtonImage; img->Resize(dim.width, dim.height); @@ -1916,7 +1916,7 @@ void ImageListBoxWidget::drawHMarker(gcn::Graphics *graphics) gcn::Rectangle dim = getHorizontalMarkerDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = markerImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -1929,7 +1929,7 @@ void ImageListBoxWidget::drawVMarker(gcn::Graphics *graphics) gcn::Rectangle dim = getVerticalMarkerDimension(); graphics->pushClipArea(dim); - CGraphic *img = NULL; + CGraphic *img = nullptr; img = markerImage; graphics->drawImage(img, 0, 0, 0, 0, img->getWidth(), img->getHeight()); @@ -2055,7 +2055,7 @@ void DropDownWidget::setSize(int width, int height) void ImageDropDownWidget::setListModel(LuaListModel *listModel) { - Assert(mScrollArea && mScrollArea->getContent() != NULL); + Assert(mScrollArea && mScrollArea->getContent() != nullptr); mListBox.setListModel(listModel); @@ -2084,7 +2084,7 @@ void ImageDropDownWidget::setSize(int width, int height) void ImageDropDownWidget::draw(gcn::Graphics *graphics) { - Assert(mScrollArea && mScrollArea->getContent() != NULL); + Assert(mScrollArea && mScrollArea->getContent() != nullptr); int h; if (mDroppedDown) @@ -2183,7 +2183,7 @@ void ImageDropDownWidget::drawButton(gcn::Graphics *graphics) int x = getWidth() - h; int y = 0; - CGraphic *img = NULL; + CGraphic *img = nullptr; if (mDroppedDown) { img = this->DownPressedImage; } else { @@ -2196,14 +2196,14 @@ void ImageDropDownWidget::drawButton(gcn::Graphics *graphics) int ImageDropDownWidget::getSelected() { - Assert(mScrollArea && mScrollArea->getContent() != NULL); + Assert(mScrollArea && mScrollArea->getContent() != nullptr); return mListBox.getSelected(); } void ImageDropDownWidget::setSelected(int selected) { - Assert(mScrollArea && mScrollArea->getContent() != NULL); + Assert(mScrollArea && mScrollArea->getContent() != nullptr); if (selected >= 0) { @@ -2213,7 +2213,7 @@ void ImageDropDownWidget::setSelected(int selected) void ImageDropDownWidget::adjustHeight() { - Assert(mScrollArea && mScrollArea->getContent() != NULL); + Assert(mScrollArea && mScrollArea->getContent() != nullptr); int listBoxHeight = mListBox.getHeight(); int h2 = mOldH ? mOldH : getFont()->getHeight(); @@ -2249,7 +2249,7 @@ void ImageDropDownWidget::setListBox(ImageListBox *listBox) listBox->setListModel(mListBox.getListModel()); listBox->addActionListener(this); - if (mScrollArea->getContent() != NULL) + if (mScrollArea->getContent() != nullptr) { mListBox.removeActionListener(this); } @@ -2276,7 +2276,7 @@ void ImageDropDownWidget::_mouseInputMessage(const gcn::MouseInput &mouseInput) if (mDroppedDown) { - Assert(mScrollArea && mScrollArea->getContent() != NULL); + Assert(mScrollArea && mScrollArea->getContent() != nullptr); if (mouseInput.y >= mOldH) { diff --git a/src/unit/build.cpp b/src/unit/build.cpp index db85e8daa..de844b1c6 100644 --- a/src/unit/build.cpp +++ b/src/unit/build.cpp @@ -93,7 +93,7 @@ CBuildRestrictionOnTop *OnTopDetails(const CUnit &unit, const CUnitType *parent) } } } - return NULL; + return nullptr; } /** @@ -117,7 +117,7 @@ bool CBuildRestrictionDistance::Check(const CUnit *builder, const CUnitType &typ Vec2i pos1(0, 0); Vec2i pos2(0, 0); int distance = 0; - CPlayer* player = builder != NULL ? builder->Player : ThisPlayer; + CPlayer* player = builder != nullptr ? builder->Player : ThisPlayer; if (this->DistanceType == LessThanEqual || this->DistanceType == GreaterThan @@ -194,7 +194,7 @@ bool CBuildRestrictionHasUnit::Check(const CUnit *builder, const CUnitType &type { Vec2i pos1(0, 0); Vec2i pos2(0, 0); - CPlayer* player = builder != NULL ? builder->Player : ThisPlayer; + CPlayer* player = builder != nullptr ? builder->Player : ThisPlayer; int count = 0; if (this->RestrictTypeOwner.size() == 0 || !this->RestrictTypeOwner.compare("self")) { count = player->GetUnitTotalCount(*this->RestrictType); @@ -320,7 +320,7 @@ bool CBuildRestrictionAddOn::Check(const CUnit *, const CUnitType &, const Vec2i return false; } functor f(Parent, pos1); - return (Map.Field(pos1)->UnitCache.find(f) != NULL); + return (Map.Field(pos1)->UnitCache.find(f) != nullptr); } /** @@ -335,7 +335,7 @@ inline bool CBuildRestrictionOnTop::functor::operator()(CUnit *const unit) ontop = unit; } else { // Something else is built on this already - ontop = NULL; + ontop = nullptr; return false; } } @@ -380,7 +380,7 @@ bool CBuildRestrictionOnTop::Check(const CUnit *builder, const CUnitType &, cons { Assert(Map.Info.IsPointOnMap(pos)); - ontoptarget = NULL; + ontoptarget = nullptr; CUnitCache &cache = Map.Field(pos)->UnitCache; CUnitCache::iterator it = std::find_if(cache.begin(), cache.end(), AliveConstructedAndSameTypeAs(*this->Parent)); @@ -417,16 +417,16 @@ bool CBuildRestrictionOnTop::Check(const CUnit *builder, const CUnitType &, cons ** @param type unit-type to be checked. ** @param pos Map position. ** -** @return OnTop, parent unit, builder on true or 1 if unit==NULL, NULL false. +** @return OnTop, parent unit, builder on true or 1 if unit==nullptr, nullptr false. */ CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos) { // Can't build outside the map if (pos.x + type.TileWidth > Map.Info.MapWidth) { - return NULL; + return nullptr; } if (pos.y + type.TileHeight > Map.Info.MapHeight) { - return NULL; + return nullptr; } // Must be checked before oil! @@ -449,7 +449,7 @@ CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos) index += Map.Info.MapWidth; } while (!success && --h); if (!success) { - return NULL; + return nullptr; } } @@ -458,7 +458,7 @@ CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos) bool aiChecked = true; size_t count = type.AiBuildingRules.size(); if (count > 0) { - CUnit *ontoptarget = NULL; + CUnit *ontoptarget = nullptr; for (unsigned int i = 0; i < count; ++i) { CBuildRestriction *rule = type.AiBuildingRules[i]; // All checks processed, did we really have success @@ -472,7 +472,7 @@ CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos) } } if (aiChecked == false) { - return NULL; + return nullptr; } } @@ -481,22 +481,22 @@ CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos) if (count > 0) { for (unsigned int i = 0; i < count; ++i) { CBuildRestriction *rule = type.BuildingRules[i]; - CUnit *ontoptarget = NULL; + CUnit *ontoptarget = nullptr; // All checks processed, did we really have success if (rule->Check(unit, type, pos, ontoptarget)) { // We passed a full ruleset return - if (unit == NULL) { + if (unit == nullptr) { return ontoptarget ? ontoptarget : (CUnit *)1; } else { return ontoptarget ? ontoptarget : const_cast(unit); } } } - return NULL; + return nullptr; } } - return (unit == NULL) ? (CUnit *)1 : const_cast(unit); + return (unit == nullptr) ? (CUnit *)1 : const_cast(unit); } /** @@ -515,20 +515,20 @@ bool CanBuildOn(const Vec2i &pos, int mask) /** ** Can build unit-type at this point. ** -** @param unit Worker that want to build the building or NULL. +** @param unit Worker that want to build the building or nullptr. ** @param type Building unit-type. ** @param pos tile map position. ** @param real Really build, or just placement ** -** @return OnTop, parent unit, builder on true, NULL false. +** @return OnTop, parent unit, builder on true, nullptr false. ** */ CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &pos, int real) { // Terrain Flags don't matter if building on top of a unit. CUnit *ontop = CanBuildHere(unit, type, pos); - if (ontop == NULL) { - return NULL; + if (ontop == nullptr) { + return nullptr; } if (ontop != (CUnit *)1 && ontop != unit) { return ontop; @@ -539,7 +539,7 @@ CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &p UnmarkUnitFieldFlags(*unit); } - CPlayer *player = NULL; + CPlayer *player = nullptr; if (unit && unit->Player->Type == PlayerTypes::PlayerPerson) { player = unit->Player; @@ -551,7 +551,7 @@ CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &p /* first part of if (!CanBuildOn(x + w, y + h, testmask)) */ if (!Map.Info.IsPointOnMap(pos.x + w, pos.y + h)) { h = type.TileHeight; - ontop = NULL; + ontop = nullptr; break; } if (player && !real) { @@ -565,12 +565,12 @@ CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &p const CMapField &mf = *Map.Field(index + pos.x + w); if (mf.CheckMask(testmask)) { h = type.TileHeight; - ontop = NULL; + ontop = nullptr; break; } if (player && !mf.playerInfo.IsExplored(*player)) { h = type.TileHeight; - ontop = NULL; + ontop = nullptr; break; } } diff --git a/src/unit/depend.cpp b/src/unit/depend.cpp index 9f882cc50..946f7d033 100644 --- a/src/unit/depend.cpp +++ b/src/unit/depend.cpp @@ -94,8 +94,8 @@ static void AddDependency(const std::string &target, const std::string &required while (node->Type != rule.Type || node->Kind.Upgrade != rule.Kind.Upgrade) { if (!node->Next) { // end of list DependRule *temp = new DependRule; - temp->Next = NULL; - temp->Rule = NULL; + temp->Next = nullptr; + temp->Rule = nullptr; temp->Type = rule.Type; temp->Kind = rule.Kind; node->Next = temp; @@ -106,8 +106,8 @@ static void AddDependency(const std::string &target, const std::string &required } } else { // create new slow node = new DependRule; - node->Next = NULL; - node->Rule = NULL; + node->Next = nullptr; + node->Rule = nullptr; node->Type = rule.Type; node->Kind = rule.Kind; DependHash[hash] = node; @@ -120,8 +120,8 @@ static void AddDependency(const std::string &target, const std::string &required } DependRule *temp = new DependRule; - temp->Rule = NULL; - temp->Next = NULL; + temp->Rule = nullptr; + temp->Next = nullptr; temp->Count = count; // Setup structure. @@ -408,7 +408,7 @@ void CleanDependencies() node = node->Next; delete temp; } - DependHash[u] = NULL; + DependHash[u] = nullptr; } } diff --git a/src/unit/script_unit.cpp b/src/unit/script_unit.cpp index cc18b2f5a..86d8851dd 100644 --- a/src/unit/script_unit.cpp +++ b/src/unit/script_unit.cpp @@ -163,7 +163,7 @@ static CUnit *CclGetUnit(lua_State *l) } else if (UnitUnderCursor) { return UnitUnderCursor; } - return NULL; + return nullptr; } return &UnitManager->GetSlotUnit(num); } @@ -178,7 +178,7 @@ static CUnit *CclGetUnit(lua_State *l) CUnit *CclGetUnitFromRef(lua_State *l) { const char *const value = LuaToString(l, -1); - unsigned int slot = strtol(value + 1, NULL, 16); + unsigned int slot = strtol(value + 1, nullptr, 16); Assert(slot < UnitManager->GetUsedSlotCount()); return &UnitManager->GetSlotUnit(slot); } @@ -287,7 +287,7 @@ static void CclParseOrders(lua_State *l, CUnit &unit) for (int j = 0; j < n; ++j) { lua_rawgeti(l, -1, j + 1); - unit.Orders.push_back(NULL); + unit.Orders.push_back(nullptr); COrderPtr *order = &unit.Orders.back(); CclParseOrder(l, unit, order); @@ -332,10 +332,10 @@ static int CclUnit(lua_State *l) } CUnit *unit = &UnitManager->GetSlotUnit(slot); - bool hadType = unit->Type != NULL; - CUnitType *type = NULL; - CUnitType *seentype = NULL; - CPlayer *player = NULL; + bool hadType = unit->Type != nullptr; + CUnitType *type = nullptr; + CUnitType *seentype = nullptr; + CPlayer *player = nullptr; // Parse the list: const int args = lua_rawlen(l, 2); @@ -577,7 +577,7 @@ static int CclUnit(lua_State *l) CclParseOrders(l, *unit); lua_pop(l, 1); // now we know unit's action so we can assign it to a player - Assert(player != NULL); + Assert(player != nullptr); unit->AssignToPlayer(*player); if (unit->CurrentAction() == UnitActionBuilt) { DebugPrint("HACK: the building is not ready yet\n"); @@ -658,7 +658,7 @@ static int CclUnit(lua_State *l) // need to actually add it now, since only with a type do we know the // BoardSize it takes up in the container CUnit *host = unit->Container; - unit->Container = NULL; + unit->Container = nullptr; unit->AddInContainer(*host); } @@ -706,7 +706,7 @@ static int CclMoveUnit(lua_State *l) const int heading = SyncRand() % 256; unit->tilePos = ipos; - DropOutOnSide(*unit, heading, NULL); + DropOutOnSide(*unit, heading, nullptr); } if (nargs == 3) { @@ -746,7 +746,7 @@ static int CclRemoveUnit(lua_State *l) CUnit *unit = CclGetUnit(l); lua_pop(l, 1); if (unit) { - unit->Remove(NULL); + unit->Remove(nullptr); LetUnitDie(*unit); } lua_pushvalue(l, 1); @@ -772,7 +772,7 @@ static int CclCreateUnit(lua_State *l) lua_pushvalue(l, 1); CUnitType *unittype = CclGetUnitType(l); - if (unittype == NULL) { + if (unittype == nullptr) { LuaError(l, "Bad unittype"); } lua_pop(l, 1); @@ -793,18 +793,18 @@ static int CclCreateUnit(lua_State *l) return 0; } CUnit *unit = MakeUnit(*unittype, &Players[playerno]); - if (unit == NULL) { + if (unit == nullptr) { DebugPrint("Unable to allocate unit"); return 0; } else { if (UnitCanBeAt(*unit, ipos) - || (unit->Type->Building && CanBuildUnitType(NULL, *unit->Type, ipos, 0))) { + || (unit->Type->Building && CanBuildUnitType(nullptr, *unit->Type, ipos, 0))) { unit->Place(ipos); } else { const int heading = SyncRand() % 256; unit->tilePos = ipos; - DropOutOnSide(*unit, heading, NULL); + DropOutOnSide(*unit, heading, nullptr); } UpdateForNewUnit(*unit, 0); @@ -871,7 +871,7 @@ static int CclDamageUnit(lua_State *l) LuaCheckArgs(l, 3); const int attacker = LuaToNumber(l, 1); - CUnit *attackerUnit = NULL; + CUnit *attackerUnit = nullptr; if (attacker != -1) { attackerUnit = &UnitManager->GetSlotUnit(attacker); } @@ -1279,7 +1279,7 @@ static int CclGetUnitVariable(lua_State *l) lua_pushvalue(l, 1); CUnit *unit = CclGetUnit(l); - if (unit == NULL) { + if (unit == nullptr) { return 1; } UpdateUnitVariables(*unit); diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp index 0420ae8b5..843e850c3 100644 --- a/src/unit/script_unittype.cpp +++ b/src/unit/script_unittype.cpp @@ -535,17 +535,17 @@ static int CclDefineUnitType(lua_State *l) if (type->Sprite && type->Sprite->File != type->File) { redefine |= redefineSprite; CGraphic::Free(type->Sprite); - type->Sprite = NULL; + type->Sprite = nullptr; } if (type->AltSprite && type->AltSprite->File != type->AltFile) { redefine |= redefineSprite; CGraphic::Free(type->AltSprite); - type->AltSprite = NULL; + type->AltSprite = nullptr; } if (redefine && type->ShadowSprite) { redefine |= redefineSprite; CGraphic::Free(type->ShadowSprite); - type->ShadowSprite = NULL; + type->ShadowSprite = nullptr; } } if (type->ShadowFile == shadowMarker) { @@ -593,7 +593,7 @@ static int CclDefineUnitType(lua_State *l) if (redefine && type->ShadowSprite) { redefine |= redefineSprite; CGraphic::Free(type->ShadowSprite); - type->ShadowSprite = NULL; + type->ShadowSprite = nullptr; } } else if (!strcmp(value, "Offset")) { CclGetPos(l, &type->OffsetX, &type->OffsetY); @@ -606,7 +606,7 @@ static int CclDefineUnitType(lua_State *l) } } else if (!strcmp(value, "Icon")) { type->Icon.Name = LuaToString(l, -1); - type->Icon.Icon = NULL; + type->Icon.Icon = nullptr; if (GameRunning) { type->Icon.Load(); } @@ -729,7 +729,7 @@ static int CclDefineUnitType(lua_State *l) type->ReactRangePerson = LuaToNumber(l, -1); } else if (!strcmp(value, "Missile")) { type->Missile.Name = LuaToString(l, -1); - type->Missile.Missile = NULL; + type->Missile.Missile = nullptr; if (GameRunning) { type->Missile.MapMissile(); } @@ -753,7 +753,7 @@ static int CclDefineUnitType(lua_State *l) type->DecayRate = LuaToNumber(l, -1); } else if (!strcmp(value, "Corpse")) { type->CorpseName = LuaToString(l, -1); - type->CorpseType = NULL; + type->CorpseType = nullptr; if (GameRunning) { if (!type->CorpseName.empty()) { type->CorpseType = UnitTypeByIdent(type->CorpseName); @@ -766,7 +766,7 @@ static int CclDefineUnitType(lua_State *l) } else if (!strcmp(value, "ExplodeWhenKilled")) { type->ExplodeWhenKilled = 1; type->Explosion.Name = LuaToString(l, -1); - type->Explosion.Missile = NULL; + type->Explosion.Missile = nullptr; if (GameRunning) { type->Explosion.MapMissile(); } @@ -827,13 +827,13 @@ static int CclDefineUnitType(lua_State *l) if (!strcmp(dtype, "general")) { type->Impact[ANIMATIONS_DEATHTYPES].Name = LuaToString(l, -1, k + 1); - type->Impact[ANIMATIONS_DEATHTYPES].Missile = NULL; + type->Impact[ANIMATIONS_DEATHTYPES].Missile = nullptr; if (GameRunning) { type->Impact[ANIMATIONS_DEATHTYPES].MapMissile(); } } else if (!strcmp(dtype, "shield")) { type->Impact[ANIMATIONS_DEATHTYPES + 1].Name = LuaToString(l, -1, k + 1); - type->Impact[ANIMATIONS_DEATHTYPES + 1].Missile = NULL; + type->Impact[ANIMATIONS_DEATHTYPES + 1].Missile = nullptr; if (GameRunning) { type->Impact[ANIMATIONS_DEATHTYPES + 1].MapMissile(); } @@ -848,7 +848,7 @@ static int CclDefineUnitType(lua_State *l) LuaError(l, "Death type not found: %s" _C_ dtype); } else { type->Impact[num].Name = LuaToString(l, -1, k + 1); - type->Impact[num].Missile = NULL; + type->Impact[num].Missile = nullptr; if (GameRunning) { type->Impact[num].MapMissile(); } @@ -1077,12 +1077,12 @@ static int CclDefineUnitType(lua_State *l) const int subargs = lua_rawlen(l, -1); if (subargs == 0) { delete[] type->CanCastSpell; - type->CanCastSpell = NULL; + type->CanCastSpell = nullptr; } for (int k = 0; k < subargs; ++k) { value = LuaToString(l, -1, k + 1); const SpellType *spell = SpellTypeByIdent(value); - if (spell == NULL) { + if (spell == nullptr) { LuaError(l, "Unknown spell type: %s" _C_ value); } type->CanCastSpell[spell->Slot] = 1; @@ -1102,13 +1102,13 @@ static int CclDefineUnitType(lua_State *l) const int subargs = lua_rawlen(l, -1); if (subargs == 0) { delete[] type->AutoCastActive; - type->AutoCastActive = NULL; + type->AutoCastActive = nullptr; } for (int k = 0; k < subargs; ++k) { value = LuaToString(l, -1, k + 1); const SpellType *spell = SpellTypeByIdent(value); - if (spell == NULL) { + if (spell == nullptr) { LuaError(l, "AutoCastActive : Unknown spell type: %s" _C_ value); } if (!spell->AutoCast) { @@ -1305,11 +1305,11 @@ static int CclCopyUnitType(lua_State *l) to->Height = from->Height; if (to->Sprite) { CGraphic::Free(to->Sprite); - to->Sprite = NULL; + to->Sprite = nullptr; } if (to->AltSprite) { CGraphic::Free(to->AltSprite); - to->AltSprite = NULL; + to->AltSprite = nullptr; } to->ShadowFile = from->ShadowFile; to->ShadowWidth = from->ShadowWidth; @@ -1320,13 +1320,13 @@ static int CclCopyUnitType(lua_State *l) to->ShadowScale = from->ShadowScale; if (to->ShadowSprite) { CGraphic::Free(to->ShadowSprite); - to->ShadowSprite = NULL; + to->ShadowSprite = nullptr; } to->OffsetX = from->OffsetX; to->OffsetY = from->OffsetY; to->Animations = from->Animations; to->Icon.Name = from->Icon.Name; - to->Icon.Icon = NULL; + to->Icon.Icon = nullptr; #ifdef USE_MNG to->Portrait.Num = from->Portrait.Num; to->Portrait.Talking = from->Portrait.Talking; @@ -1367,7 +1367,7 @@ static int CclCopyUnitType(lua_State *l) to->ReactRangeComputer = from->ReactRangeComputer; to->ReactRangePerson = from->ReactRangePerson; to->Missile.Name = from->Missile.Name; - to->Missile.Missile = NULL; // filled in later + to->Missile.Missile = nullptr; // filled in later to->MinAttackRange = from->MinAttackRange; to->DefaultStat.Variables[ATTACKRANGE_INDEX].Value = from->DefaultStat.Variables[ATTACKRANGE_INDEX].Value; to->DefaultStat.Variables[ATTACKRANGE_INDEX].Max = from->DefaultStat.Variables[ATTACKRANGE_INDEX].Max; @@ -1384,7 +1384,7 @@ static int CclCopyUnitType(lua_State *l) to->DamageType = from->DamageType; to->ExplodeWhenKilled = from->ExplodeWhenKilled; to->Explosion.Name = from->Explosion.Name; - to->Explosion.Missile = NULL; // filled later + to->Explosion.Missile = nullptr; // filled later to->TeleportCost = from->TeleportCost; to->TeleportEffectIn = from->TeleportEffectIn; to->TeleportEffectOut = from->TeleportEffectOut; @@ -1598,7 +1598,7 @@ CUnitType *CclGetUnitType(lua_State *l) } } LuaError(l, "CclGetUnitType: not a unit-type"); - return NULL; + return nullptr; } /** @@ -2063,7 +2063,7 @@ static int CclDefineDecorations(lua_State *l) const int nargs = lua_gettop(l); for (int i = 0; i < nargs; i++) { Assert(lua_istable(l, i + 1)); - CDecoVar *decovar = NULL; + CDecoVar *decovar = nullptr; memset(&tmp, 0, sizeof(tmp)); lua_pushnil(l); while (lua_next(l, i + 1)) { diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index 558274a20..090366765 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -119,7 +119,7 @@ ** ** CUnit::Container ** -** Pointer to the unit containing it, or NULL if the unit is +** Pointer to the unit containing it, or nullptr if the unit is ** free. This points to the transporter for units on board, or to ** the building for peasants inside(when they are mining). ** @@ -127,7 +127,7 @@ ** ** Pointer to the last unit added inside. Order doesn't really ** matter. All units inside are kept in a circular linked list. -** This is NULL if there are no units inside. Multiple levels +** This is nullptr if there are no units inside. Multiple levels ** of inclusion are allowed, though not very useful right now ** ** CUnit::NextContained, CUnit::PrevContained @@ -319,7 +319,7 @@ ** ** CUnit::RescuedFrom ** -** Pointer to the original owner of a unit. It will be NULL if +** Pointer to the original owner of a unit. It will be nullptr if ** the unit was not rescued. ** ** CUnit::Orders @@ -408,22 +408,22 @@ void CUnit::Init() PlayerSlot = static_cast(-1); InsideCount = 0; BoardCount = 0; - UnitInside = NULL; - Container = NULL; - NextContained = NULL; - PrevContained = NULL; - NextWorker = NULL; + UnitInside = nullptr; + Container = nullptr; + NextContained = nullptr; + PrevContained = nullptr; + NextWorker = nullptr; - Resource.Workers = NULL; + Resource.Workers = nullptr; Resource.Assigned = 0; Resource.Active = 0; tilePos.x = 0; tilePos.y = 0; Offset = 0; - Type = NULL; - Player = NULL; - Stats = NULL; + Type = nullptr; + Player = nullptr; + Stats = nullptr; CurrentSightRange = 0; delete pathFinderData; @@ -457,11 +457,11 @@ void CUnit::Init() MineLow = 0; ZDisplaced = 0; TeamSelected = 0; - RescuedFrom = NULL; + RescuedFrom = nullptr; memset(VisCount, 0, sizeof(VisCount)); memset(&Seen, 0, sizeof(Seen)); delete Variable; - Variable = NULL; + Variable = nullptr; TTL = 0; GroupId = 0; LastGroup = 0; @@ -472,20 +472,20 @@ void CUnit::Init() memset(&WaitBackup, 0, sizeof(WaitBackup)); Orders.clear(); delete SavedOrder; - SavedOrder = NULL; + SavedOrder = nullptr; delete NewOrder; - NewOrder = NULL; + NewOrder = nullptr; delete CriticalOrder; - CriticalOrder = NULL; + CriticalOrder = nullptr; delete AutoCastSpell; - AutoCastSpell = NULL; + AutoCastSpell = nullptr; delete SpellCoolDownTimers; - SpellCoolDownTimers = NULL; - Goal = NULL; + SpellCoolDownTimers = nullptr; + Goal = nullptr; } CUnit::~CUnit() { - Type = NULL; + Type = nullptr; delete pathFinderData; delete[] AutoCastSpell; @@ -555,24 +555,24 @@ void CUnit::Release(bool final) // read a BoolFlag; there are more instances of this...) for (std::vector::iterator order = Orders.begin(); order != Orders.end(); ++order) { COrder *orderToDelete = *order; - *order = NULL; + *order = nullptr; delete orderToDelete; } Orders.clear(); - if (SavedOrder != NULL) { + if (SavedOrder != nullptr) { COrder *order = SavedOrder; - SavedOrder = NULL; + SavedOrder = nullptr; delete order; } - if (NewOrder != NULL) { + if (NewOrder != nullptr) { COrder *order = NewOrder; - NewOrder = NULL; + NewOrder = nullptr; delete order; } - if (CriticalOrder != NULL) { + if (CriticalOrder != nullptr) { COrder *order = CriticalOrder; - CriticalOrder = NULL; + CriticalOrder = nullptr; delete order; } @@ -645,7 +645,7 @@ void CUnit::Init(const CUnitType &type) Variable = new CVariable[size]; std::copy(type.MapDefaultStat.Variables, type.MapDefaultStat.Variables + size, Variable); } else { - Variable = NULL; + Variable = nullptr; } memset(IndividualUpgrades, 0, sizeof(IndividualUpgrades)); @@ -679,12 +679,12 @@ void CUnit::Init(const CUnitType &type) Orders.push_back(COrder::NewActionStill()); - Assert(NewOrder == NULL); - NewOrder = NULL; - Assert(SavedOrder == NULL); - SavedOrder = NULL; - Assert(CriticalOrder == NULL); - CriticalOrder = NULL; + Assert(NewOrder == nullptr); + NewOrder = nullptr; + Assert(SavedOrder == nullptr); + SavedOrder = nullptr; + Assert(CriticalOrder == nullptr); + CriticalOrder = nullptr; } /** @@ -696,13 +696,13 @@ bool CUnit::RestoreOrder() { COrder *savedOrder = this->SavedOrder; - if (savedOrder == NULL) { + if (savedOrder == nullptr) { return false; } if (savedOrder->IsValid() == false) { delete savedOrder; - this->SavedOrder = NULL; + this->SavedOrder = nullptr; return false; } @@ -713,7 +713,7 @@ bool CUnit::RestoreOrder() //copy this->Orders.insert(this->Orders.begin() + 1, savedOrder); - this->SavedOrder = NULL; + this->SavedOrder = nullptr; return true; } @@ -729,7 +729,7 @@ bool CUnit::CanStoreOrder(COrder *order) if ((order && order->Finished == true) || order->IsValid() == false) { return false; } - if (this->SavedOrder != NULL) { + if (this->SavedOrder != nullptr) { return false; } return true; @@ -795,8 +795,8 @@ void CUnit::AssignToPlayer(CPlayer &player) CUnit *MakeUnit(const CUnitType &type, CPlayer *player) { CUnit *unit = UnitManager->AllocUnit(); - if (unit == NULL) { - return NULL; + if (unit == nullptr) { + return nullptr; } unit->Init(type); // Only Assign if a Player was specified @@ -1092,7 +1092,7 @@ void UnmarkUnitFieldFlags(const CUnit &unit) */ void CUnit::AddInContainer(CUnit &host) { - Assert(Container == NULL); + Assert(Container == nullptr); Container = &host; if (!Type) { // if we're loading a game, the Type may not have been initialized @@ -1140,13 +1140,13 @@ static void RemoveUnitFromContainer(CUnit &unit) unit.NextContained->PrevContained = unit.PrevContained; unit.PrevContained->NextContained = unit.NextContained; if (host->InsideCount == 0) { - host->UnitInside = NULL; + host->UnitInside = nullptr; } else { if (host->UnitInside == &unit) { host->UnitInside = unit.NextContained; } } - unit.Container = NULL; + unit.Container = nullptr; } @@ -1244,7 +1244,7 @@ CUnit *MakeUnitAndPlace(const Vec2i &pos, const CUnitType &type, CPlayer *player { CUnit *unit = MakeUnit(type, player); - if (unit != NULL) { + if (unit != nullptr) { unit->Place(pos); } return unit; @@ -1358,7 +1358,7 @@ void CUnit::Remove(CUnit *host) // Unit is seen as under cursor if (UnitUnderCursor == this) { - UnitUnderCursor = NULL; + UnitUnderCursor = nullptr; } } @@ -1463,11 +1463,11 @@ void UnitLost(CUnit &unit) DebugPrint("%d: Lost %s(%d)\n" _C_ player.Index _C_ type.Ident.c_str() _C_ UnitNumber(unit)); // Destroy resource-platform, must re-make resource patch. - CBuildRestrictionOnTop *b = OnTopDetails(unit, NULL); - if (b != NULL) { + CBuildRestrictionOnTop *b = OnTopDetails(unit, nullptr); + if (b != nullptr) { if (b->ReplaceOnDie && (type.GivesResource && unit.ResourcesHeld != 0)) { CUnit *temp = MakeUnitAndPlace(unit.tilePos, *b->Parent, &Players[PlayerNumNeutral]); - if (temp == NULL) { + if (temp == nullptr) { DebugPrint("Unable to allocate Unit\n"); } else { temp->ResourcesHeld = unit.ResourcesHeld; @@ -1597,7 +1597,7 @@ void CorrectWallDirections(CUnit &unit) const CUnitCache &unitCache = Map.Field(pos)->UnitCache; const CUnit *neighboor = unitCache.find(HasSamePlayerAndTypeAs(unit)); - if (neighboor != NULL) { + if (neighboor != nullptr) { flags |= dirFlag; } } @@ -1625,7 +1625,7 @@ void CorrectWallNeighBours(CUnit &unit) CUnitCache &unitCache = Map.Field(pos)->UnitCache; CUnit *neighboor = unitCache.find(HasSamePlayerAndTypeAs(unit)); - if (neighboor != NULL) { + if (neighboor != nullptr) { CorrectWallDirections(*neighboor); UnitUpdateHeading(*neighboor); } @@ -1959,7 +1959,7 @@ void CUnit::AssignWorkerToMine(CUnit &mine) if (IsMineAssignedBy(mine, *this) == true) { return; } - Assert(this->NextWorker == NULL); + Assert(this->NextWorker == nullptr); CUnit *head = mine.Resource.Workers; #if 0 @@ -1980,7 +1980,7 @@ void CUnit::DeAssignWorkerFromMine(CUnit &mine) if (IsMineAssignedBy(mine, *this) == false) { return ; } - CUnit *prev = NULL, *worker = mine.Resource.Workers; + CUnit *prev = nullptr, *worker = mine.Resource.Workers; #if 0 DebugPrint("%d: Worker [%d] is removing from %s [%d] left %d units assigned\n" _C_ this->Player->Index _C_ this->Slot @@ -1988,10 +1988,10 @@ void CUnit::DeAssignWorkerFromMine(CUnit &mine) _C_ mine.Slot _C_ mine.CurrentOrder()->Data.Resource.Assigned); #endif - for (int i = 0; NULL != worker; worker = worker->NextWorker, ++i) { + for (int i = 0; nullptr != worker; worker = worker->NextWorker, ++i) { if (worker == this) { CUnit *next = worker->NextWorker; - worker->NextWorker = NULL; + worker->NextWorker = nullptr; if (prev) { prev->NextWorker = next; } @@ -2427,7 +2427,7 @@ void DropOutAll(const CUnit &source) */ CUnit *UnitOnScreen(int x, int y) { - CUnit *candidate = NULL; + CUnit *candidate = nullptr; for (CUnitManager::Iterator it = UnitManager->begin(); it != UnitManager->end(); ++it) { CUnit &unit = **it; if (!ReplayRevealMap && !unit.IsVisibleAsGoal(*ThisPlayer)) { @@ -2526,11 +2526,11 @@ void LetUnitDie(CUnit &unit, bool suicide) } // Handle Teleporter Destination Removal if (type->BoolFlag[TELEPORTER_INDEX].value && unit.Goal) { - unit.Goal->Remove(NULL); + unit.Goal->Remove(nullptr); UnitLost(*unit.Goal); UnitClearOrders(*unit.Goal); unit.Goal->Release(); - unit.Goal = NULL; + unit.Goal = nullptr; } // Transporters lose or save their units and building their workers @@ -2540,7 +2540,7 @@ void LetUnitDie(CUnit &unit, bool suicide) DestroyAllInside(unit); } - unit.Remove(NULL); + unit.Remove(nullptr); UnitLost(unit); UnitClearOrders(unit); @@ -2662,8 +2662,8 @@ int ThreatCalculate(const CUnit &unit, const CUnit &dest) int TargetPriorityCalculate(const CUnit *const attacker, const CUnit *const dest) { - Assert(attacker != NULL); - Assert(dest != NULL); + Assert(attacker != nullptr); + Assert(dest != nullptr); const CPlayer &player = *attacker->Player; const CUnitType &type = *attacker->Type; @@ -2759,7 +2759,7 @@ int TargetPriorityCalculate(const CUnit *const attacker, const CUnit *const dest */ bool InReactRange(const CUnit &unit, const CUnit &target) { - Assert(&target != NULL); + Assert(&target != nullptr); const int distance = unit.MapDistanceTo(target); const int range = (unit.Player->Type == PlayerTypes::PlayerPerson) ? unit.Type->ReactRangePerson @@ -2777,7 +2777,7 @@ bool InReactRange(const CUnit &unit, const CUnit &target) */ bool InAttackRange(const CUnit &unit, const CUnit &target) { - Assert(&target != NULL); + Assert(&target != nullptr); const int range = unit.Stats->Variables[ATTACKRANGE_INDEX].Max; const int minRange = unit.Type->MinAttackRange; const int distance = unit.Container ? unit.Container->MapDistanceTo(target) @@ -2824,7 +2824,7 @@ bool InAttackRange(const CUnit &unit, const Vec2i &tilePos) */ Vec2i GetRndPosInDirection(const Vec2i &srcPos, const CUnit &dirUnit, const bool dirFrom, const int minRange, const int devRadius, const int rangeDev) { - Assert(&dirUnit != NULL); + Assert(&dirUnit != nullptr); const Vec2i dirPos = dirUnit.tilePos + dirUnit.Type->GetHalfTileSize(); return GetRndPosInDirection(srcPos, dirPos, dirFrom, minRange, devRadius, rangeDev); } @@ -3022,7 +3022,7 @@ static void HitUnit_RunAway(CUnit &target, const CUnit &attacker) const Vec2i pos = GetRndPosInDirection(target.tilePos, attacker, true, 5, 3); if (target.IsAgressive()) { - CommandAttack(target, pos, NULL, 0); /// Attack-move to pos + CommandAttack(target, pos, nullptr, 0); /// Attack-move to pos } else { CommandMove(target, pos, 0); /// Run away to pos } @@ -3077,16 +3077,16 @@ static void HitUnit_AttackBack(CUnit &attacker, CUnit &target) if (!PlaceReachable(target, posToAttack, 1, 1, 0, target.Stats->Variables[ATTACKRANGE_INDEX].Max, false)) { return; } - COrder *savedOrder = NULL; + COrder *savedOrder = nullptr; if (targetCurrAction == UnitActionStill || targetCurrAction == UnitActionStandGround) { savedOrder = COrder::NewActionAttack(target, target.tilePos); } else if (target.CanStoreOrder(target.CurrentOrder())) { savedOrder = target.CurrentOrder()->Clone(); } target.UnderAttack = underAttack; /// allow target to ignore non aggressive targets while searching attacker - CommandAttack(target, posToAttack, NULL, FlushCommands); + CommandAttack(target, posToAttack, nullptr, FlushCommands); - if (savedOrder != NULL) { + if (savedOrder != nullptr) { target.SavedOrder = savedOrder; } break; @@ -3524,12 +3524,12 @@ void CleanUnits() for (std::vector::iterator it = units.begin(); it != units.end(); ++it) { CUnit *unit = *it; - if (unit == NULL) { + if (unit == nullptr) { continue; } if (!unit->Destroyed) { if (!unit->Removed) { - unit->Remove(NULL); + unit->Remove(nullptr); } UnitClearOrders(*unit); } diff --git a/src/unit/unit_draw.cpp b/src/unit/unit_draw.cpp index bcec20718..e089a5cfa 100644 --- a/src/unit/unit_draw.cpp +++ b/src/unit/unit_draw.cpp @@ -70,7 +70,7 @@ class Decoration { public: - Decoration() : HotPos(0, 0), Width(0), Height(0), Sprite(NULL) {} + Decoration() : HotPos(0, 0), Width(0), Height(0), Sprite(nullptr) {} std::string File; /// File containing the graphics data PixelPos HotPos; /// drawing position (relative) @@ -320,7 +320,7 @@ static int CclDefineSprites(lua_State *l) Decoration deco; lua_pushnil(l); - const char *name = NULL;// name of the current sprite. + const char *name = nullptr;// name of the current sprite. while (lua_next(l, i + 1)) { const char *key = LuaToString(l, -2); // key name if (!strcmp(key, "Name")) { @@ -336,7 +336,7 @@ static int CclDefineSprites(lua_State *l) } lua_pop(l, 1); // pop the value; } - if (name == NULL) { + if (name == nullptr) { LuaError(l, "CclDefineSprites requires the Name flag for sprite."); } int index = GetSpriteIndex(name); // Index of the Sprite. @@ -952,7 +952,7 @@ void CUnit::Draw(const CViewport &vp) const cframe = &order.GetFrame(); } else { - cframe = NULL; + cframe = nullptr; } } else { screenPos = vp.TilePosToScreen_TopLeft(this->Seen.tilePos); diff --git a/src/unit/unit_find.cpp b/src/unit/unit_find.cpp index e6f2a3a47..61add7f13 100644 --- a/src/unit/unit_find.cpp +++ b/src/unit/unit_find.cpp @@ -80,7 +80,7 @@ CUnit *UnitFinder::FindUnitAtPos(const Vec2i &pos) const return unit; } } - return NULL; + return nullptr; } VisitResult UnitFinder::Visit(TerrainTraversal &terrainTraversal, const Vec2i &pos, const Vec2i &from) @@ -314,7 +314,7 @@ public: resultMine(resultMine) { bestCost.SetToMax(); - *resultMine = NULL; + *resultMine = nullptr; } VisitResult Visit(TerrainTraversal &terrainTraversal, const Vec2i &pos, const Vec2i &from); private: @@ -418,7 +418,7 @@ VisitResult ResourceUnitFinder::Visit(TerrainTraversal &terrainTraversal, const ** @note This will return an usable resource building that doesn't ** belong to the player or one of his allies. ** -** @return NULL or resource unit +** @return nullptr or resource unit */ CUnit *UnitFindResource(const CUnit &unit, const CUnit &startUnit, int range, int resource, bool check_usage, const CUnit *deposit) @@ -434,7 +434,7 @@ CUnit *UnitFindResource(const CUnit &unit, const CUnit &startUnit, int range, in terrainTraversal.PushUnitPosAndNeighboor(startUnit); - CUnit *resultMine = NULL; + CUnit *resultMine = nullptr; ResourceUnitFinder resourceUnitFinder(unit, deposit, resource, range, check_usage, &resultMine); @@ -451,7 +451,7 @@ CUnit *UnitFindResource(const CUnit &unit, const CUnit &startUnit, int range, in ** ** @note This will return a reachable allied depot. ** -** @return NULL or deposit unit +** @return nullptr or deposit unit */ CUnit *FindDeposit(const CUnit &unit, int range, int resource) { @@ -478,12 +478,12 @@ CUnit *FindDeposit(const CUnit &unit, int range, int resource) ** @param player Player's units to search through ** @param last Previous idle worker selected ** -** @return NULL or next idle worker +** @return nullptr or next idle worker */ CUnit *FindIdleWorker(const CPlayer &player, const CUnit *last) { - CUnit *FirstUnitFound = NULL; - int SelectNextUnit = (last == NULL) ? 1 : 0; + CUnit *FirstUnitFound = nullptr; + int SelectNextUnit = (last == nullptr) ? 1 : 0; const int nunits = player.GetUnitCount(); for (int i = 0; i < nunits; ++i) { @@ -493,7 +493,7 @@ CUnit *FindIdleWorker(const CPlayer &player, const CUnit *last) if (SelectNextUnit && !IsOnlySelected(unit)) { return &unit; } - if (FirstUnitFound == NULL) { + if (FirstUnitFound == nullptr) { FirstUnitFound = &unit; } } @@ -502,10 +502,10 @@ CUnit *FindIdleWorker(const CPlayer &player, const CUnit *last) SelectNextUnit = 1; } } - if (FirstUnitFound != NULL && !IsOnlySelected(*FirstUnitFound)) { + if (FirstUnitFound != nullptr && !IsOnlySelected(*FirstUnitFound)) { return FirstUnitFound; } - return NULL; + return nullptr; } /** @@ -606,7 +606,7 @@ CUnit *TargetOnMap(const CUnit &source, const Vec2i &pos1, const Vec2i &pos2) std::vector table; Select(pos1, pos2, table); - CUnit *best = NULL; + CUnit *best = nullptr; for (size_t i = 0; i != table.size(); ++i) { CUnit &unit = *table[i]; @@ -636,7 +636,7 @@ CUnit *TargetOnMap(const CUnit &source, const Vec2i &pos1, const Vec2i &pos2) ** @param resource resource type. ** @param mine_on_top return mine or mining area. ** -** @return Returns the deposit if found, or NULL. +** @return Returns the deposit if found, or nullptr. */ CUnit *ResourceOnMap(const Vec2i &pos, int resource, bool mine_on_top) { @@ -661,7 +661,7 @@ private: ** @param pos position on map, tile-based. ** @param resource resource type. ** -** @return Returns the deposit if found, or NULL. +** @return Returns the deposit if found, or nullptr. */ CUnit *ResourceDepositOnMap(const Vec2i &pos, int resource) { @@ -693,7 +693,7 @@ private: template CUnit *Find(Iterator begin, Iterator end) const { - CUnit *enemy = NULL; + CUnit *enemy = nullptr; int best_cost = GameSettings.SimplifiedAutoTargeting ? INT_MIN : INT_MAX; for (Iterator it = begin; it != end; ++it) { @@ -1167,7 +1167,7 @@ CUnit *AttackUnitsInDistance(const CUnit &unit, int range, CUnitFilter pred) if (table.empty() == false) { return BestRangeTargetFinder(unit, range).Find(table); } - return NULL; + return nullptr; } else { // If unit is removed, use containers x and y const CUnit *firstContainer = unit.Container ? unit.Container : &unit; diff --git a/src/unit/unit_manager.cpp b/src/unit/unit_manager.cpp index 16014b6f0..37cfbe89c 100644 --- a/src/unit/unit_manager.cpp +++ b/src/unit/unit_manager.cpp @@ -51,7 +51,7 @@ CUnitManager *UnitManager; /// Unit manager -- Functions ----------------------------------------------------------------------------*/ -CUnitManager::CUnitManager() : lastCreated(NULL) +CUnitManager::CUnitManager() : lastCreated(nullptr) { } @@ -60,7 +60,7 @@ CUnitManager::CUnitManager() : lastCreated(NULL) */ void CUnitManager::Init() { - lastCreated = NULL; + lastCreated = nullptr; //Assert(units.empty()); units.clear(); // Release memory of units in release list. @@ -109,7 +109,7 @@ void CUnitManager::ReleaseUnit(CUnit *unit) Assert(unit); if (lastCreated == unit) { - lastCreated = NULL; + lastCreated = nullptr; } if (unit->UnitManagerData.unitSlot != -1) { // == -1 when loading. Assert(units[unit->UnitManagerData.unitSlot] == unit); diff --git a/src/unit/unit_save.cpp b/src/unit/unit_save.cpp index 52eaaf0cf..d1c879ae1 100644 --- a/src/unit/unit_save.cpp +++ b/src/unit/unit_save.cpp @@ -71,7 +71,7 @@ std::string UnitReference(const CUnit &unit) */ std::string UnitReference(const CUnitPtr &unit) { - Assert(unit != NULL); + Assert(unit != nullptr); std::ostringstream ss; ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase @@ -276,7 +276,7 @@ void SaveUnit(const CUnit &unit, CFile &file) file.printf(" \"next-worker\", \"%s\",", UnitReference(*unit.NextWorker).c_str()); } - if (unit.Resource.Workers != NULL) { + if (unit.Resource.Workers != nullptr) { file.printf(" \"resource-active\", %d,", unit.Resource.Active); file.printf(" \"resource-assigned\", %d,", unit.Resource.Assigned); file.printf(" \"resource-workers\", \"%s\",", UnitReference(*unit.Resource.Workers).c_str()); diff --git a/src/unit/unitptr.cpp b/src/unit/unitptr.cpp index d6d2a3def..525906a72 100644 --- a/src/unit/unitptr.cpp +++ b/src/unit/unitptr.cpp @@ -53,7 +53,7 @@ void CUnitPtr::Reset() if (unit) { unit->RefsDecrease(); } - unit = NULL; + unit = nullptr; } CUnitPtr &CUnitPtr::operator= (CUnit *u) diff --git a/src/unit/unittype.cpp b/src/unit/unittype.cpp index af9923682..5d908b6d8 100644 --- a/src/unit/unittype.cpp +++ b/src/unit/unittype.cpp @@ -305,7 +305,7 @@ ** ** CUnitType::ResInfo[::MaxCosts] ** -** Information about resource harvesting. If NULL, it can't +** Information about resource harvesting. If nullptr, it can't ** harvest it. ** ** CUnitType::NeutralMinimapColorRGB @@ -520,15 +520,15 @@ int GetResourceIdByName(lua_State *l, const char *resourceName) CUnitType::CUnitType() : Slot(0), Width(0), Height(0), OffsetX(0), OffsetY(0), DrawLevel(0), ShadowWidth(0), ShadowHeight(0), ShadowOffsetX(0), ShadowOffsetY(0), - Animations(NULL), StillFrame(0), - OnDeath(NULL), OnHit(NULL), OnEachCycle(NULL), OnEachSecond(NULL), OnInit(NULL), - OnReady(NULL), TeleportCost(0), TeleportEffectIn(NULL), TeleportEffectOut(NULL), - CorpseType(NULL), Construction(NULL), RepairHP(0), TileWidth(0), TileHeight(0), + Animations(nullptr), StillFrame(0), + OnDeath(nullptr), OnHit(nullptr), OnEachCycle(nullptr), OnEachSecond(nullptr), OnInit(nullptr), + OnReady(nullptr), TeleportCost(0), TeleportEffectIn(nullptr), TeleportEffectOut(nullptr), + CorpseType(nullptr), Construction(nullptr), RepairHP(0), TileWidth(0), TileHeight(0), PersonalSpaceWidth(0), PersonalSpaceHeight(0), BoxWidth(0), BoxHeight(0), BoxOffsetX(0), BoxOffsetY(0), NumDirections(0), MinAttackRange(0), ReactRangeComputer(0), ReactRangePerson(0), BurnPercent(0), BurnDamageRate(0), RepairRange(0), - CanCastSpell(NULL), AutoCastActive(NULL), + CanCastSpell(nullptr), AutoCastActive(nullptr), AutoBuildRate(0), RandomMovementProbability(0), RandomMovementDistance(1), ClicksToExplode(0), MaxOnBoard(0), BoardSize(1), ButtonLevelForTransporter(0), StartingResources(0), UnitType(UnitTypeLand), DecayRate(0), AnnoyComputerFactor(0), AiAdjacentRange(-1), @@ -538,7 +538,7 @@ CUnitType::CUnitType() : CanAttack(0), Neutral(0), GivesResource(0), PoisonDrain(0), FieldFlags(0), MovementMask(0), - Sprite(NULL), AltSprite(NULL), ShadowSprite(NULL), ShadowSpriteFrame(0), ShadowScale(1) + Sprite(nullptr), AltSprite(nullptr), ShadowSprite(nullptr), ShadowSpriteFrame(0), ShadowScale(1) { #ifdef USE_MNG memset(&Portrait, 0, sizeof(Portrait)); @@ -851,7 +851,7 @@ CUnitType *UnitTypeByIdent(const std::string &ident) if (ret != UnitTypeMap.end()) { return (*ret).second; } - return NULL; + return nullptr; } /** @@ -933,11 +933,11 @@ static int GetStillFrame(const CUnitType &type) if (anim->Type == AnimationFrame) { CAnimation_Frame &a_frame = *static_cast(anim); // Use the frame facing down - return a_frame.ParseAnimInt(NULL) + type.NumDirections / 2; + return a_frame.ParseAnimInt(nullptr) + type.NumDirections / 2; } else if (anim->Type == AnimationExactFrame) { CAnimation_ExactFrame &a_frame = *static_cast(anim); - return a_frame.ParseAnimInt(NULL); + return a_frame.ParseAnimInt(nullptr); } anim = anim->Next; } @@ -953,7 +953,7 @@ void InitUnitTypes(int reset_player_stats) CUnitType &type = *UnitTypes[i]; Assert(type.Slot == (int)i); - if (type.Animations == NULL) { + if (type.Animations == nullptr) { DebugPrint(_("unit-type '%s' without animations, ignored.\n") _C_ type.Ident.c_str()); continue; } @@ -1127,8 +1127,8 @@ void CleanUnitTypes() UnitTypeVar.Clear(); // Clean hardcoded unit types. - UnitTypeHumanWall = NULL; - UnitTypeOrcWall = NULL; + UnitTypeHumanWall = nullptr; + UnitTypeOrcWall = nullptr; } //@} diff --git a/src/unit/upgrade.cpp b/src/unit/upgrade.cpp index 5bb063b88..cd5130eab 100644 --- a/src/unit/upgrade.cpp +++ b/src/unit/upgrade.cpp @@ -159,7 +159,7 @@ CUpgrade *CUpgrade::New(const std::string &ident) ** ** @param ident Upgrade identifier ** -** @return Upgrade pointer or NULL if not found. +** @return Upgrade pointer or nullptr if not found. */ CUpgrade *CUpgrade::Get(const std::string &ident) { diff --git a/src/video/cursor.cpp b/src/video/cursor.cpp index a84aa866f..e2336748b 100644 --- a/src/video/cursor.cpp +++ b/src/video/cursor.cpp @@ -120,10 +120,10 @@ SDL_Cursor *CCursor::GetSDLCursor() SDL_Rect srect = {G->frame_map[i].x, G->frame_map[i].y, G->getWidth(), G->getHeight()}; SDL_Surface *intermediate = SDL_CreateRGBSurface(0, srect.w, srect.h, 32, RMASK, GMASK, BMASK, AMASK); - SDL_BlitSurface(G->Surface, &srect, intermediate, NULL); + SDL_BlitSurface(G->Surface, &srect, intermediate, nullptr); SDL_Surface *cursorFrame = SDL_CreateRGBSurface(0, w, h, 32, RMASK, GMASK, BMASK, AMASK); - SDL_BlitScaled(intermediate, NULL, cursorFrame, NULL); + SDL_BlitScaled(intermediate, nullptr, cursorFrame, nullptr); SDL_FreeSurface(intermediate); @@ -200,7 +200,7 @@ CCursor *CursorByIdent(const std::string &ident) } } DebugPrint("Cursor '%s' not found, please check your code.\n" _C_ ident.c_str()); - return NULL; + return nullptr; } /** @@ -239,7 +239,7 @@ static void DrawBuildingCursor() const Vec2i mpos = vp.ScreenToTilePos(CursorScreenPos); const PixelPos screenPos = vp.TilePosToScreen_TopLeft(mpos); - CUnit *ontop = NULL; + CUnit *ontop = nullptr; // // Draw building @@ -267,14 +267,14 @@ static void DrawBuildingCursor() if (!Selected.empty()) { f = 1; for (size_t i = 0; f && i < Selected.size(); ++i) { - f = ((ontop = CanBuildHere(Selected[i], *CursorBuilding, mpos)) != NULL); - // Assign ontop or NULL - ontop = (ontop == Selected[i] ? NULL : ontop); + f = ((ontop = CanBuildHere(Selected[i], *CursorBuilding, mpos)) != nullptr); + // Assign ontop or nullptr + ontop = (ontop == Selected[i] ? nullptr : ontop); } } else { - f = ((ontop = CanBuildHere(NoUnitP, *CursorBuilding, mpos)) != NULL); + f = ((ontop = CanBuildHere(NoUnitP, *CursorBuilding, mpos)) != nullptr); if (!Editor.Running || ontop == (CUnit *)1) { - ontop = NULL; + ontop = nullptr; } } @@ -323,7 +323,7 @@ void DrawCursor() } } else if (ActuallyVisibleGameCursor) { SDL_SetCursor(Video.blankCursor); - ActuallyVisibleGameCursor = NULL; + ActuallyVisibleGameCursor = nullptr; } // Selecting rectangle @@ -338,10 +338,10 @@ void DrawCursor() // Cursor may not exist if we are loading a game or something. // Only draw it if it exists - if (GameCursor == NULL || IsDemoMode()) { + if (GameCursor == nullptr || IsDemoMode()) { if (Preference.HardwareCursor) { SDL_SetCursor(Video.blankCursor); - ActuallyVisibleGameCursor = NULL; + ActuallyVisibleGameCursor = nullptr; } return; } @@ -368,7 +368,7 @@ void DrawCursor() TheScreen->format->Amask); } SDL_Rect srcRect = { Sint16(pos.x), Sint16(pos.y), Uint16(GameCursor->G->getWidth()), Uint16(GameCursor->G->getHeight())}; - SDL_BlitSurface(TheScreen, &srcRect, HiddenSurface, NULL); + SDL_BlitSurface(TheScreen, &srcRect, HiddenSurface, nullptr); } if (!GameCursor->G->IsLoaded()) { @@ -396,10 +396,10 @@ void HideCursor() if (!Preference.HardwareCursor && !GameRunning && !Editor.Running && GameCursor) { const PixelPos pos = CursorScreenPos - GameCursor->HotPos; SDL_Rect dstRect = {Sint16(pos.x), Sint16(pos.y), 0, 0 }; - SDL_BlitSurface(HiddenSurface, NULL, TheScreen, &dstRect); + SDL_BlitSurface(HiddenSurface, nullptr, TheScreen, &dstRect); } else { SDL_SetCursor(Video.blankCursor); - ActuallyVisibleGameCursor = NULL; + ActuallyVisibleGameCursor = nullptr; } } @@ -442,9 +442,9 @@ void CleanCursors() } AllCursors.clear(); - CursorBuilding = NULL; - GameCursor = NULL; - UnitUnderCursor = NULL; + CursorBuilding = nullptr; + GameCursor = nullptr; + UnitUnderCursor = nullptr; } /** @@ -496,7 +496,7 @@ static int CclDefineCursor(lua_State *l) // // Look if this kind of cursor already exists. // - CCursor *ct = NULL; + CCursor *ct = nullptr; for (size_t i = 0; i < AllCursors.size(); ++i) { // Race not same, not found. if (AllCursors[i]->Race != race) { diff --git a/src/video/font.cpp b/src/video/font.cpp index 68c39bcbc..3934c2bff 100644 --- a/src/video/font.cpp +++ b/src/video/font.cpp @@ -85,7 +85,7 @@ CFont &GetSmallFont() bool IsGameFontReady() { - return GameFont != NULL || CFont::Get("game") != NULL; + return GameFont != nullptr || CFont::Get("game") != nullptr; } CFont &GetGameFont() @@ -793,7 +793,7 @@ static std::string FormatNumber(const int number) ** ** @param s original string. ** @param c character to find. -** @param maxlen size limit of the search. (0 means unlimited). (in char if font == NULL else in pixels). +** @param maxlen size limit of the search. (0 means unlimited). (in char if font == nullptr else in pixels). ** @param font if specified use font->Width() instead of strlen. ** ** @return computed value. @@ -837,7 +837,7 @@ static int strchrlen(const std::string &s, char c, unsigned int maxlen, const CF ** ** @param line line number. ** @param s multiline string. -** @param maxlen max length of the string (0 : unlimited) (in char if font == NULL else in pixels). +** @param maxlen max length of the string (0 : unlimited) (in char if font == nullptr else in pixels). ** @param font if specified use font->Width() instead of strlen. ** ** @return computed value. @@ -1002,12 +1002,12 @@ void ReloadFonts() std::map::iterator it = Fonts.find(ident); if (it == Fonts.end()) { DebugPrint("font not found: %s\n" _C_ ident.c_str()); - return NULL; + return nullptr; } CFont *font = it->second; - if (font == NULL) { + if (font == nullptr) { DebugPrint("font not found: %s\n" _C_ ident.c_str()); - return NULL; + return nullptr; } return font; } @@ -1035,7 +1035,7 @@ CFontColor::~CFontColor() { CFontColor *&fc = FontColors[ident]; - if (fc == NULL) { + if (fc == nullptr) { fc = new CFontColor(ident); } return fc; @@ -1079,8 +1079,8 @@ void CleanFonts() } FontColors.clear(); - SmallFont = NULL; - GameFont = NULL; + SmallFont = nullptr; + GameFont = nullptr; } //@} diff --git a/src/video/graphic.cpp b/src/video/graphic.cpp index 7b565a151..4cbfc2b6f 100644 --- a/src/video/graphic.cpp +++ b/src/video/graphic.cpp @@ -426,7 +426,7 @@ CGraphic *CGraphic::New(const std::string &filename, const int w, const int h) const std::string file = LibraryFileName(filename.c_str()); CGraphic *&g = GraphicHash[file]; - if (g == NULL) { + if (g == nullptr) { g = new CGraphic; if (!g) { fprintf(stderr, "Out of memory\n"); @@ -463,7 +463,7 @@ CPlayerColorGraphic *CPlayerColorGraphic::New(const std::string &filename, int w const std::string file = LibraryFileName(filename.c_str()); CPlayerColorGraphic *g = dynamic_cast(GraphicHash[file]); - if (g == NULL) { + if (g == nullptr) { g = new CPlayerColorGraphic; if (!g) { fprintf(stderr, "Out of memory\n"); @@ -538,7 +538,7 @@ CPlayerColorGraphic *CPlayerColorGraphic::Clone(bool grayscale) const CGraphic *CGraphic::Get(const std::string &filename) { if (filename.empty()) { - return NULL; + return nullptr; } const std::string file = LibraryFileName(filename.c_str()); @@ -557,7 +557,7 @@ CGraphic *CGraphic::Get(const std::string &filename) CPlayerColorGraphic *CPlayerColorGraphic::Get(const std::string &filename) { if (filename.empty()) { - return NULL; + return nullptr; } const std::string file = LibraryFileName(filename.c_str()); @@ -599,7 +599,7 @@ CPlayerColorGraphic *CPlayerColorGraphic::ForceNew(const std::string &file, int void CGraphic::GenFramesMap() { Assert(NumFrames != 0); - Assert(Surface != NULL); + Assert(Surface != nullptr); Assert(Width != 0); Assert(Height != 0); @@ -673,7 +673,7 @@ void CGraphic::Load(bool grayscale) goto error; } Surface = IMG_Load_RW(fp.as_SDL_RWops(), 0); - if (Surface == NULL) { + if (Surface == nullptr) { fprintf(stderr, "Couldn't load file %s: %s", name.c_str(), IMG_GetError()); goto error; } @@ -729,7 +729,7 @@ static void FreeSurface(SDL_Surface **surface) } VideoPaletteListRemove(*surface); - unsigned char *pixels = NULL; + unsigned char *pixels = nullptr; if ((*surface)->flags & SDL_PREALLOC) { pixels = (unsigned char *)(*surface)->pixels; @@ -737,7 +737,7 @@ static void FreeSurface(SDL_Surface **surface) SDL_FreeSurface(*surface); delete[] pixels; - *surface = NULL; + *surface = nullptr; } /** @@ -757,11 +757,11 @@ void CGraphic::Free(CGraphic *g) if (!g->Refs) { FreeSurface(&g->Surface); delete[] g->frame_map; - g->frame_map = NULL; + g->frame_map = nullptr; FreeSurface(&g->SurfaceFlip); delete[] g->frameFlip_map; - g->frameFlip_map = NULL; + g->frameFlip_map = nullptr; if (!g->HashFile.empty()) { GraphicHash.erase(g->HashFile); @@ -975,19 +975,19 @@ void CGraphic::SetOriginalSize() if (Surface) { FreeSurface(&Surface); - Surface = NULL; + Surface = nullptr; } delete[] frame_map; - frame_map = NULL; + frame_map = nullptr; if (SurfaceFlip) { FreeSurface(&SurfaceFlip); - SurfaceFlip = NULL; + SurfaceFlip = nullptr; } delete[] frameFlip_map; - frameFlip_map = NULL; + frameFlip_map = nullptr; this->Width = this->Height = 0; - this->Surface = NULL; + this->Surface = nullptr; this->Load(); Resized = false; @@ -1008,7 +1008,7 @@ void CGraphic::AppendFrames(const sequence_of_images &frames) for (auto &frame : frames) { SDL_Rect dstRect { frame_map[currFrame].x, frame_map[currFrame].y, Width, Height }; - SDL_BlitSurface(frame.get(), NULL, Surface, &dstRect); + SDL_BlitSurface(frame.get(), nullptr, Surface, &dstRect); currFrame++; } } @@ -1043,7 +1043,7 @@ void CGraphic::ExpandFor(const uint16_t numOfFramesToAdd) SDL_SetColorKey(newSurface, SDL_TRUE, ckey); } - SDL_FillRect(newSurface, NULL, useckey ? ckey : 0); + SDL_FillRect(newSurface, nullptr, useckey ? ckey : 0); /// Copy pixels const uint8_t *src = static_cast(Surface->pixels); @@ -1231,7 +1231,7 @@ static void applyAlphaGrayscaleToSurface(SDL_Surface **src, int alpha) DebugPrint("%s\n" _C_ SDL_GetError()); Assert(false); } - SDL_BlitSurface(*src, NULL, alphaSurface, NULL); + SDL_BlitSurface(*src, nullptr, alphaSurface, nullptr); SDL_SetSurfaceAlphaMod(alphaSurface, alpha); SDL_SetSurfaceColorMod(alphaSurface, 0, 0, 0); SDL_FreeSurface(*src); @@ -1331,7 +1331,7 @@ CFiller::bits_map::~bits_map() { if (bstore) { free(bstore); - bstore = NULL; + bstore = nullptr; } Width = 0; Height = 0; @@ -1345,7 +1345,7 @@ void CFiller::bits_map::Init(CGraphic *g) if (bstore) { free(bstore); - bstore = NULL; + bstore = nullptr; Width = 0; Height = 0; } diff --git a/src/video/mng.cpp b/src/video/mng.cpp index e19188041..f0cbfdfbe 100644 --- a/src/video/mng.cpp +++ b/src/video/mng.cpp @@ -122,7 +122,7 @@ static mng_bool MNG_DECL my_processheader(mng_handle handle, mng_uint32 width, mng->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8 * 3, Rmask, Gmask, Bmask, 0); SDL_SetColorKey(mng->surface, 1, 0); - if (mng->surface == NULL) { + if (mng->surface == nullptr) { fprintf(stderr, "Out of memory"); exit(1); } @@ -189,7 +189,7 @@ static mng_bool MNG_DECL my_errorproc(mng_handle handle, mng_int32, Mng::Mng() : - name(""), fd(NULL), handle(NULL), surface(NULL), buffer(NULL), + name(""), fd(nullptr), handle(nullptr), surface(nullptr), buffer(nullptr), ticks(0), iteration(0), is_dirty(false) { } @@ -219,7 +219,7 @@ void Mng::Draw(int x, int y) } SDL_Rect rect = {(short int)x, (short int)y, (short unsigned int)(surface->w), (short unsigned int)(surface->h)}; - SDL_BlitSurface(surface, NULL, TheScreen, &rect); + SDL_BlitSurface(surface, nullptr, TheScreen, &rect); } static std::map MngCache; @@ -228,7 +228,7 @@ Mng *Mng::New(const std::string &name) { const std::string file = LibraryFileName(name.c_str()); Mng *mng = MngCache[file]; - if (mng == NULL) { + if (mng == nullptr) { mng = new Mng(); mng->name = LibraryFileName(name.c_str()); Assert(mng); @@ -239,7 +239,7 @@ Mng *Mng::New(const std::string &name) void Mng::Free(Mng *mng) { - // XXX: Weird free bug that I don't understand, just skip it if already NULL + // XXX: Weird free bug that I don't understand, just skip it if already nullptr if ((intptr_t)mng < 40) { return; } diff --git a/src/video/movie.cpp b/src/video/movie.cpp index 29dce4aba..864ace872 100644 --- a/src/video/movie.cpp +++ b/src/video/movie.cpp @@ -199,7 +199,7 @@ int OggInit(CFile *f, OggData *data) if (num_theora) { theora_decode_init(&data->tstate, &data->tinfo); - data->tstate.internal_encode = NULL; // needed for a bug in libtheora (fixed in next release) + data->tstate.internal_encode = nullptr; // needed for a bug in libtheora (fixed in next release) } else { theora_info_clear(&data->tinfo); theora_comment_clear(&data->tcomment); @@ -270,9 +270,9 @@ static int OutputTheora(OggData *data, SDL_Texture *yuv_overlay, SDL_Rect *rect) theora_decode_YUVout(&data->tstate, &yuv); - SDL_UpdateYUVTexture(yuv_overlay, NULL, yuv.y, yuv.y_stride, yuv.u, yuv.uv_stride, yuv.v, yuv.uv_stride); + SDL_UpdateYUVTexture(yuv_overlay, nullptr, yuv.y, yuv.y_stride, yuv.u, yuv.uv_stride, yuv.v, yuv.uv_stride); SDL_RenderClear(TheRenderer); - SDL_RenderCopy(TheRenderer, yuv_overlay, NULL, rect); + SDL_RenderCopy(TheRenderer, yuv_overlay, nullptr, rect); SDL_RenderPresent(TheRenderer); return 0; @@ -352,7 +352,7 @@ int PlayMovie(const std::string &name) data.tinfo.frame_width, data.tinfo.frame_height); - if (yuv_overlay == NULL) { + if (yuv_overlay == nullptr) { fprintf(stderr, "SDL_CreateYUVOverlay: %s\n", SDL_GetError()); fprintf(stderr, "SDL_CreateYUVOverlay: %dx%d\n", data.tinfo.frame_width, data.tinfo.frame_height); OggFree(&data); @@ -385,7 +385,7 @@ int PlayMovie(const std::string &name) Invalidate(); SDL_RenderClear(TheRenderer); SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255); - SDL_RenderDrawRect(TheRenderer, NULL); + SDL_RenderDrawRect(TheRenderer, nullptr); // SDL_RenderPresent(TheRenderer); MovieStop = false; @@ -430,19 +430,19 @@ int PlayMovie(const std::string &name) Movie::~Movie() { - if (rect != NULL) { + if (rect != nullptr) { free(rect); } - if (surface != NULL) { + if (surface != nullptr) { SDL_FreeSurface(surface); } - if (yuv_overlay != NULL) { + if (yuv_overlay != nullptr) { SDL_DestroyTexture(yuv_overlay); } - if (data != NULL) { + if (data != nullptr) { OggFree(data); } - if (f != NULL) { + if (f != nullptr) { delete f; } } @@ -450,7 +450,7 @@ Movie::~Movie() static void RenderToSurface(SDL_Surface *surface, SDL_Texture *yuv_overlay, SDL_Rect *rect, OggData *data) { yuv_buffer *yuv = (yuv_buffer*)calloc(sizeof(yuv_buffer), 1); theora_decode_YUVout(&data->tstate, yuv); - SDL_UpdateYUVTexture(yuv_overlay, NULL, yuv->y, yuv->y_stride, yuv->u, yuv->uv_stride, yuv->v, yuv->uv_stride); + SDL_UpdateYUVTexture(yuv_overlay, nullptr, yuv->y, yuv->y_stride, yuv->u, yuv->uv_stride, yuv->v, yuv->uv_stride); SDL_RenderClear(TheRenderer); // since SDL will render us at logical size, and SDL_RenderReadPixels will read the at @@ -472,10 +472,10 @@ static void RenderToSurface(SDL_Surface *surface, SDL_Texture *yuv_overlay, SDL_ read_rect.h = rect->h; read_rect.x = (ww - (rw * scale)) / 2; read_rect.y = (wh - (rh * scale)) / 2; - SDL_RenderCopy(TheRenderer, yuv_overlay, NULL, &render_rect); + SDL_RenderCopy(TheRenderer, yuv_overlay, nullptr, &render_rect); if (SDL_RenderReadPixels(TheRenderer, &read_rect, surface->format->format, surface->pixels, surface->pitch)) { fprintf(stderr, "Reading from renderer not supported\n"); - SDL_FillRect(surface, NULL, 0); // completely transparent + SDL_FillRect(surface, nullptr, 0); // completely transparent } free(yuv); } @@ -504,7 +504,7 @@ bool Movie::Load(const std::string &name, int w, int h) 0x000000ff, 0xff000000); - if (surface == NULL) { + if (surface == nullptr) { fprintf(stderr, "SDL_CreateRGBSurface: %s\n", SDL_GetError()); f->close(); return false; @@ -515,7 +515,7 @@ bool Movie::Load(const std::string &name, int w, int h) void *Movie::_getData() const { - if (data == NULL) { + if (data == nullptr) { data = (OggData*)calloc(sizeof(OggData), 1); if (OggInit(f, data) || !data->video) { OggFree(data); @@ -531,7 +531,7 @@ void *Movie::_getData() const data->tinfo.frame_width, data->tinfo.frame_height); - if (yuv_overlay == NULL) { + if (yuv_overlay == nullptr) { fprintf(stderr, "SDL_CreateYUVOverlay: %s\n", SDL_GetError()); fprintf(stderr, "SDL_CreateYUVOverlay: %dx%d\n", data->tinfo.frame_width, data->tinfo.frame_height); OggFree(data); diff --git a/src/video/png.cpp b/src/video/png.cpp index 34a0688d1..e849922f7 100644 --- a/src/video/png.cpp +++ b/src/video/png.cpp @@ -67,7 +67,7 @@ void SaveScreenshotPNG(const char *name) void SaveMapPNG(const char *name) { FILE *fp = fopen(name, "wb"); - if (fp == NULL) { + if (fp == nullptr) { return; } diff --git a/src/video/sdl.cpp b/src/video/sdl.cpp index 8bd08021e..c67f9e486 100644 --- a/src/video/sdl.cpp +++ b/src/video/sdl.cpp @@ -89,7 +89,7 @@ ----------------------------------------------------------------------------*/ SDL_Window *TheWindow; /// Internal screen -SDL_Renderer *TheRenderer = NULL; /// Internal screen +SDL_Renderer *TheRenderer = nullptr; /// Internal screen SDL_Texture *TheTexture; /// Internal screen SDL_Surface *TheScreen; /// Internal screen @@ -297,14 +297,14 @@ static void setDpiAware() { if (userDLL) { SetProcessDPIAware = (BOOL(WINAPI *)(void)) SDL_LoadFunction(userDLL, "SetProcessDPIAware"); } else { - SetProcessDPIAware = NULL; + SetProcessDPIAware = nullptr; } shcoreDLL = SDL_LoadObject("SHCORE.DLL"); if (shcoreDLL) { SetProcessDpiAwareness = (HRESULT(WINAPI *)(PROCESS_DPI_AWARENESS)) SDL_LoadFunction(shcoreDLL, "SetProcessDpiAwareness"); } else { - SetProcessDpiAwareness = NULL; + SetProcessDpiAwareness = nullptr; } if (SetProcessDpiAwareness) { @@ -402,7 +402,7 @@ void InitVideoSdl() TheWindow = SDL_CreateWindow(win_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Video.WindowWidth, Video.WindowHeight, flags); - if (TheWindow == NULL) { + if (TheWindow == nullptr) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", Video.Width, Video.Height, Video.Depth, SDL_GetError()); exit(1); @@ -430,8 +430,8 @@ void InitVideoSdl() Video.ResizeScreen(Video.Width, Video.Height); // #ifdef USE_WIN32 -// HWND hwnd = NULL; -// HICON hicon = NULL; +// HWND hwnd = nullptr; +// HICON hicon = nullptr; // SDL_SysWMinfo info; // SDL_VERSION(&info.version); @@ -440,7 +440,7 @@ void InitVideoSdl() // } // if (hwnd) { -// hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0); +// hicon = ExtractIcon(GetModuleHandle(nullptr), Parameters::Instance.applicationName.c_str(), 0); // } // if (hicon) { @@ -451,8 +451,8 @@ void InitVideoSdl() #if ! defined(USE_WIN32) && ! defined(USE_MAEMO) - SDL_Surface *icon = NULL; - CGraphic *g = NULL; + SDL_Surface *icon = nullptr; + CGraphic *g = nullptr; struct stat st; std::string FullGameNameL = FullGameName; @@ -805,7 +805,7 @@ void WaitEventsOneFrame() break; } } - handleInput(NULL); + handleInput(nullptr); if (SkipGameCycle < 0) { SkipGameCycle += SkipCycles; @@ -853,12 +853,12 @@ void RealizeVideoMemory() } if (NumRects) { //SDL_UpdateWindowSurfaceRects(TheWindow, Rects, NumRects); - SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch); + SDL_UpdateTexture(TheTexture, nullptr, TheScreen->pixels, TheScreen->pitch); if (!RenderWithShader(TheRenderer, TheWindow, TheTexture)) { SDL_RenderClear(TheRenderer); //for (int i = 0; i < NumRects; i++) // SDL_UpdateTexture(TheTexture, &Rects[i], TheScreen->pixels, TheScreen->pitch); - SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL); + SDL_RenderCopy(TheRenderer, TheTexture, nullptr, nullptr); } if (Parameters::Instance.benchmark) { RenderBenchmarkOverlay(); diff --git a/src/video/shaders.cpp b/src/video/shaders.cpp index 361cd9221..9dabbbedb 100644 --- a/src/video/shaders.cpp +++ b/src/video/shaders.cpp @@ -86,7 +86,7 @@ void (CCONV *lazyGlOrtho)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdo static const int MAX_SHADERS = 128; static GLuint shaderPrograms[MAX_SHADERS + 1] = { (GLuint) 0 }; -static const char* shaderNames[MAX_SHADERS + 1] = { NULL }; +static const char* shaderNames[MAX_SHADERS + 1] = { nullptr }; static char shadersLoaded = -1; #define canUseShaders (shadersLoaded == 1) #define shadersAreInitialized (shadersLoaded != -1) @@ -112,7 +112,7 @@ static GLuint compileShader(const char* source, GLuint shaderType) { // Create ID for shader GLuint result = glCreateShader(shaderType); // Define shader text - glShaderSource(result, 1, &source, NULL); + glShaderSource(result, 1, &source, nullptr); // Compile shader glCompileShader(result); @@ -218,7 +218,7 @@ static int loadShaders() { char *cShaderPath; #ifdef _WIN32 shaderPath.append("\\shaders\\"); - int fullpathsize = ExpandEnvironmentStrings(shaderPath.c_str(), NULL, 0); + int fullpathsize = ExpandEnvironmentStrings(shaderPath.c_str(), nullptr, 0); cShaderPath = (char*)calloc(fullpathsize + 1, sizeof(char)); ExpandEnvironmentStrings(shaderPath.c_str(), cShaderPath, fullpathsize); #else @@ -284,10 +284,10 @@ bool RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* back static bool RenderWithShaderInternal(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer) { GLint oldProgramId; // Detach the texture - SDL_SetRenderTarget(renderer, NULL); + SDL_SetRenderTarget(renderer, nullptr); SDL_RenderClear(renderer); - SDL_GL_BindTexture(backBuffer, NULL, NULL); + SDL_GL_BindTexture(backBuffer, nullptr, nullptr); if (LastShaderIndex != currentShaderIdx) { LastShaderIndex = currentShaderIdx; // force to recalculate everything based on size, too @@ -475,7 +475,7 @@ static int CclSetShader(lua_State *l) { static int CclGetShaderNames(lua_State *l) { LuaCheckArgs(l, 0); lua_newtable(l); - for (int i = 0; shaderNames[i] != NULL; i++) { + for (int i = 0; shaderNames[i] != nullptr; i++) { lua_pushstring(l, shaderNames[i]); lua_rawseti(l, -2, i + 1); } diff --git a/src/video/video.cpp b/src/video/video.cpp index 421cc2863..0ea3e7c2c 100644 --- a/src/video/video.cpp +++ b/src/video/video.cpp @@ -118,7 +118,7 @@ private: static void CreateInstanceIfNeeded() { - if (s_instance == NULL) { + if (s_instance == nullptr) { s_instance = new CColorCycling; } } @@ -126,7 +126,7 @@ private: public: static CColorCycling &GetInstance() { CreateInstanceIfNeeded(); return *s_instance; } - static void ReleaseInstance() { delete s_instance; s_instance = NULL; } + static void ReleaseInstance() { delete s_instance; s_instance = nullptr; } public: std::vector PaletteList; /// List of all used palettes. std::vector ColorIndexRanges; /// List of range of color index for cycling. @@ -153,7 +153,7 @@ extern void SdlUnlockScreen(); /// Do SDL hardware unlock ----------------------------------------------------------------------------*/ CVideo Video; -/*static*/ CColorCycling *CColorCycling::s_instance = NULL; +/*static*/ CColorCycling *CColorCycling::s_instance = nullptr; char VideoForceFullScreen; /// fullscreen set from commandline @@ -441,7 +441,7 @@ void BlitSurfaceAlphaBlending_32bpp(const SDL_Surface *srcSurface, const SDL_Rec */ void VideoPaletteListAdd(SDL_Surface *surface) { - if (surface == NULL || surface->format == NULL || surface->format->BytesPerPixel != 1) { + if (surface == nullptr || surface->format == nullptr || surface->format->BytesPerPixel != 1) { return; } diff --git a/src/win32/SetupConsole_win32.cpp b/src/win32/SetupConsole_win32.cpp index 8094293d1..66e5c8b78 100644 --- a/src/win32/SetupConsole_win32.cpp +++ b/src/win32/SetupConsole_win32.cpp @@ -134,7 +134,7 @@ bool SetStreamAndFdFromStdConsole(FILE *stream, int fd, DWORD std, bool input) { *stream = *stream_new; /* Disable bufferring */ - setvbuf(stream, NULL, _IONBF, 0); + setvbuf(stream, nullptr, _IONBF, 0); return true; diff --git a/tests/network/test_net_lowlevel.cpp b/tests/network/test_net_lowlevel.cpp index 7aa9182dc..635729b9c 100644 --- a/tests/network/test_net_lowlevel.cpp +++ b/tests/network/test_net_lowlevel.cpp @@ -55,8 +55,8 @@ class Job public: virtual ~Job() {} - void Run() { pthread_create(&tid, NULL, Job::ThreadRun, this); } - void Wait() { pthread_join(tid, NULL); } + void Run() { pthread_create(&tid, nullptr, Job::ThreadRun, this); } + void Wait() { pthread_join(tid, nullptr); } private: virtual void DoJob() = 0; @@ -65,7 +65,7 @@ private: { Job *that = reinterpret_cast(data); that->DoJob(); - return NULL; + return nullptr; } private: @@ -104,7 +104,7 @@ void TCPRead(Socket socket, T *obj) class ServerTCP { public: - explicit ServerTCP(int port) { socket = NetOpenTCP(NULL, port); } + explicit ServerTCP(int port) { socket = NetOpenTCP(nullptr, port); } ~ServerTCP() { NetCloseTCP(socket); } bool Listen() { return NetListenTCP(socket) != -1; } @@ -126,7 +126,7 @@ private: class ClientTCP { public: - explicit ClientTCP(int port) { socket = NetOpenTCP(NULL, port); } + explicit ClientTCP(int port) { socket = NetOpenTCP(nullptr, port); } ~ClientTCP() { NetCloseTCP(socket); } bool Connect(const char *host, int port) { return NetConnectTCP(socket, NetResolveHost(host), port) != -1; } diff --git a/tests/stratagus/test_util.cpp b/tests/stratagus/test_util.cpp index 6017dca23..5dd1c3872 100644 --- a/tests/stratagus/test_util.cpp +++ b/tests/stratagus/test_util.cpp @@ -67,8 +67,8 @@ TEST(STRCPY_S) { char buffer[42]; - CHECK_EQUAL(EINVAL, strcpy_s(NULL, 42, "NULL dest")); - CHECK_EQUAL(EINVAL, strcpy_s(buffer, 42, NULL)); + CHECK_EQUAL(EINVAL, strcpy_s(nullptr, 42, "NULL dest")); + CHECK_EQUAL(EINVAL, strcpy_s(buffer, 42, nullptr)); CHECK_EQUAL(ERANGE, strcpy_s(buffer, 10, "longer than given size")); CHECK_EQUAL(0, strcpy_s(buffer, 10, "correct")); CHECK_EQUAL("correct", buffer); @@ -78,8 +78,8 @@ TEST(STRNCPY_S) { char buffer[42]; - CHECK_EQUAL(EINVAL, strncpy_s(NULL, 42, "NULL dest", 5)); - CHECK_EQUAL(EINVAL, strncpy_s(buffer, 42, NULL, 5)); + CHECK_EQUAL(EINVAL, strncpy_s(nullptr, 42, "NULL dest", 5)); + CHECK_EQUAL(EINVAL, strncpy_s(buffer, 42, nullptr, 5)); CHECK_EQUAL(EINVAL, strncpy_s(buffer, 10, "longer than given size", 12)); CHECK_EQUAL(0, strncpy_s(buffer, 10, "correct", 8)); CHECK_EQUAL("correct", buffer); @@ -91,8 +91,8 @@ TEST(STRCAT_S) buffer[0] = '\0'; - CHECK_EQUAL(EINVAL, strcat_s(NULL, 42, "NULL dest")); - CHECK_EQUAL(EINVAL, strcat_s(buffer, 42, NULL)); + CHECK_EQUAL(EINVAL, strcat_s(nullptr, 42, "NULL dest")); + CHECK_EQUAL(EINVAL, strcat_s(buffer, 42, nullptr)); CHECK_EQUAL(ERANGE, strcat_s(buffer, 10, "longer than given size")); CHECK_EQUAL(0, strcat_s(buffer, 42, "hello")); CHECK_EQUAL(0, strcat_s(buffer, 42, " world")); @@ -103,7 +103,7 @@ TEST(STRCASESTR) { const char *text = "HELLO world"; - CHECK(NULL == strcasestr(text, "not found")); + CHECK(nullptr == strcasestr(text, "not found")); CHECK(text == strcasestr(text, "HelLo")); CHECK(text + 6 == strcasestr(text, "WoRlD")); CHECK(text + 4 == strcasestr(text, "o")); diff --git a/tools/genversion.cpp b/tools/genversion.cpp index eb6352fd2..9df586a99 100644 --- a/tools/genversion.cpp +++ b/tools/genversion.cpp @@ -81,7 +81,7 @@ int main(int argc, char * argv[]) { fclose(file); } } else { - git_rev = NULL; + git_rev = nullptr; fprintf(stderr, "Cannot get git revision\n"); } @@ -94,7 +94,7 @@ int main(int argc, char * argv[]) { break; } } - if (git_rev == NULL) { + if (git_rev == nullptr) { needs_update = true; } @@ -112,7 +112,7 @@ int main(int argc, char * argv[]) { if ( ! file ) return 1; - if (git_rev == NULL) { + if (git_rev == nullptr) { fprintf(file, "/* %d %d %d %d no-rev */\n", new_ver[0], new_ver[1], new_ver[2], new_ver[3]); } else { fprintf(file, "/* %d %d %d %d %s */\n", new_ver[0], new_ver[1], new_ver[2], new_ver[3], git_rev); @@ -124,10 +124,10 @@ int main(int argc, char * argv[]) { fprintf(file, "#define StratagusPatchLevel2 %d\n", new_ver[3]); - if ( git_rev != NULL ) + if ( git_rev != nullptr ) fprintf(file, "#define StratagusGitRev %s\n", git_rev); - time_t tt = time(NULL); + time_t tt = time(nullptr); char *source_date_epoch = std::getenv("SOURCE_DATE_EPOCH"); if (source_date_epoch) { std::istringstream iss(source_date_epoch); diff --git a/tools/png2stratagus.cpp b/tools/png2stratagus.cpp index 5e6ed6356..0a0822cca 100644 --- a/tools/png2stratagus.cpp +++ b/tools/png2stratagus.cpp @@ -92,13 +92,13 @@ public: int bit_depth, color_type, interlace_type, compression_type, filter_type; int row_bytes; - if ((fp = fopen(filename.c_str (), "rb")) == NULL) + if ((fp = fopen(filename.c_str (), "rb")) == nullptr) { perror (filename.c_str ()); exit (EXIT_FAILURE); } - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); info_ptr = png_create_info_struct(png_ptr); png_init_io(png_ptr, fp); png_read_info(png_ptr, info_ptr); @@ -178,7 +178,7 @@ public: m_palette[i].blue = lpalette[i].blue; } - png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)nullptr); fclose (fp); } @@ -195,12 +195,12 @@ public: //png_uint_32 bytes_per_pixel = 1; fp = fopen(filename.c_str (), "wb"); - if (fp == NULL) + if (fp == nullptr) assert (false); - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); info_ptr = png_create_info_struct(png_ptr); png_init_io(png_ptr, fp);