From 37d056c041e7718bc22873d02e6d0488bc5b331b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 27 Dec 2008 20:18:31 +0000 Subject: [PATCH] - Fixed: The correct player class was not remembered when the menu had both a player class selection menu and an episode menu. - Fixed: AddToConsole could write outside its working buffer. - Fixed: 0 was no longer recognized as placeholder for 'no state' in A_Chase. - Fixed: When picking up weapons the code did not check if it should switch away from weak weapons. SVN r1332 (trunk) --- docs/rh-log.txt | 8 ++++++++ src/c_console.cpp | 11 ++++++++++- src/d_player.h | 5 +++-- src/g_shared/a_pickups.cpp | 13 ++----------- src/g_shared/a_weapons.cpp | 9 +++++++++ src/m_menu.cpp | 9 ++++++++- src/p_user.cpp | 25 +++++++++++++++++++++++++ src/thingdef/thingdef_states.cpp | 9 ++++++++- 8 files changed, 73 insertions(+), 16 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 3aaa379d7..696c694ef 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,11 @@ +December 27, 2008 (Changes by Graf Zahl) +- Fixed: The correct player class was not remembered when the menu had both + a player class selection menu and an episode menu. +- Fixed: AddToConsole could write outside its working buffer. +- Fixed: 0 was no longer recognized as placeholder for 'no state' in A_Chase. +- Fixed: When picking up weapons the code did not check if it should switch away + from weak weapons. + December 20, 2008 - OggMod improperly decodes the right channel of stereo samples when sending them to OggEnc, so I have no choice but to convert them to mono by chopping diff --git a/src/c_console.cpp b/src/c_console.cpp index d66c403d1..76d135743 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -667,7 +667,7 @@ void AddToConsole (int printlevel, const char *text) } len = (int)strlen (text); - size = len + 3; + size = len + 20; if (addtype != NEWLINE) { @@ -767,6 +767,15 @@ void AddToConsole (int printlevel, const char *text) if (*work_p) { linestart = work_p - 1 - cc.Len(); + if (linestart < work) + { + // The line start is outside the buffer. + // Make space for the newly inserted stuff. + size_t movesize = work-linestart; + memmove(work + movesize, work, strlen(work)); + work_p += movesize; + linestart = work; + } linestart[0] = TEXTCOLOR_ESCAPE; strncpy (linestart + 1, cc, cc.Len()); } diff --git a/src/d_player.h b/src/d_player.h index 50518a543..c277311c2 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -80,8 +80,9 @@ public: virtual void TweakSpeeds (int &forwardmove, int &sidemove); virtual void MorphPlayerThink (); virtual void ActivateMorphWeapon (); - virtual AWeapon *PickNewWeapon (const PClass *ammotype); - virtual AWeapon *BestWeapon (const PClass *ammotype); + AWeapon *PickNewWeapon (const PClass *ammotype); + AWeapon *BestWeapon (const PClass *ammotype); + void CheckWeaponSwitch(const PClass *ammotype); virtual void GiveDeathmatchInventory (); virtual void FilterCoopRespawnInventory (APlayerPawn *oldplayer); diff --git a/src/g_shared/a_pickups.cpp b/src/g_shared/a_pickups.cpp index e3309fc87..8ae26365a 100644 --- a/src/g_shared/a_pickups.cpp +++ b/src/g_shared/a_pickups.cpp @@ -96,18 +96,9 @@ bool AAmmo::HandlePickup (AInventory *item) assert (Owner != NULL); - if (oldamount == 0 && Owner != NULL && Owner->player != NULL && - !Owner->player->userinfo.neverswitch && - Owner->player->PendingWeapon == WP_NOCHANGE && - (Owner->player->ReadyWeapon == NULL || - (Owner->player->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON))) + if (oldamount == 0 && Owner != NULL && Owner->player != NULL) { - AWeapon *best = barrier_cast(Owner)->BestWeapon (GetClass()); - if (best != NULL && (Owner->player->ReadyWeapon == NULL || - best->SelectionOrder < Owner->player->ReadyWeapon->SelectionOrder)) - { - Owner->player->PendingWeapon = best; - } + barrier_cast(Owner)->CheckWeaponSwitch(GetClass()); } } return true; diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index 33f27930e..b74a4e203 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -158,8 +158,17 @@ bool AWeapon::PickupForAmmo (AWeapon *ownedWeapon) // Don't take ammo if the weapon sticks around. if (!ShouldStay ()) { + int oldamount = 0; + if (ownedWeapon->Ammo1 != NULL) oldamount = ownedWeapon->Ammo1->Amount; + if (AmmoGive1 > 0) gotstuff = AddExistingAmmo (ownedWeapon->Ammo1, AmmoGive1); if (AmmoGive2 > 0) gotstuff |= AddExistingAmmo (ownedWeapon->Ammo2, AmmoGive2); + + AActor *Owner = ownedWeapon->Owner; + if (gotstuff && oldamount == 0 && Owner != NULL && Owner->player != NULL) + { + static_cast(Owner)->CheckWeaponSwitch(ownedWeapon->Ammo1->GetClass()); + } } return gotstuff; } diff --git a/src/m_menu.cpp b/src/m_menu.cpp index 09ad5db55..96b69e8a1 100644 --- a/src/m_menu.cpp +++ b/src/m_menu.cpp @@ -267,6 +267,8 @@ static FSaveGameNode NewSaveNode; static int epi; // Selected episode +static const char *saved_playerclass = NULL; + // PRIVATE MENU DEFINITIONS ------------------------------------------------ // @@ -1821,15 +1823,18 @@ void M_Episode (int choice) if (AllSkills.Size() == 1) { + saved_playerclass = NULL; M_ChooseSkill(0); return; } else if (EpisodeNoSkill[choice]) { + saved_playerclass = NULL; M_ChooseSkill(AllSkills.Size() == 2? 1:2); return; } - M_StartupSkillMenu(NULL); + M_StartupSkillMenu(saved_playerclass); + saved_playerclass = NULL; } //========================================================================== @@ -1856,6 +1861,7 @@ static void SCClass (int option) if (EpiDef.numitems > 1) { + saved_playerclass = playerclass; M_SetupNextMenu (&EpiDef); } else if (AllSkills.Size() == 1) @@ -1888,6 +1894,7 @@ static void M_ChooseClass (int choice) if (EpiDef.numitems > 1) { + saved_playerclass = playerclass; M_SetupNextMenu (&EpiDef); } else if (AllSkills.Size() == 1) diff --git a/src/p_user.cpp b/src/p_user.cpp index 245e3bff9..413f67e64 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -680,6 +680,31 @@ AWeapon *APlayerPawn::PickNewWeapon (const PClass *ammotype) return best; } + +//=========================================================================== +// +// APlayerPawn :: CheckWeaponSwitch +// +// Checks if weapons should be changed after picking up ammo +// +//=========================================================================== + +void APlayerPawn::CheckWeaponSwitch(const PClass *ammotype) +{ + if (!player->userinfo.neverswitch && + player->PendingWeapon == WP_NOCHANGE && + (player->ReadyWeapon == NULL || + (player->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON))) + { + AWeapon *best = BestWeapon (ammotype); + if (best != NULL && (player->ReadyWeapon == NULL || + best->SelectionOrder < player->ReadyWeapon->SelectionOrder)) + { + player->PendingWeapon = best; + } + } +} + //=========================================================================== // // APlayerPawn :: GiveDeathmatchInventory diff --git a/src/thingdef/thingdef_states.cpp b/src/thingdef/thingdef_states.cpp index 69d6a4946..9c88e87d9 100644 --- a/src/thingdef/thingdef_states.cpp +++ b/src/thingdef/thingdef_states.cpp @@ -325,7 +325,14 @@ do_stop: sc.ScriptError("Negative jump offsets are not allowed"); } - x = new FxStateByIndex(bag.statedef.GetStateCount() + v, sc); + if (x > 0) + { + x = new FxStateByIndex(bag.statedef.GetStateCount() + v, sc); + } + else + { + x = new FxConstant((FState*)NULL, sc); + } } else {