From 3d28006edaeb4a3815f2d37267a29b282fe02a3d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 4 Dec 2018 00:41:39 +0100 Subject: [PATCH] - started removing literal references of AInventory, so far only simple stuff. --- src/b_think.cpp | 6 +++--- src/ct_chat.cpp | 6 +++--- src/d_dehacked.cpp | 17 ++++++++--------- src/d_net.cpp | 6 +++--- src/g_game.cpp | 2 +- src/g_statusbar/sbarinfo_commands.cpp | 22 +++++++++++----------- src/p_acs.cpp | 6 +++--- src/p_actionfunctions.cpp | 2 +- src/p_conversation.cpp | 2 +- src/p_interaction.cpp | 2 +- src/p_lnspec.cpp | 4 ++-- src/p_mobj.cpp | 21 ++++++++++----------- src/v_blend.cpp | 2 +- 13 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/b_think.cpp b/src/b_think.cpp index 8c231f80e..33539a1a5 100644 --- a/src/b_think.cpp +++ b/src/b_think.cpp @@ -290,7 +290,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd) if (r < 128) { TThinkerIterator it (MAX_STATNUM+1, bglobal.firstthing); - AInventory *item = it.Next(); + auto item = it.Next(); if (item != NULL || (item = it.Next()) != NULL) { @@ -369,8 +369,8 @@ void DBot::WhatToGet (AActor *item) { if (!weapgiveammo) return; - auto ammo1 = heldWeapon->PointerVar(NAME_Ammo1); - auto ammo2 = heldWeapon->PointerVar(NAME_Ammo2); + auto ammo1 = heldWeapon->PointerVar(NAME_Ammo1); + auto ammo2 = heldWeapon->PointerVar(NAME_Ammo2); if ((ammo1 == NULL || ammo1->IntVar(NAME_Amount) >= ammo1->IntVar(NAME_MaxAmount)) && (ammo2 == NULL || ammo2->IntVar(NAME_Amount) >= ammo2->IntVar(NAME_MaxAmount))) { diff --git a/src/ct_chat.cpp b/src/ct_chat.cpp index b772e280c..ec3c4f4e2 100644 --- a/src/ct_chat.cpp +++ b/src/ct_chat.cpp @@ -375,8 +375,8 @@ static bool DoSubstitution (FString &out, const char *in) { player_t *player = &players[consoleplayer]; auto weapon = player->ReadyWeapon; - auto ammo1 = weapon ? weapon->PointerVar(NAME_Ammo1) : nullptr; - auto ammo2 = weapon ? weapon->PointerVar(NAME_Ammo2) : nullptr; + auto ammo1 = weapon ? weapon->PointerVar(NAME_Ammo1) : nullptr; + auto ammo2 = weapon ? weapon->PointerVar(NAME_Ammo2) : nullptr; const char *a, *b; a = in; @@ -415,7 +415,7 @@ static bool DoSubstitution (FString &out, const char *in) { if (strnicmp(a, "armor", 5) == 0) { - AInventory *armor = player->mo->FindInventory(NAME_BasicArmor); + auto armor = player->mo->FindInventory(NAME_BasicArmor); out.AppendFormat("%d", armor != NULL ? armor->IntVar(NAME_Amount) : 0); } } diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 8f69fc3e7..8daecc411 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1673,7 +1673,7 @@ static int PatchWeapon (int weapNum) AmmoType = AmmoNames[val]; if (AmmoType != nullptr) { - info->IntVar(NAME_AmmoGive1) = ((AInventory*)GetDefaultByType(AmmoType))->IntVar(NAME_Amount) * 2; + info->IntVar(NAME_AmmoGive1) = GetDefaultByType(AmmoType)->IntVar(NAME_Amount) * 2; auto &AmmoUse = info->IntVar(NAME_AmmoUse1); if (AmmoUse == 0) { @@ -1977,21 +1977,20 @@ static int PatchMisc (int dummy) barmor->IntVar("MaxSaveAmount") = deh.MaxArmor; } - AInventory *health; - health = static_cast (GetDefaultByName ("HealthBonus")); + auto health = GetDefaultByName ("HealthBonus"); if (health!=NULL) { health->IntVar(NAME_MaxAmount) = 2 * deh.MaxHealth; } - health = static_cast (GetDefaultByName ("Soulsphere")); + health = GetDefaultByName ("Soulsphere"); if (health!=NULL) { health->IntVar(NAME_Amount) = deh.SoulsphereHealth; health->IntVar(NAME_MaxAmount) = deh.MaxSoulsphere; } - health = static_cast (GetDefaultByName ("MegasphereHealth")); + health = GetDefaultByName ("MegasphereHealth"); if (health!=NULL) { health->IntVar(NAME_Amount) = health->IntVar(NAME_MaxAmount) = deh.MegasphereHealth; @@ -3067,8 +3066,8 @@ void FinishDehPatch () if (!type->IsDescendantOf(NAME_Inventory)) { - // If this is a hacked non-inventory item we must also copy AInventory's special states - statedef.AddStateDefines(RUNTIME_CLASS(AInventory)->GetStateLabels()); + // If this is a hacked non-inventory item we must also copy Inventory's special states + statedef.AddStateDefines(PClass::FindActor(NAME_Inventory)->GetStateLabels()); } statedef.InstallStates(subclass, defaults2); @@ -3111,7 +3110,7 @@ void FinishDehPatch () auto wcls = PClass::FindActor(NAME_Weapon); for(unsigned i = 0; i < WeaponNames.Size(); i++) { - AInventory *weap = (AInventory*)GetDefaultByType(WeaponNames[i]); + auto weap = GetDefaultByType(WeaponNames[i]); bool found = false; if (weap->flags6 & MF6_INTRYMOVE) { @@ -3163,7 +3162,7 @@ void FinishDehPatch () DEFINE_ACTION_FUNCTION(ADehackedPickup, DetermineType) { - PARAM_SELF_PROLOGUE(AInventory); + PARAM_SELF_PROLOGUE(AActor); // Look at the actor's current sprite to determine what kind of // item to pretend to me. diff --git a/src/d_net.cpp b/src/d_net.cpp index ac4f512f5..d271bc472 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2249,11 +2249,11 @@ void Net_DoCommand (int type, uint8_t **stream, int player) case DEM_INVUSEALL: if (gamestate == GS_LEVEL && !paused) { - AInventory *item = players[player].mo->Inventory; + auto item = players[player].mo->Inventory; auto pitype = PClass::FindActor(NAME_PuzzleItem); while (item != NULL) { - AInventory *next = item->Inventory; + auto next = item->Inventory; IFVIRTUALPTR(item, AInventory, UseAll) { VMValue param[] = { item, players[player].mo }; @@ -2275,7 +2275,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player) if (gamestate == GS_LEVEL && !paused && players[player].playerstate != PST_DEAD) { - AInventory *item = players[player].mo->Inventory; + auto item = players[player].mo->Inventory; while (item != NULL && item->InventoryID != which) { item = item->Inventory; diff --git a/src/g_game.cpp b/src/g_game.cpp index d99ec6e8e..33957673f 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -508,7 +508,7 @@ CCMD (select) { if (argv.argc() > 1) { - AInventory *item = who->FindInventory(argv[1]); + auto item = who->FindInventory(argv[1]); if (item != NULL) { who->InvSel = item; diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index 1cae8dcb8..22624542e 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -556,7 +556,7 @@ class CommandDrawSwitchableImage : public CommandDrawImage bool found2 = false; drawAlt = 1; - for(AInventory *item = statusBar->CPlayer->mo->Inventory;item != NULL;item = item->Inventory) + for(auto item = statusBar->CPlayer->mo->Inventory;item != NULL;item = item->Inventory) { if(item->IsKindOf(NAME_Key)) { @@ -1208,7 +1208,7 @@ class CommandDrawNumber : public CommandDrawString if (inventoryItem == NULL || !inventoryItem->IsDescendantOf(NAME_Inventory)) { sc.ScriptMessage("'%s' is not a type of inventory item.", sc.String); - inventoryItem = RUNTIME_CLASS(AInventory); + inventoryItem = PClass::FindActor(NAME_Inventory); } } sc.MustGetToken(','); @@ -1476,7 +1476,7 @@ class CommandDrawNumber : public CommandDrawString break; case KEYS: num = 0; - for(AInventory *item = statusBar->CPlayer->mo->Inventory;item != NULL;item = item->Inventory) + for(auto item = statusBar->CPlayer->mo->Inventory;item != NULL;item = item->Inventory) { if(item->IsKindOf(NAME_Key)) num++; @@ -2351,7 +2351,7 @@ class CommandDrawKeyBar : public SBarInfoCommand void Draw(const SBarInfoMainBlock *block, const DSBarInfo *statusBar) { - AInventory *item = statusBar->CPlayer->mo->Inventory; + auto item = statusBar->CPlayer->mo->Inventory; if(item == NULL) return; int slotOffset = 0; @@ -2603,7 +2603,7 @@ class CommandDrawBar : public SBarInfoCommand if(data.inventoryItem == NULL || !data.inventoryItem->IsDescendantOf(NAME_Inventory)) { sc.ScriptMessage("'%s' is not a type of inventory item.", sc.String); - data.inventoryItem = RUNTIME_CLASS(AInventory); + data.inventoryItem = PClass::FindActor(NAME_Inventory); } } sc.MustGetToken(','); @@ -2665,7 +2665,7 @@ class CommandDrawBar : public SBarInfoCommand max = data.value; else if(data.inventoryItem != NULL) { - AInventory *item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); //max comparer + auto item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); //max comparer if(item != NULL) max = item->IntVar(NAME_Amount); else @@ -2680,7 +2680,7 @@ class CommandDrawBar : public SBarInfoCommand max = data.value; else if(data.inventoryItem != NULL) { - AInventory *item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); + auto item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); if(item != NULL) max = item->IntVar(NAME_Amount); else @@ -2711,7 +2711,7 @@ class CommandDrawBar : public SBarInfoCommand break; case AMMO: { - AInventory *item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); + auto item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); if(item != NULL) { value = item->IntVar(NAME_Amount); @@ -2739,7 +2739,7 @@ class CommandDrawBar : public SBarInfoCommand break; case INVENTORY: { - AInventory *item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); + auto item = statusBar->CPlayer->mo->FindInventory(data.inventoryItem); if(item != NULL) { value = item->IntVar(NAME_Amount); @@ -2825,7 +2825,7 @@ class CommandDrawBar : public SBarInfoCommand if(data.inventoryItem == NULL || !data.inventoryItem->IsDescendantOf(NAME_Inventory)) //must be a kind of inventory { sc.ScriptMessage("'%s' is not a type of inventory item.", sc.String); - data.inventoryItem = RUNTIME_CLASS(AInventory); + data.inventoryItem = PClass::FindActor(NAME_Inventory); } } else if(extendedSyntax && sc.CheckToken(TK_IntConst)) @@ -3331,7 +3331,7 @@ class CommandInInventory : public SBarInfoNegatableFlowControl if (item[i] == NULL || !item[i]->IsDescendantOf(NAME_Inventory)) //must be a kind of ammo { sc.ScriptMessage("'%s' is not a type of inventory item.", sc.String); - item[i] = RUNTIME_CLASS(AInventory); + item[i] = PClass::FindActor(NAME_Inventory); } if (sc.CheckToken(',')) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 8f943fa37..e5c554b14 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1733,7 +1733,7 @@ void P_WriteACSVars(FSerializer &arc) static bool DoUseInv (AActor *actor, PClassActor *info) { - AInventory *item = actor->FindInventory (info); + auto item = actor->FindInventory (info); if (item != NULL) { player_t* const player = actor->player; @@ -1837,7 +1837,7 @@ int CheckInventory (AActor *activator, const char *type, bool max) return 0; } - AInventory *item = activator->FindInventory (info); + auto item = activator->FindInventory (info); if (max) { @@ -9357,7 +9357,7 @@ scriptwait: } else { - STACK(1) = ((AInventory *)GetDefaultByType (type))->IntVar(NAME_MaxAmount); + STACK(1) = GetDefaultByType (type)->IntVar(NAME_MaxAmount); } } else diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 0ab4a8aab..751fdc04b 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -2114,7 +2114,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_DropInventory) if (drop) { - AInventory *inv = self->FindInventory(drop); + auto inv = self->FindInventory(drop); if (inv) { self->DropInventory(inv, amount); diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 45e176261..cd2bc60c0 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -963,7 +963,7 @@ static void HandleReply(player_t *player, bool isconsole, int nodenum, int reply if (takestuff) { - AInventory *item = static_cast(Spawn(reply->GiveType)); + auto item = static_cast(Spawn(reply->GiveType)); // Items given here should not count as items! item->ClearCounters(); if (item->GetClass()->TypeName == NAME_FlameThrower) diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 51089352a..ecd996547 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -324,7 +324,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf //flags &= ~MF_INVINCIBLE; // [RH] Notify this actor's items. - for (AInventory *item = Inventory; item != NULL; ) + for (auto item = Inventory; item != NULL; ) { AInventory *next = item->Inventory; IFVIRTUALPTR(item, AInventory, OwnerDied) diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index 64184ea3a..b23965c3a 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -2961,7 +2961,7 @@ FUNC(LS_SetPlayerProperty) { // Take power from activator if (power != 4) { - AInventory *item = it->FindInventory(powers[power], true); + auto item = it->FindInventory(powers[power], true); if (item != NULL) { item->Destroy (); @@ -3001,7 +3001,7 @@ FUNC(LS_SetPlayerProperty) { // Take power if (power != 4) { - AInventory *item = players[i].mo->FindInventory (PClass::FindActor(powers[power])); + auto item = players[i].mo->FindInventory (PClass::FindActor(powers[power])); if (item != NULL) { item->Destroy (); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 0f2b65ff3..9ad85ebd2 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -781,7 +781,7 @@ void AActor::DestroyAllInventory () while (inv != nullptr) { toDelete.Push(inv); - AInventory *item = inv->Inventory; + auto item = inv->Inventory; inv->Inventory = nullptr; inv->PointerVar(NAME_Owner) = nullptr; inv = item; @@ -902,18 +902,17 @@ DEFINE_ACTION_FUNCTION(AActor, FindInventory) AInventory *AActor::GiveInventoryType (PClassActor *type) { - AInventory *item = NULL; - - if (type != NULL) + if (type != nullptr) { - item = static_cast(Spawn (type)); + auto item = static_cast(Spawn (type)); if (!CallTryPickup (item, this)) { item->Destroy (); - return NULL; + return nullptr; } + return item; } - return item; + return nullptr; } DEFINE_ACTION_FUNCTION(AActor, GiveInventoryType) @@ -1005,7 +1004,7 @@ void AActor::ObtainInventory (AActor *other) you->InvSel = NULL; } - AInventory *item = Inventory; + auto item = Inventory; while (item != nullptr) { item->PointerVar(NAME_Owner) = this; @@ -3451,7 +3450,7 @@ bool AActor::AdjustReflectionAngle (AActor *thing, DAngle &angle) int AActor::AbsorbDamage(int damage, FName dmgtype) { - for (AInventory *item = Inventory; item != nullptr; item = item->Inventory) + for (auto item = Inventory; item != nullptr; item = item->Inventory) { IFVIRTUALPTR(item, AInventory, AbsorbDamage) { @@ -3467,7 +3466,7 @@ void AActor::AlterWeaponSprite(visstyle_t *vis) int changed = 0; TArray items; // This needs to go backwards through the items but the list has no backlinks. - for (AInventory *item = Inventory; item != nullptr; item = item->Inventory) + for (auto item = Inventory; item != nullptr; item = item->Inventory) { items.Push(item); } @@ -3786,7 +3785,7 @@ void AActor::Tick () { // Handle powerup effects here so that the order is controlled // by the order in the inventory, not the order in the thinker table - AInventory *item = Inventory; + auto item = Inventory; while (item != NULL) { diff --git a/src/v_blend.cpp b/src/v_blend.cpp index 11307721c..5b9a55cf5 100644 --- a/src/v_blend.cpp +++ b/src/v_blend.cpp @@ -95,7 +95,7 @@ void V_AddPlayerBlend (player_t *CPlayer, float blend[4], float maxinvalpha, int int cnt; // [RH] All powerups can affect the screen blending now - for (AInventory *item = CPlayer->mo->Inventory; item != NULL; item = item->Inventory) + for (auto item = CPlayer->mo->Inventory; item != NULL; item = item->Inventory) { PalEntry color = 0;