Skip to content

Commit

Permalink
Energy Rework Part 5.3
Browse files Browse the repository at this point in the history
Starting with some macros, it's working alright. Updated the firework iuse actions to use the new transforms, removed the `taser2` iuse.

Remind myself to update the hand crank to actually recharge batteries after I'm done here.
  • Loading branch information
KheirFerrum committed Nov 21, 2024
1 parent 1b16cdf commit bafda51
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 259 deletions.
10 changes: 0 additions & 10 deletions data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,11 @@
"id": "FILL_PIT",
"name": { "str": "Fill pit / tamp ground" }
},
{
"type": "item_action",
"id": "FIRECRACKER",
"name": { "str": "Light up" }
},
{
"type": "item_action",
"id": "FIRECRACKER_ACT",
"name": { "str": "Light up" }
},
{
"type": "item_action",
"id": "FIRECRACKER_PACK",
"name": { "str": "Light up" }
},
{
"type": "item_action",
"id": "FIRECRACKER_PACK_ACT",
Expand Down
22 changes: 20 additions & 2 deletions data/json/items/tool/explosives.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,16 @@
"material": "paper",
"symbol": ";",
"color": "red",
"use_action": "FIRECRACKER",
"use_action": {
"target": "firecracker_act",
"msg": "You light the firecracker.",
"target_charges": 1,
"active": true,
"menu_text": "Light up",
"need_dry": true,
"need_fire": true,
"type": "transform"
},
"flags": [ "GRENADE" ]
},
{
Expand Down Expand Up @@ -416,7 +425,16 @@
"initial_charges": 25,
"max_charges": 25,
"charges_per_use": 1,
"use_action": "FIRECRACKER_PACK",
"use_action": {
"target": "firecracker_pack_act",
"msg": "You light the pack of firecrackers.",
"target_charges": 25,
"active": true,
"menu_text": "Light up",
"need_dry": true,
"need_fire": true,
"type": "transform"
},
"flags": [ "GRENADE" ]
},
{
Expand Down
5 changes: 4 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7822,8 +7822,11 @@ units::energy item::energy_required() const
return 0_J;
}

bool item::energy_sufficient( const Character &ch, units::energy p_needed ) const
bool item::energy_sufficient( const Character &ch, units::energy p_needed ) const
{
if( p_needed == -1_J ) {
p_needed = energy_required();
}
return energy_remaining() >= p_needed;
}

Expand Down
8 changes: 6 additions & 2 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1849,8 +1849,12 @@ class item : public location_visitable<item>, public game_object<item>
/** Amount of power consumed per usage of tool or with each shot of gun */
units::energy energy_required() const;

/** Check that item has sufficient energy */
bool energy_sufficient( const Character &ch, units::energy p_needed = 0_J ) const;
/**
* Check that item has sufficient energy
* @param ch Character to check (used if ammo is UPS charges)
* @param uses number of uses, if unspecified use 1x item default
*/
bool energy_sufficient( const Character &ch, units::energy p_needed = -1_J ) const;

/**
* Consume power(if available) and return the amount of power that was consumed
Expand Down
Loading

0 comments on commit bafda51

Please sign in to comment.