Skip to content

Commit

Permalink
Merge pull request #124 from AtomicFox556/cherrypick-fix2
Browse files Browse the repository at this point in the history
Make start date and Cataclysm date adjustable
  • Loading branch information
AtomicFox556 authored Aug 21, 2023
2 parents fa3844d + 598a401 commit e7ac3c0
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 452 deletions.
18 changes: 12 additions & 6 deletions data/json/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@
"start_name": "Outside Town",
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ],
"flags": [ "LONE_START" ],
"custom_initial_date": { "season": "winter" },
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 1, "season": "winter", "year": 1 },
"add_professions": true,
"professions": [
"sheltered_survivor",
Expand Down Expand Up @@ -555,7 +556,8 @@
],
"start_name": "Outside Town",
"flags": [ "LONE_START" ],
"custom_initial_date": { "season": "summer", "year": 2 },
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 1, "season": "summer", "year": 2 },
"add_professions": true,
"professions": [
"sheltered_survivor",
Expand All @@ -577,7 +579,8 @@
"description": "It's been a year since the apocalypse, and winter is fast approaching. You and your company have managed to gather up enough supplies to finally settle down somewhere, away from the death and destruction. Life has been hard for you, but in your heart you still hold a vision of a bright future lying ahead.",
"start_name": "Old Evac Shelter",
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ],
"custom_initial_date": { "season": "autumn", "year": 2 },
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 1, "season": "autumn", "year": 2 },
"add_professions": true,
"professions": [ "sheltered_survivor", "sheltered_militia", "winter_scavenger", "winter_army" ],
"requirement": "achievement_survive_91_days",
Expand All @@ -593,7 +596,8 @@
"allowed_locs": [ "sloc_lmoe_empty", "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ],
"start_name": "Enclosed Shelter",
"flags": [ "LONE_START" ],
"custom_initial_date": { "season": "winter" },
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 1, "season": "winter", "year": 1 },
"professions": [ "sheltered_militia", "sheltered_survivor", "unemployed" ]
},
{
Expand Down Expand Up @@ -666,7 +670,8 @@
"requirement": "achievement_reach_mi-Go_encampment",
"reveal_locale": false,
"flags": [ "LONE_START", "CHALLENGE" ],
"custom_initial_date": { "season": "winter" }
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 1, "season": "winter", "year": 1 }
},
{
"type": "scenario",
Expand Down Expand Up @@ -1115,7 +1120,8 @@
"description": "You were camping in the wild to let things back home cool off. One night strange noises closed in on you and you were attacked. You managed to get away but can feel things moving in the dark.",
"id": "camp_attack_start",
"points": 0,
"custom_initial_date": { "hour": 1 },
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 1, "day": 61, "season": "spring", "year": 1 },
"start_name": "Wilderness",
"eoc": [ "scenario_surrounded_zombie_heavy" ],
"allowed_locs": [
Expand Down
6 changes: 4 additions & 2 deletions data/mods/Standard_Combat_Tests/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"professions": [ "sct_mid" ],
"map_extra": "mx_sct_mid",
"flags": [ "CITY_START", "LONE_START" ],
"custom_initial_date": { "hour": 8, "day": 45, "season": "summer" }
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 45, "season": "summer", "year": 1 }
},
{
"type": "scenario",
Expand All @@ -50,7 +51,8 @@
"professions": [ "sct_late" ],
"map_extra": "mx_sct_late",
"flags": [ "CITY_START", "LONE_START" ],
"custom_initial_date": { "hour": 8, "day": 45, "season": "autumn" }
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 45, "season": "autumn", "year": 1 }
},
{
"id": "mx_sct_day1",
Expand Down
36 changes: 24 additions & 12 deletions data/mods/TEST_DATA/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
[
{
"type": "scenario",
"id": "test_random_hour",
"name": "Test random hour",
"id": "test_custom_game",
"name": "Test custom game start date",
"points": 0,
"description": "Test starting on random hour.",
"description": "Test starting on custom game start date.",
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ],
"start_name": "Evac Shelter",
"flags": [ "CITY_START" ],
"custom_initial_date": { "hour": -1, "season": "summer" }
"start_of_game": { "hour": 18, "day": 7, "season": "summer", "year": 4 }
},
{
"type": "scenario",
"id": "test_random_day",
"name": "Test random day",
"id": "test_custom_game_invalid",
"name": "Test invalid custom game start date",
"points": 0,
"description": "Test starting on random day.",
"description": "Test starting on custom start date that is before cataclysm start date.",
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ],
"start_name": "Evac Shelter",
"flags": [ "CITY_START" ],
"custom_initial_date": { "day": -1, "season": "summer" }
"start_of_game": { "hour": 3, "day": 8, "season": "spring", "year": -1 }
},
{
"type": "scenario",
"id": "test_random_year",
"name": "Test random year",
"id": "test_custom_cataclysm",
"name": "Test custom cataclysm start date",
"points": 0,
"description": "Test starting on random year.",
"description": "Test starting with custom cataclysm start date.",
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ],
"start_name": "Evac Shelter",
"flags": [ "CITY_START" ],
"custom_initial_date": { "year": -1, "season": "summer" }
"start_of_cataclysm": { "hour": 1, "day": 9, "season": "autumn", "year": 7 }
},
{
"type": "scenario",
"id": "test_custom_both",
"name": "Test custom cataclysm start date and game start date",
"points": 0,
"description": "Test starting with custom cataclysm start date and on custom game start date.",
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ],
"start_name": "Evac Shelter",
"flags": [ "CITY_START" ],
"start_of_cataclysm": { "hour": 6, "day": 4, "season": "winter", "year": 6 },
"start_of_game": { "hour": 13, "day": 19, "season": "autumn", "year": 9 }
}
]
6 changes: 4 additions & 2 deletions data/mods/innawood/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@
"start_name": "Outside Town",
"surround_groups": [ [ "GROUP_BLACK_ROAD", 70.0 ] ],
"flags": [ "LONE_START" ],
"custom_initial_date": { "season": "winter" },
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 1, "season": "winter", "year": 1 },
"professions": [
"svictim",
"naked",
Expand Down Expand Up @@ -301,7 +302,8 @@
"allowed_locs": [ "sloc_field", "sloc_forest", "sloc_desert_island", "sloc_river" ],
"start_name": "Outside Town",
"flags": [ "LONE_START" ],
"custom_initial_date": { "season": "summer", "year": 2 },
"start_of_cataclysm": { "hour": 0, "day": 61, "season": "spring", "year": 1 },
"start_of_game": { "hour": 8, "day": 1, "season": "summer", "year": 2 },
"professions": [
"svictim",
"naked",
Expand Down
42 changes: 42 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,27 @@
{ "input_method": "keyboard_code", "key": "8", "mod": [ "shift" ] }
]
},
{
"type": "keybinding",
"id": "CHANGE_START_OF_CATACLYSM",
"category": "NEW_CHAR_DESCRIPTION",
"name": "Change cataclysm start date",
"bindings": [ { "input_method": "keyboard_char", "key": "%" }, { "input_method": "keyboard_code", "key": "5", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "CHANGE_START_OF_GAME",
"category": "NEW_CHAR_DESCRIPTION",
"name": "Change game start date",
"bindings": [ { "input_method": "keyboard_char", "key": "^" }, { "input_method": "keyboard_code", "key": "6", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "RESET_CALENDAR",
"category": "NEW_CHAR_DESCRIPTION",
"name": "Reset scenario calendar",
"bindings": [ { "input_method": "keyboard_char", "key": "$" }, { "input_method": "keyboard_code", "key": "4", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "CHOOSE_CITY",
Expand Down Expand Up @@ -1584,6 +1605,27 @@
"name": "Toggle sorting order",
"bindings": [ { "input_method": "keyboard_any", "key": "s" } ]
},
{
"type": "keybinding",
"id": "CHANGE_START_OF_CATACLYSM",
"category": "NEW_CHAR_SCENARIOS",
"name": "Change cataclysm start date",
"bindings": [ { "input_method": "keyboard_char", "key": "%" }, { "input_method": "keyboard_code", "key": "5", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "CHANGE_START_OF_GAME",
"category": "NEW_CHAR_SCENARIOS",
"name": "Change game start date",
"bindings": [ { "input_method": "keyboard_char", "key": "^" }, { "input_method": "keyboard_code", "key": "6", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "RESET_CALENDAR",
"category": "NEW_CHAR_SCENARIOS",
"name": "Reset scenario calendar",
"bindings": [ { "input_method": "keyboard_char", "key": "$" }, { "input_method": "keyboard_code", "key": "4", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "SCROLL_SKILL_INFO_UP",
Expand Down
35 changes: 26 additions & 9 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ Use the `Home` key to return to the top.
- [`reveal_locale`](#reveal_locale)
- [`eocs`](#eocs)
- [`missions`](#missions-1)
- [`custom_initial_date`](#custom_initial_date)
- [`start_of_cataclysm`](#start_of_cataclysm)
- [`start_of_game`](#start_of_game)
- [Starting locations](#starting-locations)
- [`name`](#name-3)
- [`terrain`](#terrain)
Expand Down Expand Up @@ -5302,23 +5303,39 @@ A list of eocs that are triggered once for each new character on scenario start.

A list of mission ids that will be started and assigned to the player at the start of the game. Only missions with the ORIGIN_GAME_START origin are allowed. The last mission in the list will be the active mission, if multiple missions are assigned.

## `custom_initial_date`
## `start_of_cataclysm`
(optional, object with optional members "hour", "day", "season" and "year")

Allows customizing start date. If `custom_initial_date` is not set the corresponding values from world options are used instead.
Allows customization of cataclysm start date. If `start_of_cataclysm` is not set the corresponding default values are used instead - `Year 1, Spring, Day 61, 00:00:00`. Can be changed in new character creation screen.

If the start date of the scenario is before the date of cataclysm defined by map settings then the scenario date is moved forwards by one year.
```C++
"start_of_cataclysm": { "hour": 7, "day": 10, "season": "winter", "year": 1 }
```
Identifier | Description
--- | ---
`hour` | (optional, integer) Hour of the day. Default value is 0.
`day` | (optional, integer) Day of the season. Default value is 61.
`season` | (optional, integer) Season of the year. Default value is `spring`.
`year` | (optional, integer) Year. Default value is 1.
## `start_of_game`
(optional, object with optional members "hour", "day", "season" and "year")
Allows customization of game start date. If `start_of_game` is not set the corresponding default values are used instead - `Year 1, Spring, Day 61, 08:00:00`. Can be changed in new character creation screen.
**Attention**: Game start date is automatically adjusted, so it is not before the cataclysm start date.
```C++
"custom_initial_date": { "hour": 3, "day": 10, "season": "winter", "year": 1 }
"start_of_game": { "hour": 8, "day": 16, "season": "winter", "year": 2 }
```

Identifier | Description
--- | ---
`hour` | (optional, integer) Hour of the day for initial date. Default 8. -1 randomizes 0-23.
`day` | (optional, integer) Day of the season for initial date. Default 0. -1 randomizes 0-season length.
`season` | (optional, integer) Season for initial date. Default `SPRING`.
`year` | (optional, integer) Year for initial date. Default 1. -1 randomizes 1-11.
`hour` | (optional, integer) Hour of the day. Default value is 8.
`day` | (optional, integer) Day of the season. Default value is 61.
`season` | (optional, integer) Season of the year. Default value is `spring`.
`year` | (optional, integer) Year. Default value is 1.

# Starting locations

Expand Down
80 changes: 80 additions & 0 deletions src/calendar_ui.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "calendar_ui.h"

#include "string_formatter.h"
#include "string_input_popup.h"
#include "ui.h"
#include "ui_manager.h"

time_point calendar_ui::select_time_point( time_point initial_value, std::string_view title )
{
time_point return_value = initial_value;
auto set_turn = [&]( const int initial, const time_duration & factor, const char *const msg ) {
string_input_popup pop;
const int new_value = pop
.title( msg )
.width( 20 )
.text( std::to_string( initial ) )
.only_digits( true )
.query_int();
if( pop.canceled() ) {
return;
}
const time_duration offset = ( new_value - initial ) * factor;
// Arbitrary maximal value.
const time_point max = calendar::turn_zero + time_duration::from_turns(
std::numeric_limits<int>::max() / 2 );
return_value = std::max( std::min( max, return_value + offset ), calendar::turn_zero );
};

uilist smenu;
static const auto years = []( const time_point & p ) {
return static_cast<int>( ( p - calendar::turn_zero ) / calendar::year_length() );
};
do {
const int iSel = smenu.ret;
smenu.reset();
smenu.title = title;
smenu.text += string_format( "Old date: %1$s\nNew date: %2$s",
colorize( to_string( initial_value ), c_light_red ),
colorize( to_string( return_value ), c_light_cyan ) );
smenu.desc_enabled = true;
smenu.footer_text = string_format( _( "Press <color_light_green>%s</color> when done" ),
input_context( smenu.input_category ).get_desc( "UILIST.QUIT" ) );
smenu.addentry( 0, true, 'y', "%s: %d", _( "year" ), years( return_value ) + 1 );
smenu.addentry( 1, !calendar::eternal_season(), 's', "%s: %d",
_( "season" ), static_cast<int>( season_of_year( return_value ) ) );
smenu.addentry( 2, true, 'd', "%s: %d", _( "day" ), day_of_season<int>( return_value ) + 1 );
smenu.addentry( 3, true, 'h', "%s: %d", _( "hour" ), hour_of_day<int>( return_value ) );
smenu.addentry( 4, true, 'm', "%s: %d", _( "minute" ), minute_of_hour<int>( return_value ) );
smenu.addentry( 5, true, 't', "%s: %d", _( "turn" ),
to_turns<int>( return_value - calendar::turn_zero ) );
smenu.selected = iSel;
smenu.query();

switch( smenu.ret ) {
case 0:
set_turn( years( return_value ) + 1, calendar::year_length(), _( "Set year to?" ) );
break;
case 1:
set_turn( static_cast<int>( season_of_year( return_value ) ), calendar::season_length(),
_( "Set season to? (0 = spring)" ) );
break;
case 2:
set_turn( day_of_season<int>( return_value ) + 1, 1_days, _( "Set days to?" ) );
break;
case 3:
set_turn( hour_of_day<int>( return_value ), 1_hours, _( "Set hour to?" ) );
break;
case 4:
set_turn( minute_of_hour<int>( return_value ), 1_minutes, _( "Set minute to?" ) );
break;
case 5:
set_turn( to_turns<int>( return_value - calendar::turn_zero ), 1_turns,
string_format( _( "Set turn to? (One day is %i turns)" ), to_turns<int>( 1_days ) ).c_str() );
break;
default:
break;
}
} while( smenu.ret != UILIST_CANCEL );
return return_value;
}
20 changes: 20 additions & 0 deletions src/calendar_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#ifndef CATA_SRC_CALENDAR_UI_H
#define CATA_SRC_CALENDAR_UI_H

#include <string>

#include "calendar.h"
#include "translations.h"

namespace calendar_ui
{

/**
* Displays ui element that allows to select and return time point.
*/
time_point select_time_point( time_point initial_value,
std::string_view title = _( "Select time point" ) );
} // namespace calendar_ui

#endif // CATA_SRC_CALENDAR_UI_H
Loading

0 comments on commit e7ac3c0

Please sign in to comment.