Skip to content

Commit

Permalink
Add Hunger Service
Browse files Browse the repository at this point in the history
Similar to the Respirator Service, this will give modders access to how much energy/fluids/sickness a given player has.
  • Loading branch information
UndeadZeratul authored and caligari87 committed Feb 14, 2024
1 parent a8267b7 commit 0e6b97e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
66 changes: 66 additions & 0 deletions hunger/module/hunger_service.zsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class UaS_HungerStatus : Service {
// Returns -1 on any invalid condition
override int GetInt(String request, string stringArg, int intArg, double doubleArg, Object objectArg) {
// Do casting and nullchecks for player and respirator
let p = HDPlayerPawn(objectArg); if (!p) return -1;
let r = UaS_HungerTracker(p.FindInventory("UaS_HungerTracker")); if (!r) return -1;

// Process the request
if (request ~== "Energy") { return int(r.energy); }
if (request ~== "Hydro") { return int(r.hydro); }
if (request ~== "Sick") { return int(r.sick); }
return -1;
}

// Returns -1 on any invalid condition
override int GetIntUI(String request, string stringArg, int intArg, double doubleArg, Object objectArg) {
// Do casting and nullchecks for player and respirator
let p = HDPlayerPawn(objectArg); if (!p) return -1;
let r = UaS_HungerTracker(p.FindInventory("UaS_HungerTracker")); if (!r) return -1;

// Process the request
if (request ~== "Energy") { return int(r.energy); }
if (request ~== "Hydro") { return int(r.hydro); }
if (request ~== "Sick") { return int(r.sick); }
return -1;
}
}

// Example implementation that returns the respirator status
// for whichever player uses the test item from inventory.
/*
class MyTestObject {
int getPlayerEnergy(int pnum) {
ServiceIterator i = ServiceIterator.Find("UaS_HungerStatus");
service HungerStatus;
while (HungerStatus = i.Next()) {
int energy = int(HungerStatus.GetInt("Energy", objectArg:players[pnum].mo));
console.printf("player "..pnum.." Energy "..energy);
return energy;
}
return -1;
}
int getPlayerThirst(int pnum) {
ServiceIterator i = ServiceIterator.Find("UaS_HungerStatus");
service HungerStatus;
while (HungerStatus = i.Next()) {
int thirst = int(HungerStatus.GetInt("Thirst", objectArg:players[pnum].mo));
console.printf("player "..pnum.." Thirst "..thirst);
return thirst;
}
return -1;
}
int getPlayerHunger(int pnum) {
ServiceIterator i = ServiceIterator.Find("UaS_HungerStatus");
service HungerStatus;
while (HungerStatus = i.Next()) {
int sick = int(HungerStatus.GetInt("Sick", objectArg:players[pnum].mo));
console.printf("player "..pnum.." Sick "..sick);
return sick;
}
return -1;
}
}
*/
1 change: 1 addition & 0 deletions hunger/zscript.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version "4.5"
#include "module/hunger_bootstrap.zsc"
#include "module/hunger_spawner.zsc"
#include "module/hunger_tracker.zsc"
#include "module/hunger_service.zsc"

// Consumable
#include "module/consumable/consumable.zsc"
Expand Down
1 change: 1 addition & 0 deletions zscript.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ version "4.10"
#include "food/module/food_drinks.zsc"
#include "food/module/food_basics.zsc"
#include "fragfactor/module/fragfactor.zsc"
#include "hunger/module/hunger_service.zsc"
#include "hunger/module/hunger_tracker.zsc"
#include "hunger/module/hunger_spawner.zsc"
#include "hunger/module/hunger_bootstrap.zsc"
Expand Down

0 comments on commit 0e6b97e

Please sign in to comment.