@@ -213,66 +213,55 @@ std::unique_ptr<iuse_actor> iuse_transform::clone() const
213
213
214
214
void iuse_transform::load ( const JsonObject &obj, const std::string & )
215
215
{
216
- obj. read ( " target" , target, true );
217
- obj. read ( " target_group" , target_group, true );
216
+ optional ( obj, false , " target" , target );
217
+ optional ( obj, false , " target_group" , target_group );
218
218
219
219
if ( !target.is_empty () && !target_group.is_empty () ) {
220
220
obj.throw_error_at ( " target_group" , " Cannot use both target and target_group at once" );
221
221
}
222
222
223
- obj.read ( " msg" , msg_transform );
224
- obj.read ( " variant_type" , variant_type );
225
- obj.read ( " container" , container );
226
- obj.read ( " sealed" , sealed );
223
+ optional ( obj, false , " msg" , msg_transform );
224
+ optional ( obj, false , " msg" , msg_transform );
225
+ optional ( obj, false , " variant_type" , variant_type, " <any>" );
226
+ optional ( obj, false , " container" , container );
227
+ optional ( obj, false , " sealed" , sealed, true );
227
228
if ( obj.has_member ( " target_charges" ) && obj.has_member ( " rand_target_charges" ) ) {
228
229
obj.throw_error_at ( " target_charges" ,
229
230
" Transform actor specified both fixed and random target charges" );
230
231
}
231
- obj.read ( " target_charges" , ammo_qty );
232
- if ( obj.has_array ( " rand_target_charges" ) ) {
233
- for ( const int charge : obj.get_array ( " rand_target_charges" ) ) {
234
- random_ammo_qty.push_back ( charge );
235
- }
236
- if ( random_ammo_qty.size () < 2 ) {
237
- obj.throw_error_at ( " rand_target_charges" ,
238
- " You must specify two or more values to choose between" );
239
- }
232
+ optional ( obj, false , " target_charges" , ammo_qty, -1 );
233
+ optional ( obj, false , " rand_target_charges" , random_ammo_qty );
234
+ if ( random_ammo_qty.size () == 1 ) {
235
+ obj.throw_error_at ( " rand_target_charges" ,
236
+ " You must specify two or more values to choose between" );
240
237
}
241
- obj. read ( " target_ammo" , ammo_type );
238
+ optional ( obj, false , " target_ammo" , ammo_type );
242
239
243
- obj. read ( " target_timer" , target_timer );
240
+ optional ( obj, false , " target_timer" , target_timer, 0_seconds );
244
241
245
242
if ( !ammo_type.is_empty () && !container.is_empty () ) {
246
243
obj.throw_error_at ( " target_ammo" , " Transform actor specified both ammo type and container type" );
247
244
}
248
245
249
- obj. read ( " active" , active );
246
+ optional ( obj, false , " active" , active, false );
250
247
251
- obj.read ( " moves" , moves );
252
- if ( moves < 0 ) {
253
- obj.throw_error_at ( " moves" , " transform actor specified negative moves" );
254
- }
248
+ optional ( obj, false , " moves" , moves, numeric_bound_reader<int > { 0 }, 0 );
255
249
256
- obj.read ( " need_fire" , need_fire );
257
- need_fire = std::max ( need_fire, 0 );
258
- if ( !obj.read ( " need_charges_msg" , need_charges_msg ) ) {
259
- need_charges_msg = to_translation ( " The %s is empty!" );
260
- }
250
+ optional ( obj, false , " need_fire" , need_fire, numeric_bound_reader<int > { 0 }, 0 );
251
+ optional ( obj, false , " need_charges_msg" , need_charges_msg, to_translation ( " The %s is empty!" ) );
261
252
262
- obj.read ( " need_charges" , need_charges );
263
- need_charges = std::max ( need_charges, 0 );
264
- if ( !obj.read ( " need_fire_msg" , need_fire_msg ) ) {
265
- need_fire_msg = to_translation ( " You need a source of fire!" );
266
- }
253
+ optional ( obj, false , " need_charges" , need_charges, numeric_bound_reader<int > { 0 }, 0 );
254
+ optional ( obj, false , " need_fire_msg" , need_fire_msg,
255
+ to_translation ( " You need a source of fire!" ) );
267
256
268
- obj. read ( " need_worn" , need_worn );
269
- obj. read ( " need_wielding" , need_wielding );
257
+ optional ( obj, false , " need_worn" , need_worn, false );
258
+ optional ( obj, false , " need_wielding" , need_wielding, false );
270
259
271
- obj. read ( " need_empty" , need_empty );
260
+ optional ( obj, false , " need_empty" , need_empty, false );
272
261
273
- obj. read ( " qualities_needed" , qualities_needed );
262
+ optional ( obj, false , " qualities_needed" , qualities_needed );
274
263
275
- obj. read ( " menu_text" , menu_text );
264
+ optional ( obj, false , " menu_text" , menu_text );
276
265
}
277
266
278
267
std::optional<int > iuse_transform::use ( Character *p, item &it, const tripoint_bub_ms &pos ) const
@@ -572,9 +561,9 @@ std::unique_ptr<iuse_actor> unpack_actor::clone() const
572
561
573
562
void unpack_actor::load ( const JsonObject &obj, const std::string & )
574
563
{
575
- obj. read ( " group" , unpack_group );
576
- obj. read ( " items_fit" , items_fit );
577
- assign ( obj, " filthy_volume_threshold" , filthy_vol_threshold );
564
+ optional ( obj, false , " group" , unpack_group );
565
+ optional ( obj, false , " items_fit" , items_fit, false );
566
+ optional ( obj, false , " filthy_volume_threshold" , filthy_vol_threshold, 0_ml );
578
567
}
579
568
580
569
std::optional<int > unpack_actor::use ( Character *p, item &it, const tripoint_bub_ms &pos ) const
@@ -629,8 +618,8 @@ std::unique_ptr<iuse_actor> message_iuse::clone() const
629
618
630
619
void message_iuse::load ( const JsonObject &obj, const std::string & )
631
620
{
632
- obj. read ( " name" , name );
633
- obj. read ( " message" , message );
621
+ optional ( obj, false , " name" , name );
622
+ optional ( obj, false , " message" , message );
634
623
}
635
624
636
625
std::optional<int > message_iuse::use ( Character *p, item &it,
@@ -669,11 +658,11 @@ std::unique_ptr<iuse_actor> sound_iuse::clone() const
669
658
670
659
void sound_iuse::load ( const JsonObject &obj, const std::string & )
671
660
{
672
- obj. read ( " name" , name );
673
- obj. read ( " sound_message" , sound_message );
674
- obj. read ( " sound_volume" , sound_volume );
675
- obj. read ( " sound_id" , sound_id );
676
- obj. read ( " sound_variant" , sound_variant );
661
+ optional ( obj, false , " name" , name );
662
+ optional ( obj, false , " sound_message" , sound_message );
663
+ optional ( obj, false , " sound_volume" , sound_volume, 0 );
664
+ optional ( obj, false , " sound_id" , sound_id, " misc " );
665
+ optional ( obj, false , " sound_variant" , sound_variant, " default " );
677
666
}
678
667
679
668
std::optional<int > sound_iuse::use ( Character *, item &,
@@ -738,23 +727,20 @@ static std::vector<tripoint_bub_ms> points_for_gas_cloud( map *here, const tripo
738
727
void explosion_iuse::load ( const JsonObject &obj, const std::string & )
739
728
{
740
729
optional ( obj, false , " explosion" , explosion );
741
- obj.read ( " draw_explosion_radius" , draw_explosion_radius );
742
- if ( obj.has_member ( " draw_explosion_color" ) ) {
743
- draw_explosion_color = color_from_string ( obj.get_string ( " draw_explosion_color" ) );
744
- }
745
- obj.read ( " do_flashbang" , do_flashbang );
746
- obj.read ( " flashbang_player_immune" , flashbang_player_immune );
747
- obj.read ( " fields_radius" , fields_radius );
730
+ optional ( obj, false , " draw_explosion_radius" , draw_explosion_radius, -1 );
731
+ optional ( obj, false , " draw_explosion_color" , draw_explosion_color, nc_color_reader{}, c_white );
732
+ optional ( obj, false , " do_flashbang" , do_flashbang, false );
733
+ optional ( obj, false , " flashbang_player_immune" , flashbang_player_immune, false );
734
+ optional ( obj, false , " fields_radius" , fields_radius, -1 );
748
735
if ( obj.has_member ( " fields_type" ) || fields_radius > 0 ) {
749
- fields_type = field_type_id ( obj.get_string ( " fields_type" ) );
750
- }
751
- obj.read ( " fields_min_intensity" , fields_min_intensity );
752
- obj.read ( " fields_max_intensity" , fields_max_intensity );
753
- if ( fields_max_intensity == 0 ) {
754
- fields_max_intensity = fields_type.obj ().get_max_intensity ();
755
- }
756
- obj.read ( " emp_blast_radius" , emp_blast_radius );
757
- obj.read ( " scrambler_blast_radius" , scrambler_blast_radius );
736
+ mandatory ( obj, false , " fields_type" , fields_type );
737
+ }
738
+ optional ( obj, false , " fields_min_intensity" , fields_min_intensity, 1 );
739
+ // this should happen in finalize, fields_type is not necessarily loaded
740
+ optional ( obj, false , " fields_max_intensity" , fields_max_intensity,
741
+ fields_type->get_max_intensity () );
742
+ optional ( obj, false , " emp_blast_radius" , emp_blast_radius, -1 );
743
+ optional ( obj, false , " scrambler_blast_radius" , scrambler_blast_radius, -1 );
758
744
}
759
745
760
746
std::optional<int > explosion_iuse::use ( Character *p, item &it, const tripoint_bub_ms &pos ) const
0 commit comments