Skip to content

Commit

Permalink
Load mission deadlines as a single object
Browse files Browse the repository at this point in the history
  • Loading branch information
RenechCDDA committed Oct 15, 2024
1 parent 4a7d45e commit 5d32994
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
3 changes: 1 addition & 2 deletions data/json/npcs/exodii/exodii_merchant_missions.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@
"fail": { "effect": { "math": [ "faction_trust('exodii')", "-=", "20" ] } },
"origins": [ "ORIGIN_SECONDARY" ],
"has_generic_rewards": false,
"deadline_low": 20,
"deadline_high": 20,
"deadline": [ "20 days", "20 days" ],
"//": "Dialogue for this mission is handled externally.",
"dialogue": {
"describe": ".",
Expand Down
9 changes: 3 additions & 6 deletions data/json/npcs/missiondef.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"value": 150000,
"urgent": true,
"origins": [ "ORIGIN_OPENER_NPC", "ORIGIN_ANY_NPC" ],
"deadline_low": 30,
"deadline_high": 48,
"deadline": [ "30 days", "48 days" ],
"dialogue": {
"describe": "I'm… short… of breath…",
"offer": "I'm asthmatic. I need you to get an inhaler for me…",
Expand Down Expand Up @@ -74,8 +73,7 @@
"urgent": true,
"goal_condition": { "or": [ { "u_has_item": "antibiotics" }, { "u_has_item": "strong_antibiotic" }, { "u_has_item": "panacea" } ] },
"origins": [ "ORIGIN_OPENER_NPC" ],
"deadline_low": 24,
"deadline_high": 48,
"deadline": [ "24 days", "48 days" ],
"dialogue": {
"describe": "This infection is bad, <very> bad…",
"offer": "I'm infected. Badly. I need you to get some good antibiotics for me…",
Expand Down Expand Up @@ -969,8 +967,7 @@
"description": "You have some time left until you can transfer control to your companions, provided you have <color_yellow>established a Basecamp</color> and <color_yellow>have at least 1 NPC companion</color>.",
"difficulty": 0,
"value": 0,
"deadline_low": { "math": [ "time_between_succession" ] },
"deadline_high": { "math": [ "time_between_succession" ] },
"deadline": { "math": [ "time_between_succession" ] },
"invisible_on_complete": true,
"start": {
"effect": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,7 @@
"fail": { "effect": { "math": [ "faction_trust('robofac')", "-=", "20" ] } },
"origins": [ "ORIGIN_SECONDARY" ],
"has_generic_rewards": false,
"deadline_low": 20,
"deadline_high": 20,
"deadline": [ "20 days", "20 days" ],
"//": "Dialogue for this mission is handled externally.",
"dialogue": {
"describe": ".",
Expand Down
3 changes: 1 addition & 2 deletions data/mods/classic_zombies/missiondef.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"type": "mission_definition",
"name": { "str": "Reach Refugee Center" },
"goal": "MGOAL_NULL",
"deadline_low": "1s",
"deadline_high": "1s",
"deadline": "1 seconds",
"difficulty": 0,
"value": 0
}
Expand Down
6 changes: 2 additions & 4 deletions data/mods/innawood/npcs/missiondef.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"value": 150000,
"urgent": true,
"origins": [ "ORIGIN_OPENER_NPC", "ORIGIN_ANY_NPC" ],
"deadline_low": 30,
"deadline_high": 48,
"deadline": [ "30 days", "48 days" ],
"dialogue": {
"describe": "I'm… short… of breath…",
"offer": "I'm asthmatic. I need you to get some kind of medicinal tea for me…",
Expand Down Expand Up @@ -45,8 +44,7 @@
"urgent": true,
"goal_condition": { "u_has_item": "cattail_jelly" },
"origins": [ "ORIGIN_OPENER_NPC" ],
"deadline_low": 24,
"deadline_high": 48,
"deadline": [ "24 days", "48 days" ],
"dialogue": {
"describe": "This infection is bad, <very> bad…",
"offer": "I'm infected. Badly. I need you to get something antiseptic for me…",
Expand Down
20 changes: 20 additions & 0 deletions doc/MISSIONS_JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NPCs can assign missions to the player. There is a fairly regular structure for
"name": "Retrieve Black Box Transcript",
"description": "Decrypt the contents of the black box using a terminal from a nearby lab.",
"goal": "MGOAL_FIND_ITEM",
"deadline": [ "16 hours", "math": [ "time(' 16 h') * 2" ] ],
"difficulty": 2,
"value": 150000,
"item": "black_box_transcript",
Expand All @@ -17,6 +18,14 @@ NPCs can assign missions to the player. There is a fairly regular structure for
"effect": { "u_buy_item": "black_box" },
"assign_mission_target": { "om_terrain": "lab", "reveal_radius": 3 }
},
"urgent": false,
"has_generic_rewards": true,
"item": "pencil",
"item_group": "pencil_box_with_pencil",
"count": 6,
"required_container": "pencil_box",
"remove_container": true;
"empty_container": "can_drink",
"origins": [ "ORIGIN_SECONDARY" ],
"followup": "MISSION_EXPLORE_SARCOPHAGUS",
"dialogue": {
Expand All @@ -43,6 +52,11 @@ it with "MISSION" and to use a fairly descriptive name.
### name
The name is also required, and is displayed to the user in the 'm'issions menu.

### deadline
How long after being assigned this mission before it will automatically fail (if not already completed). Can be a pair of values, in which case a random value between the two is picked. If only a single value is given, always uses that value.

Supports variable objects and math expressions.

### description
Not required, but it's strongly recommended that you summarize all relevant info for the mission.
You may refer to mission end effects of the "u_buy_item" type, as long as they do not come at a
Expand All @@ -61,6 +75,12 @@ cost to the player. See the example below:
```
This system may be expanded in the future to allow referring to other mission parameters and effects.

### name
The name is also required, and is displayed to the user in the 'm'issions menu.

### urgent
If true, the NPC giving this mission will refuse to speak on any other topics besides completing this mission while it is active.

### goal
Must be included, and must be one of these strings:

Expand Down
14 changes: 6 additions & 8 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ mission mission_type::create( const character_id &npc_id ) const

struct dialogue d( get_talker_for( get_player_character() ),
get_talker_for( g->find_npc( npc_id ) ) );
time_duration deadline_low_as_var = deadline_low.evaluate( d );
time_duration deadline_high_as_var = deadline_high.evaluate( d );
if( deadline_low_as_var != 0_turns || deadline_high_as_var != 0_turns ) {
ret.deadline = calendar::turn + rng( deadline_low_as_var, deadline_high_as_var );
time_duration deadline_as_var = deadline.evaluate( d );
if( deadline_as_var != 0_turns ) {
ret.deadline = calendar::turn + deadline_as_var;
} else {
ret.deadline = calendar::turn_zero;
}
Expand Down Expand Up @@ -323,10 +322,9 @@ void mission::assign( avatar &u )
kill_count_to_reach = kills.kill_count( monster_species ) + monster_kill_goal;
}
dialogue d( get_talker_for( u ), get_talker_for( g->find_npc( npc_id ) ) );
time_duration deadline_low = type->deadline_low.evaluate( d );
time_duration deadline_high = type->deadline_high.evaluate( d );
if( deadline_low != 0_turns || deadline_high != 0_turns ) {
deadline = calendar::turn + rng( deadline_low, deadline_high );
time_duration deadline_as_var = type->deadline.evaluate( d );
if( deadline_as_var != 0_turns ) {
deadline = calendar::turn + deadline_as_var;
} else {
deadline = calendar::turn_zero;
}
Expand Down
6 changes: 3 additions & 3 deletions src/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ struct mission_type {
int difficulty = 0;
// Value; determines rewards and such
int value = 0;
// Low and high deadlines
duration_or_var deadline_low;
duration_or_var deadline_high;
// When this mission will auto-fail, if ever. Can be pair of values or just one
// If loaded as a pair, automatically calls rng(min, max) when evaluated, standard stuff
duration_or_var deadline;
// If true, the NPC will press this mission!
bool urgent = false;
// If the mission has generic rewards, so that the completion dialogue knows whether to offer them.
Expand Down
3 changes: 1 addition & 2 deletions src/missiondef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ void mission_type::load( const JsonObject &jo, const std::string &src )
return;
}

deadline_low = get_duration_or_var( jo, "deadline_low", false );
deadline_high = get_duration_or_var( jo, "deadline_high", false );
deadline = get_duration_or_var( jo, "deadline", false );

if( jo.has_member( "followup" ) ) {
follow_up = mission_type_id( jo.get_string( "followup" ) );
Expand Down

0 comments on commit 5d32994

Please sign in to comment.