|
6 | 6 | #include <string>
|
7 | 7 | #include <utility>
|
8 | 8 |
|
9 |
| -#include "assign.h" |
10 | 9 | #include "calendar.h"
|
11 | 10 | #include "character.h"
|
12 | 11 | #include "condition.h"
|
@@ -123,13 +122,10 @@ void weakpoint_family::load( const JsonValue &jsin )
|
123 | 122 | proficiency = proficiency_id( id );
|
124 | 123 | } else {
|
125 | 124 | JsonObject jo = jsin.get_object();
|
126 |
| - assign( jo, "id", id ); |
127 |
| - assign( jo, "proficiency", proficiency ); |
128 |
| - assign( jo, "bonus", bonus ); |
129 |
| - assign( jo, "penalty", penalty ); |
130 |
| - if( !jo.has_string( "id" ) ) { |
131 |
| - id = static_cast<std::string>( proficiency ); |
132 |
| - } |
| 125 | + mandatory( jo, false, "proficiency", proficiency ); |
| 126 | + optional( jo, false, "id", id, proficiency.str() ); |
| 127 | + optional( jo, false, "bonus", bonus ); |
| 128 | + optional( jo, false, "penalty", penalty ); |
133 | 129 | }
|
134 | 130 | }
|
135 | 131 |
|
@@ -304,41 +300,14 @@ void weakpoint_effect::apply_to( Creature &target, int total_damage,
|
304 | 300 |
|
305 | 301 | void weakpoint_effect::load( const JsonObject &jo )
|
306 | 302 | {
|
307 |
| - if( jo.has_string( "effect" ) ) { |
308 |
| - assign( jo, "effect", effect ); |
309 |
| - } |
310 |
| - if( jo.has_array( "effect_on_conditions" ) ) { |
311 |
| - assign( jo, "effect_on_conditions", effect_on_conditions ); |
312 |
| - } |
313 |
| - if( jo.has_float( "chance" ) ) { |
314 |
| - assign( jo, "chance", chance, false, 0.0f, 100.0f ); |
315 |
| - } |
316 |
| - if( jo.has_bool( "permanent" ) ) { |
317 |
| - assign( jo, "permanent", permanent ); |
318 |
| - } |
319 |
| - if( jo.has_string( "message" ) ) { |
320 |
| - assign( jo, "message", message ); |
321 |
| - } |
322 |
| - |
323 |
| - // Support shorthand for a single value. |
324 |
| - if( jo.has_int( "duration" ) ) { |
325 |
| - int i = jo.get_int( "duration", 0 ); |
326 |
| - duration = {i, i}; |
327 |
| - } else if( jo.has_array( "duration" ) ) { |
328 |
| - assign( jo, "duration", duration ); |
329 |
| - } |
330 |
| - if( jo.has_int( "intensity" ) ) { |
331 |
| - int i = jo.get_int( "intensity", 0 ); |
332 |
| - intensity = {i, i}; |
333 |
| - } else if( jo.has_array( "intensity" ) ) { |
334 |
| - assign( jo, "intensity", intensity ); |
335 |
| - } |
336 |
| - if( jo.has_float( "damage_required" ) ) { |
337 |
| - float f = jo.get_float( "damage_required", 0.0f ); |
338 |
| - damage_required = {f, f}; |
339 |
| - } else if( jo.has_array( "damage_required" ) ) { |
340 |
| - assign( jo, "damage_required", damage_required ); |
341 |
| - } |
| 303 | + optional( jo, false, "effect", effect ); |
| 304 | + optional( jo, false, "effect_on_conditions", effect_on_conditions ); |
| 305 | + optional( jo, false, "chance", chance, numeric_bound_reader{0.f, 100.f} ); |
| 306 | + optional( jo, false, "permanent", permanent ); |
| 307 | + optional( jo, false, "message", message ); |
| 308 | + optional( jo, false, "duration", duration, pair_reader<int> {} ); |
| 309 | + optional( jo, false, "intensity", intensity, pair_reader<int> {} ); |
| 310 | + optional( jo, false, "damage_required", damage_required, pair_reader<float> {} ); |
342 | 311 | }
|
343 | 312 |
|
344 | 313 | weakpoint_attack::weakpoint_attack() :
|
@@ -419,52 +388,32 @@ weakpoint::weakpoint() : coverage_mult( 1.0f ), difficulty( -100.0f )
|
419 | 388 |
|
420 | 389 | void weakpoint::load( const JsonObject &jo )
|
421 | 390 | {
|
422 |
| - assign( jo, "id", id ); |
423 |
| - assign( jo, "name", name ); |
424 |
| - assign( jo, "coverage", coverage, false, 0.0f, 100.0f ); |
425 |
| - if( jo.has_bool( "is_good" ) ) { |
426 |
| - assign( jo, "is_good", is_good ); |
427 |
| - } |
428 |
| - if( is_good && jo.has_bool( "is_head" ) ) { |
429 |
| - assign( jo, "is_head", is_head ); |
430 |
| - } |
431 |
| - if( jo.has_object( "armor_mult" ) ) { |
432 |
| - armor_mult = load_damage_map( jo.get_object( "armor_mult" ) ); |
433 |
| - } |
434 |
| - if( jo.has_object( "armor_penalty" ) ) { |
435 |
| - armor_penalty = load_damage_map( jo.get_object( "armor_penalty" ) ); |
436 |
| - } |
437 |
| - if( jo.has_object( "damage_mult" ) ) { |
438 |
| - damage_mult = load_damage_map( jo.get_object( "damage_mult" ) ); |
439 |
| - } |
440 |
| - if( jo.has_object( "crit_mult" ) ) { |
441 |
| - crit_mult = load_damage_map( jo.get_object( "crit_mult" ) ); |
| 391 | + if( jo.has_member( "id" ) ) { |
| 392 | + mandatory( jo, false, "id", id ); |
442 | 393 | } else {
|
443 |
| - // Default to damage multiplier, if crit multipler is not specified. |
444 |
| - crit_mult = damage_mult; |
| 394 | + mandatory( jo, false, "name", id ); |
445 | 395 | }
|
| 396 | + optional( jo, false, "name", name ); |
| 397 | + optional( jo, false, "coverage", coverage, numeric_bound_reader{0.0f, 100.0f}, 100.f ); |
| 398 | + optional( jo, false, "is_good", is_good, true ); |
| 399 | + // ??? |
| 400 | + if( is_good ) { |
| 401 | + optional( jo, false, "is_head", is_head, false ); |
| 402 | + } |
| 403 | + optional( jo, false, "armor_mult", armor_mult, generic_map_reader<damage_type_id, float> {} ); |
| 404 | + optional( jo, false, "armor_penalty", armor_penalty, generic_map_reader<damage_type_id, float> {} ); |
| 405 | + optional( jo, false, "damage_mult", damage_mult, generic_map_reader<damage_type_id, float> {} ); |
| 406 | + optional( jo, false, "crit_mult", crit_mult, generic_map_reader<damage_type_id, float> {}, |
| 407 | + damage_mult ); |
| 408 | + |
| 409 | + // FIXME: read conditions with optional |
446 | 410 | if( jo.has_member( "condition" ) ) {
|
447 | 411 | read_condition( jo, "condition", condition, false );
|
448 | 412 | has_condition = true;
|
449 | 413 | }
|
450 |
| - if( jo.has_array( "effects" ) ) { |
451 |
| - for( const JsonObject effect_jo : jo.get_array( "effects" ) ) { |
452 |
| - weakpoint_effect effect; |
453 |
| - effect.load( effect_jo ); |
454 |
| - effects.push_back( std::move( effect ) ); |
455 |
| - } |
456 |
| - } |
457 |
| - if( jo.has_object( "coverage_mult" ) ) { |
458 |
| - coverage_mult.load( jo.get_object( "coverage_mult" ) ); |
459 |
| - } |
460 |
| - if( jo.has_object( "difficulty" ) ) { |
461 |
| - difficulty.load( jo.get_object( "difficulty" ) ); |
462 |
| - } |
463 |
| - |
464 |
| - // Set the ID to the name, if not provided. |
465 |
| - if( !jo.has_string( "id" ) ) { |
466 |
| - assign( jo, "name", id ); |
467 |
| - } |
| 414 | + optional( jo, false, "effects", effects ); |
| 415 | + optional( jo, false, "coverage_mult", coverage_mult, weakpoint_difficulty( 1.f ) ); |
| 416 | + optional( jo, false, "difficulty", difficulty, weakpoint_difficulty( -100.f ) ); |
468 | 417 | }
|
469 | 418 |
|
470 | 419 | void weakpoint::check() const
|
|
0 commit comments