Skip to content

Commit 1cee9dc

Browse files
committed
Mandatory/optional for bionic_data
These functions have the best error reporting and support for extended features. Keep the bounds, even though they weren't actually checked, except for the case where there was existing JSON that was out of the bounds. Drop support for specifying integer kJ values instead of string, there are only a few uses of it.
1 parent 4c20b2c commit 1cee9dc

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

data/json/bionics.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@
14521452
"description": "A small module connected to your brain allows you to interface with nearby devices with wireless capabilities.",
14531453
"occupied_bodyparts": [ [ "head", 2 ] ],
14541454
"flags": [ "BIONIC_TOGGLED" ],
1455-
"react_cost": 1,
1455+
"react_cost": "1 kJ",
14561456
"time": "24 s"
14571457
},
14581458
{
@@ -1461,7 +1461,7 @@
14611461
"name": { "str": "Sonic Resonator" },
14621462
"description": "Your entire body may resonate at very high power, creating a short-range shockwave. While it will not do much damage to creatures, solid objects such as walls and doors will be damaged.",
14631463
"occupied_bodyparts": [ [ "torso", 15 ], [ "head", 1 ], [ "arm_l", 2 ], [ "arm_r", 2 ], [ "leg_l", 4 ], [ "leg_r", 4 ] ],
1464-
"act_cost": 100
1464+
"act_cost": "100 kJ"
14651465
},
14661466
{
14671467
"id": "bio_scent_mask",
@@ -1471,8 +1471,8 @@
14711471
"occupied_bodyparts": [ [ "torso", 3 ], [ "head", 1 ], [ "arm_l", 1 ], [ "arm_r", 1 ], [ "leg_l", 1 ], [ "leg_r", 1 ] ],
14721472
"flags": [ "BIONIC_TOGGLED" ],
14731473
"active_flags": [ "NO_SCENT" ],
1474-
"act_cost": 1,
1475-
"react_cost": 1,
1474+
"act_cost": "1 kJ",
1475+
"react_cost": "1 kJ",
14761476
"time": "1 m"
14771477
},
14781478
{
@@ -1492,7 +1492,6 @@
14921492
"flags": [ "BIONIC_TOGGLED" ],
14931493
"active_flags": [ "STOP_SLEEP_DEPRIVATION" ],
14941494
"occupied_bodyparts": [ [ "head", 1 ], [ "torso", 1 ] ],
1495-
"act_cost": 0,
14961495
"react_cost": "1 kJ",
14971496
"time": "100 s"
14981497
},
@@ -1511,7 +1510,7 @@
15111510
"name": { "str": "Shockwave Generator" },
15121511
"description": "You generate a powerful shockwave, knocking back all nearby creatures. Targets are stunned briefly, take damage and additional stun upon impact with impassable terrain, and knockback any creatures they collide with.",
15131512
"occupied_bodyparts": [ [ "torso", 20 ] ],
1514-
"act_cost": 250
1513+
"act_cost": "250 kJ"
15151514
},
15161515
{
15171516
"id": "bio_sleepy",
@@ -1648,7 +1647,7 @@
16481647
"name": { "str": "Teleportation Unit" },
16491648
"description": "This highly experimental unit folds space over short distances, instantly transporting your body up to 25 feet at the cost of much power. Note that prolonged or frequent use may have dangerous side effects.",
16501649
"occupied_bodyparts": [ [ "torso", 16 ], [ "arm_l", 3 ], [ "arm_r", 3 ], [ "leg_l", 4 ], [ "leg_r", 4 ] ],
1651-
"act_cost": 250
1650+
"act_cost": "250 kJ"
16521651
},
16531652
{
16541653
"id": "bio_thumbs",
@@ -1677,7 +1676,7 @@
16771676
[ "foot_l", 1 ],
16781677
[ "foot_r", 1 ]
16791678
],
1680-
"act_cost": 50
1679+
"act_cost": "50 kJ"
16811680
},
16821681
{
16831682
"id": "bio_tools",

src/bionics.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include "action.h"
2020
#include "activity_actor_definitions.h"
21-
#include "assign.h"
2221
#include "avatar.h"
2322
#include "avatar_action.h"
2423
#include "ballistics.h"
@@ -313,12 +312,15 @@ void bionic_data::load( const JsonObject &jsobj, std::string_view src )
313312
mandatory( jsobj, was_loaded, "description", description );
314313

315314
optional( jsobj, was_loaded, "cant_remove_reason", cant_remove_reason );
316-
// uses assign because optional doesn't handle loading units as strings
317-
assign( jsobj, "react_cost", power_over_time, false, 0_kJ );
318-
assign( jsobj, "capacity", capacity, false );
319-
assign( jsobj, "act_cost", power_activate, false, 0_kJ );
320-
assign( jsobj, "deact_cost", power_deactivate, false, 0_kJ );
321-
assign( jsobj, "trigger_cost", power_trigger, false, 0_kJ );
315+
optional( jsobj, was_loaded, "react_cost", power_over_time,
316+
units_bound_reader<units::energy>( 0_kJ ), 0_kJ );
317+
optional( jsobj, was_loaded, "capacity", capacity, 0_kJ );
318+
optional( jsobj, was_loaded, "act_cost", power_activate,
319+
units_bound_reader<units::energy>( 0_kJ ), 0_kJ );
320+
optional( jsobj, was_loaded, "deact_cost", power_deactivate,
321+
units_bound_reader<units::energy>( 0_kJ ), 0_kJ );
322+
optional( jsobj, was_loaded, "trigger_cost", power_trigger,
323+
units_bound_reader<units::energy>( 0_kJ ), 0_kJ );
322324

323325
optional( jsobj, was_loaded, "time", charge_time, 0_turns );
324326

0 commit comments

Comments
 (0)