Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nullptr instead of NULL. #446

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/action/action_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -350,18 +350,18 @@ 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)
const bool immobile = (this->Action == UnitActionStandGround || unit.Removed || !unit.CanMove()) ? true : false;
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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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))) {

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
26 changes: 13 additions & 13 deletions src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
}


Expand All @@ -316,7 +316,7 @@ bool COrder_Build::StartBuilding(CUnit &unit, CUnit &ontop)
CUnit *build = MakeUnit(const_cast<CUnitType &>(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());
Expand All @@ -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();
Expand Down Expand Up @@ -394,7 +394,7 @@ static void AnimateActionBuild(CUnit &unit)
{
CAnimations *animations = unit.Type->Animations;

if (animations == NULL) {
if (animations == nullptr) {
return ;
}
if (animations->Build) {
Expand All @@ -414,7 +414,7 @@ bool COrder_Build::BuildFromOutside(CUnit &unit) const
{
AnimateActionBuild(unit);

if (this->BuildingUnit == NULL) {
if (this->BuildingUnit == nullptr) {
return false;
}

Expand All @@ -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;
}
Expand All @@ -464,7 +464,7 @@ CUnit *COrder_Build::GetBuildingUnit() const
}
CUnit *ontop = this->CheckCanBuild(unit);

if (ontop != NULL) {
if (ontop != nullptr) {
this->StartBuilding(unit, *ontop);
}
}
Expand All @@ -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<COrder_Built *>(this->BuildingUnit->CurrentOrder());
targetOrder.Cancel(*this->BuildingUnit);
}
Expand Down
22 changes: 11 additions & 11 deletions src/action/action_built.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_defend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/action/action_die.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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 ;
}
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/action/action_follow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand All @@ -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)) {
Expand All @@ -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 ;
}
Expand All @@ -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) {
Expand All @@ -293,15 +293,15 @@ 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();
}

this->Finished = true;
unit.Orders.insert(unit.Orders.begin() + 1, COrder::NewActionAttack(unit, target->tilePos));

if (savedOrder != NULL) {
if (savedOrder != nullptr) {
unit.SavedOrder = savedOrder;
}
}
Expand Down
Loading
Loading