- Moved weapon slot initialization into APlayerPawn::PostBeginPlay() so that

they can be initialized when players respawn in multiplayer.


SVN r1476 (trunk)
This commit is contained in:
Randy Heit 2009-03-12 03:54:23 +00:00
parent c65dc5bad4
commit 69c2c4de64
6 changed files with 109 additions and 40 deletions

View file

@ -1,4 +1,8 @@
March 11, 2009 (Changes by Graf Zahl) March 11, 2009
- Moved weapon slot initialization into APlayerPawn::PostBeginPlay() so that
they can be initialized when players respawn in multiplayer.
March 11, 2009 (Changes by Graf Zahl)
- Added a Check for the Vavoom namespace to the UDMF parser. Functionally - Added a Check for the Vavoom namespace to the UDMF parser. Functionally
it's 100% identical with ZDoom's own but needs to be checked for in it's 100% identical with ZDoom's own but needs to be checked for in
case Vavoom compatible UDMF maps are released. case Vavoom compatible UDMF maps are released.

View file

@ -80,6 +80,7 @@ class APlayerPawn : public AActor
public: public:
virtual void Serialize (FArchive &arc); virtual void Serialize (FArchive &arc);
virtual void PostBeginPlay();
virtual void Tick(); virtual void Tick();
virtual void AddInventory (AInventory *item); virtual void AddInventory (AInventory *item);
virtual void RemoveInventory (AInventory *item); virtual void RemoveInventory (AInventory *item);

View file

@ -922,7 +922,6 @@ void G_DoLoadLevel (int position, bool autosave)
} }
P_SetupLevel (level.mapname, position); P_SetupLevel (level.mapname, position);
P_CompleteWeaponSetup();
AM_LevelInit(); AM_LevelInit();

View file

