Skip to content

Commit

Permalink
Manually Tick() upgrades because we can't inherit them from Thinker s…
Browse files Browse the repository at this point in the history
…afely
  • Loading branch information
ToxicFrog committed Jun 30, 2022
1 parent 56dea99 commit 03da4fd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Putrefaction upgrade is now significantly more powerful
- new Hallucinogens upgrade makes severely poisoned enemies fight on your side
- Change: internal cleanup to UpgradeBag and Dot APIs
- Fix: crash when carrying upgraded weapons across level transitions

# 0.4

Expand Down
3 changes: 3 additions & 0 deletions ca.ancilla.laevis/PerPlayerStats.zs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ class ::PerPlayerStats : ::Force {
AddXP(owner.score - prevScore);
prevScore = owner.score;
}

upgrades.Tick();
info.upgrades.Tick();
}

States {
Expand Down
6 changes: 5 additions & 1 deletion ca.ancilla.laevis/upgrades/BaseUpgrade.zs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
// registration after the first.
#namespace TFLV::Upgrade;

class ::BaseUpgrade : Thinker {
class ::BaseUpgrade : Object play {
uint level;

// VIRTUAL FUNCTIONS //

// Tick function. Equivalent to Thinker.Tick() but we define it here because
// we can't inherit from Thinker and have the upgrades survive level changes.
virtual void Tick() {}

// Upgrade selection functions.
// These will be called when generating an upgrade to see if the upgrade should
// be added to the pool.
Expand Down
7 changes: 7 additions & 0 deletions ca.ancilla.laevis/upgrades/UpgradeBag.zs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
class ::UpgradeBag : Object play {
array<::BaseUpgrade> upgrades;

void Tick() {
for (uint i = 0; i < upgrades.Size(); ++i) {
upgrades[i].Tick();
}
}

::BaseUpgrade Add(string classname, uint level=1) {
return AddUpgrade(::BaseUpgrade(new(classname)), level);
}
Expand Down Expand Up @@ -54,6 +60,7 @@ class ::UpgradeBag : Object play {

double ModifyDamageDealt(Actor pawn, Actor shot, Actor target, double damage) {
for (uint i = 0; i < upgrades.Size(); ++i) {
DEBUG("UpgradeBag.ModifyDamageDealt: %d %s", i, TFLV::Util.SafeCls(upgrades[i]));
damage = upgrades[i].ModifyDamageDealt(pawn, shot, target, damage);
}
return damage;
Expand Down

0 comments on commit 03da4fd

Please sign in to comment.