Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CR] Camp calorie test #68127

Merged
merged 8 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions data/mods/TEST_DATA/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -4754,5 +4754,42 @@
"to_hit": -3,
"melee_damage": { "bash": 1 },
"revert_to": "cheese_hard"
},
{
"type": "COMESTIBLE",
"comestible_type": "FOOD",
"id": "test_100_kcal",
"category": "spare_parts",
"symbol": ",",
"color": "light_gray",
"name": { "str": "TEST rock cheese" },
"description": "A perfectly divided 100kcal portion of pure food.",
"price": 0,
"spoils_in": "360 days",
"calories": 100,
"material": [ "stone" ],
"weight": "100 g",
"volume": "250 ml",
"to_hit": -3,
"melee_damage": { "bash": 1 }
},
{
"type": "COMESTIBLE",
"comestible_type": "FOOD",
"id": "test_200_kcal",
"category": "spare_parts",
"symbol": ",",
"color": "light_gray",
"name": { "str": "TEST 200kcal recipe inherited" },
"description": "Two 100kcal portions of pure food smashed together by a rude survivor. Not a sandwich.",
"price": 0,
"spoils_in": "360 days",
"//": "The purpose of this item is to make sure it gives 200kcal when crafted from 100+100, and not the set calories",
"calories": 185,
"material": [ "stone" ],
"weight": "100 g",
"volume": "250 ml",
"to_hit": -3,
"melee_damage": { "bash": 1 }
}
]
12 changes: 12 additions & 0 deletions data/mods/TEST_DATA/recipes.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,17 @@
"time": "2 h",
"autolearn": true,
"using": [ [ "tailoring_cotton_patchwork", 6 ] ]
},
{
"result": "test_200_kcal",
"type": "recipe",
"activity_level": "NO_EXERCISE",
"category": "CC_FOOD",
"subcategory": "CSC_FOOD_MEAT",
"skill_used": "cooking",
"difficulty": 0,
"time": "2 s",
"autolearn": true,
"components": [ [ [ "test_100_kcal", 2 ] ] ]
}
]
9 changes: 9 additions & 0 deletions tests/eoc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ TEST_CASE( "EOC_transform_radius", "[eoc][timed_event]" )
calendar::turn += 2_seconds;
get_timed_events().process();
check_ter_in_radius( start, eoc_range, t_grass );
CHECK( "Cleaning up avatar's pos and location after successful test…" );
// Bizarre point handling ahead, sanity beware...
// Without this, we have an offset of {-12,-12, 0 } between player's pos and location.
tripoint_abs_omt return_omt;
point_omt_ms return_square;
std::tie( return_omt, return_square ) = project_remain<coords::omt>( start );
g->place_player_overmap( return_omt );
g->place_player( tripoint {start.x() + return_square.x(), start.y() + return_square.y(), 0} );
Maleclypse marked this conversation as resolved.
Show resolved Hide resolved
REQUIRE( get_map().inbounds( start ) );
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
}

TEST_CASE( "EOC_transform_line", "[eoc][timed_event]" )
Expand Down
60 changes: 60 additions & 0 deletions tests/faction_camp_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <cstddef>
#include <iosfwd>
#include <utility>
#include <vector>

#include "basecamp.h"
#include "cata_catch.h"
#include "clzones.h"
#include "coordinates.h"
#include "faction.h"
#include "map.h"
#include "map_helpers.h"
#include "overmap.h"
#include "overmapbuffer.h"
#include "player_helpers.h"

static const zone_type_id zone_type_CAMP_FOOD( "CAMP_FOOD" );
static const zone_type_id zone_type_CAMP_STORAGE( "CAMP_STORAGE" );

TEST_CASE( "camp_calorie_counting", "[camp]" )
{
clear_avatar();
clear_map();
map &m = get_map();
const tripoint zone_loc = m.getabs( tripoint{ 5, 5, 0 } );
Maleclypse marked this conversation as resolved.
Show resolved Hide resolved
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
mapgen_place_zone( zone_loc, zone_loc, zone_type_CAMP_FOOD, your_fac, {},
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
"food" );
mapgen_place_zone( zone_loc, zone_loc, zone_type_CAMP_STORAGE, your_fac, {},
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
"storage" );
faction *camp_faction = get_player_character().get_faction();
const tripoint_abs_omt this_omt = project_to<coords::omt>( m.getglobal( zone_loc ) );
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
m.add_camp( this_omt, "faction_camp" );
std::optional<basecamp *> bcp = overmap_buffer.find_camp( this_omt.xy() );
basecamp *test_camp = *bcp;
WHEN( "a base item is added to larder" ) {
camp_faction->food_supply = 0;
item test_100_kcal( "test_100_kcal" );
m.i_clear( zone_loc );
m.add_item_or_charges( zone_loc, test_100_kcal );
REQUIRE( m.has_items( zone_loc ) );
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
test_camp->distribute_food();
CHECK( camp_faction->food_supply == 100 );
}

WHEN( "an item with inherited components is added to larder" ) {
camp_faction->food_supply = 0;
item test_100_kcal( "test_100_kcal" );
item test_200_kcal( "test_200_kcal" );
item_components made_of;
made_of.add( test_100_kcal );
made_of.add( test_100_kcal );
// Setting the actual components. This will return 185 unless it's actually made up of two 100kcal components!
test_200_kcal.components = made_of;
m.i_clear( zone_loc );
m.add_item_or_charges( zone_loc, test_200_kcal );
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
test_camp->distribute_food();
CHECK( camp_faction->food_supply == 200 );
}
}
// TODO: Tests for: Check calorie display at various activity levels, camp crafting works as expected (consumes inputs, returns outputs+byproducts, costs calories)