@ -16,13 +16,15 @@ class AWeapon;
class FWeaponSlot class FWeaponSlot
{ {
public: public:
FWeaponSlot() { Clear(); }
FWeaponSlot(const FWeaponSlot &other) { Weapons = other.Weapons; }
FWeaponSlot &operator= (const FWeaponSlot &other) { Weapons = other.Weapons; return *this; } FWeaponSlot &operator= (const FWeaponSlot &other) { Weapons = other.Weapons; return *this; }
void Clear() { Weapons.Clear(); } void Clear() { Weapons.Clear(); }
bool AddWeapon (const char *type); bool AddWeapon (const char *type);
bool AddWeapon (const PClass *type); bool AddWeapon (const PClass *type);
void AddWeaponList (const char *list, bool clear); void AddWeaponList (const char *list, bool clear);
AWeapon *PickWeapon (player_t *player); AWeapon *PickWeapon (player_t *player);
int Size () { return (int)Weapons.Size(); } int Size () const { return (int)Weapons.Size(); }
int LocateWeapon (const PClass *type); int LocateWeapon (const PClass *type);
inline const PClass *GetWeapon (int index) const inline const PClass *GetWeapon (int index) const
@ -59,6 +61,9 @@ enum ESlotDef
struct FWeaponSlots struct FWeaponSlots
{ {
FWeaponSlots() { Clear(); }
FWeaponSlots(const FWeaponSlots &other);
FWeaponSlot Slots[NUM_WEAPON_SLOTS]; FWeaponSlot Slots[NUM_WEAPON_SLOTS];
AWeapon *PickNextWeapon (player_t *player); AWeapon *PickNextWeapon (player_t *player);
@ -69,7 +74,9 @@ struct FWeaponSlots
ESlotDef AddDefaultWeapon (int slot, const PClass *type); ESlotDef AddDefaultWeapon (int slot, const PClass *type);
void AddExtraWeapons(); void AddExtraWeapons();
void SetFromPlayer(const PClass *type); void SetFromPlayer(const PClass *type);
void CompleteSetup(const PClass *type); void StandardSetup(const PClass *type);
void LocalSetup(const PClass *type);
void SendDifferences(const FWeaponSlots &other);
int RestoreSlots (FConfigFile *config, const char *section); int RestoreSlots (FConfigFile *config, const char *section);
void PrintSettings(); void PrintSettings();
@ -78,8 +85,7 @@ struct FWeaponSlots
}; };
void P_PlaybackKeyConfWeapons(); void P_PlaybackKeyConfWeapons(FWeaponSlots *slots);
void P_CompleteWeaponSetup();
void Net_WriteWeapon(const PClass *type); void Net_WriteWeapon(const PClass *type);
const PClass *Net_ReadWeapon(BYTE **stream); const PClass *Net_ReadWeapon(BYTE **stream);

View file

@ -28,7 +28,7 @@ END_POINTERS
FString WeaponSection; FString WeaponSection;
TArray<FString> KeyConfWeapons; TArray<FString> KeyConfWeapons;
bool PlayingKeyConf; FWeaponSlots *PlayingKeyConf;
TArray<const PClass *> Weapons_ntoh; TArray<const PClass *> Weapons_ntoh;
TMap<const PClass *, int> Weapons_hton; TMap<const PClass *, int> Weapons_hton;
@ -642,8 +642,6 @@ bool AWeaponGiver::TryPickup(AActor *&toucher)
/* Weapon slots ***********************************************************/ /* Weapon slots ***********************************************************/
FWeaponSlots LocalWeapons;
//=========================================================================== //===========================================================================
// //
// FWeaponSlot :: AddWeapon // FWeaponSlot :: AddWeapon
@ -844,6 +842,20 @@ void FWeaponSlot::Sort()
} }
} }
//===========================================================================
//
// FWeaponSlots - Copy Constructor
//
//===========================================================================
FWeaponSlots::FWeaponSlots(const FWeaponSlots &other)
{
for (int i = 0; i < NUM_WEAPON_SLOTS; ++i)
{
Slots[i] = other.Slots[i];
}
}
//=========================================================================== //===========================================================================
// //
// FWeaponSlots :: Clear // FWeaponSlots :: Clear
@ -1105,24 +1117,36 @@ void FWeaponSlots::AddExtraWeapons()
//=========================================================================== //===========================================================================
// //
// FWeaponSlots :: CompleteSetup // FWeaponSlots :: StandardSetup
// //
// Sets up local weapon slots in this order: // Setup weapons in this order:
// 1. Use slots from player class. // 1. Use slots from player class.
// 2. Add extra weapons that specify their own slot. // 2. Add extra weapons that specify their own slots.
// 3. Run KEYCONF weapon commands, affecting slots accordingly. //
// 4. Read config slots, overriding current slots. If WeaponSection is set, //===========================================================================
void FWeaponSlots::StandardSetup(const PClass *type)
{
SetFromPlayer(type);
AddExtraWeapons();
}
//===========================================================================
//
// FWeaponSlots :: LocalSetup
//
// Setup weapons in this order:
// 1. Run KEYCONF weapon commands, affecting slots accordingly.
// 2. Read config slots, overriding current slots. If WeaponSection is set,
// then [<WeaponSection>.<PlayerClass>.Weapons] is tried, followed by // then [<WeaponSection>.<PlayerClass>.Weapons] is tried, followed by
// [<WeaponSection>.Weapons] if that did not exist. If WeaponSection is // [<WeaponSection>.Weapons] if that did not exist. If WeaponSection is
// empty, then the slots are read from [<PlayerClass>.Weapons]. // empty, then the slots are read from [<PlayerClass>.Weapons].
// //
//=========================================================================== //===========================================================================
void FWeaponSlots::CompleteSetup(const PClass *type) void FWeaponSlots::LocalSetup(const PClass *type)
{ {
SetFromPlayer(type); P_PlaybackKeyConfWeapons(this);
AddExtraWeapons();
P_PlaybackKeyConfWeapons();
if (WeaponSection.IsNotEmpty()) if (WeaponSection.IsNotEmpty())
{ {
FString sectionclass(WeaponSection); FString sectionclass(WeaponSection);
@ -1138,25 +1162,41 @@ void FWeaponSlots::CompleteSetup(const PClass *type)
} }
} }
void P_CompleteWeaponSetup() //===========================================================================
//
// FWeaponSlots :: SendDifferences
//
// Sends the weapon slots from this instance that differ from other's.
//
//===========================================================================
void FWeaponSlots::SendDifferences(const FWeaponSlots &other)
{ {
if (players[consoleplayer].mo != NULL) int i, j;
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
{ {
// Set up the weapon slots locally if (other.Slots[i].Size() == Slots[i].Size())
LocalWeapons.CompleteSetup(players[consoleplayer].mo->GetClass());
// Now transmit them across the network
for (int i = 0; i < NUM_WEAPON_SLOTS; ++i)
{ {
if (LocalWeapons.Slots[i].Size() > 0) for (j = (int)Slots[i].Size(); j-- > 0; )
{ {
if (other.Slots[i].GetWeapon(j) != Slots[i].GetWeapon(j))
{
break;
}
}
if (j < 0)
{ // The two slots are the same.
continue;
}
}
// The slots differ. Send mine.
Net_WriteByte(DEM_SETSLOT); Net_WriteByte(DEM_SETSLOT);
Net_WriteByte(i); Net_WriteByte(i);
Net_WriteByte(LocalWeapons.Slots[i].Size()); Net_WriteByte(Slots[i].Size());
for(int j = 0; j < LocalWeapons.Slots[i].Size(); j++) for (j = 0; j < Slots[i].Size(); ++j)
{ {
Net_WriteWeapon(LocalWeapons.Slots[i].GetWeapon(j)); Net_WriteWeapon(Slots[i].GetWeapon(j));
}
}
} }
} }
} }
@ -1268,12 +1308,12 @@ CCMD (setslot)
{ {
KeyConfWeapons.Push(argv.args()); KeyConfWeapons.Push(argv.args());
} }
else if (PlayingKeyConf) else if (PlayingKeyConf != NULL)
{ {
LocalWeapons.Slots[slot].Clear(); PlayingKeyConf->Slots[slot].Clear();
for (int i = 2; i < argv.argc(); ++i) for (int i = 2; i < argv.argc(); ++i)
{ {
LocalWeapons.Slots[slot].AddWeapon(argv[i]); PlayingKeyConf->Slots[slot].AddWeapon(argv[i]);
} }
} }
else else
@ -1321,9 +1361,9 @@ CCMD (addslot)
{ {
KeyConfWeapons.Push(argv.args()); KeyConfWeapons.Push(argv.args());
} }
else if (PlayingKeyConf) else if (PlayingKeyConf != NULL)
{ {
LocalWeapons.AddSlot(int(slot), PClass::FindClass(argv[2]), false); PlayingKeyConf->AddSlot(int(slot), PClass::FindClass(argv[2]), false);
} }
else else
{ {
@ -1397,9 +1437,9 @@ CCMD (addslotdefault)
{ {
KeyConfWeapons.Push(argv.args()); KeyConfWeapons.Push(argv.args());
} }
else if (PlayingKeyConf) else if (PlayingKeyConf != NULL)
{ {
LocalWeapons.AddSlotDefault(int(slot), PClass::FindClass(argv[2]), false); PlayingKeyConf->AddSlotDefault(int(slot), PClass::FindClass(argv[2]), false);
} }
else else
{ {
@ -1417,15 +1457,15 @@ CCMD (addslotdefault)
// //
//=========================================================================== //===========================================================================
void P_PlaybackKeyConfWeapons() void P_PlaybackKeyConfWeapons(FWeaponSlots *slots)
{ {
PlayingKeyConf = true; PlayingKeyConf = slots;
for (unsigned int i = 0; i < KeyConfWeapons.Size(); ++i) for (unsigned int i = 0; i < KeyConfWeapons.Size(); ++i)
{ {
FString cmd(KeyConfWeapons[i]); FString cmd(KeyConfWeapons[i]);
AddCommandString(cmd.LockBuffer()); AddCommandString(cmd.LockBuffer());
} }
PlayingKeyConf = false; PlayingKeyConf = NULL;
} }
//=========================================================================== //===========================================================================

View file

@ -491,7 +491,26 @@ void APlayerPawn::Tick()
Super::Tick(); Super::Tick();
} }
//===========================================================================
//
// APlayerPawn :: PostBeginPlay
//
//===========================================================================
void APlayerPawn::PostBeginPlay()
{
// If we're not a voodoo doll, set up our weapons.
if (player != NULL && player->mo == this)
{
player->weapons.StandardSetup(GetClass());
if (player - players == consoleplayer)
{ // If we're the local player, then there's a bit more work to do.
FWeaponSlots local_slots(player->weapons);
local_slots.LocalSetup(GetClass());
local_slots.SendDifferences(player->weapons);
}
}
}
//=========================================================================== //===========================================================================
// //