Skip to content

Commit

Permalink
Add dropped items spread handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
sidav committed Oct 23, 2024
1 parent a4f5e8b commit 0ebd1ba
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions mapinfo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gameinfo
AddEventHandlers = "AffixClassesCacheHandler"
AddEventHandlers = "AmmoDropsHandler"
AddEventHandlers = "DropsHandler"
AddEventHandlers = "DroppedItemsSpreadHandler"
AddEventHandlers = "ConsoleDropsHandler"
AddEventHandlers = "PressToPickupHandler"
AddEventHandlers = "StartingItemsHandler"
Expand Down
1 change: 1 addition & 0 deletions zscript.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ version "4.10.0"
#include "zscript/drops/ammo_drops_handler.zs"
#include "zscript/drops/drops_decider.zs"
#include "zscript/drops/drops_handler.zs"
#include "zscript/drops/dropped_items_spread_handler.zs"
#include "zscript/drops/drop_spreadable.zs"
#include "zscript/drops/console_drops_handler.zs"
#include "zscript/drops/default_items_replacements_handler.zs"
Expand Down
4 changes: 4 additions & 0 deletions zscript/drops/drop_spreadable.zs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ mixin class DropSpreadable {
a.Vel3DFromAngle(rnd.randf(8.0, 10.0), rnd.randf(1.0, 360.0), rnd.randf(-80.0, -60.0));
}

static play void AssignMinorSpreadVelocityTo(Actor a) {
a.Vel3DFromAngle(rnd.randf(4.0, 7.0), rnd.randf(0.0, 360.0), rnd.randf(-80.0, -60.0));
}

}
36 changes: 36 additions & 0 deletions zscript/drops/dropped_items_spread_handler.zs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Allows items to "jump" from other drops if too close.
class DroppedItemsSpreadHandler : EventHandler
{
mixin DropSpreadable;

int currTick;

override void WorldTick() {
currTick++;
if (currTick % TICRATE != 0) {
return;
}
let ti = ThinkerIterator.Create('Inventory');
Inventory itm;
while (itm = Inventory(ti.next())) {
let isRWInstance = (AffixableDetector.IsAffixableItem(itm));
if (itm && isRWInstance && rnd.OneChanceFrom(10)) {
moveItmIfNeeded(itm);
}
}
}

void moveItmIfNeeded(Inventory itmToMove) {
let ti = ThinkerIterator.Create('Inventory');
Inventory itm;
while (itm = Inventory(ti.next())) {
let isRWInstance = (AffixableDetector.IsAffixableItem(itm));
if (itm != itmToMove && itm && isRWInstance) {
let dist = itmToMove.Distance3D(itm);
if (dist <= itmToMove.radius) {
AssignMinorSpreadVelocityTo(itmToMove);
}
}
}
}
}

0 comments on commit 0ebd1ba

Please sign in to comment.