Permalink
Browse files

Settlers can get hungry. This is a work in progress - they all die in…

… 8 days.
  • Loading branch information...
thebracket committed Apr 10, 2018
1 parent 2739740 commit 3d979c69bc12b9e60872ceddd3a539c2e6dd1adb
@@ -341,6 +341,7 @@
<ClCompile Include="..\..\src\systems\run_systems.cpp" />
<ClCompile Include="..\..\src\systems\scheduler\calendar_system.cpp" />
<ClCompile Include="..\..\src\systems\scheduler\corpse_system.cpp" />
<ClCompile Include="..\..\src\systems\scheduler\hunger_system.cpp" />
<ClCompile Include="..\..\src\systems\scheduler\initiative_system.cpp" />
<ClCompile Include="..\..\src\systems\scheduler\tick_system.cpp" />
<ClCompile Include="..\..\src\utils\system_log.cpp" />
@@ -387,6 +388,7 @@
<ClInclude Include="..\..\src\components\corpse_settler.hpp" />
<ClInclude Include="..\..\src\components\designated_lumberjack.hpp" />
<ClInclude Include="..\..\src\components\designations.hpp" />
<ClInclude Include="..\..\src\components\hunger_t.hpp" />
<ClInclude Include="..\..\src\components\machinery\entry_trigger.hpp" />
<ClInclude Include="..\..\src\components\explosion_t.hpp" />
<ClInclude Include="..\..\src\components\falling.hpp" />
@@ -581,6 +583,7 @@
<ClInclude Include="..\..\src\systems\run_systems.hpp" />
<ClInclude Include="..\..\src\systems\scheduler\calendar_system.hpp" />
<ClInclude Include="..\..\src\systems\scheduler\corpse_system.hpp" />
<ClInclude Include="..\..\src\systems\scheduler\hunger_system.hpp" />
<ClInclude Include="..\..\src\systems\scheduler\initiative_system.hpp" />
<ClInclude Include="..\..\src\systems\scheduler\tick_system.hpp" />
<ClInclude Include="..\..\src\utils\system_log.hpp" />
@@ -497,6 +497,9 @@
<ClCompile Include="..\..\src\systems\gui\circuit_graph.cpp">
<Filter>Source Files\systems\gui</Filter>
</ClCompile>
<ClCompile Include="..\..\src\systems\scheduler\hunger_system.cpp">
<Filter>Source Files\systems\scheduler</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\components\calendar.hpp">
@@ -1216,5 +1219,11 @@
<ClInclude Include="..\..\src\components\buildings\construct_provides_support.hpp">
<Filter>Header Files\components\buildings</Filter>
</ClInclude>
<ClInclude Include="..\..\src\components\hunger_t.hpp">
<Filter>Header Files\components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\systems\scheduler\hunger_system.hpp">
<Filter>Header Files\systems\scheduler</Filter>
</ClInclude>
</ItemGroup>
</Project>
@@ -2,7 +2,7 @@
#include <string>
constexpr int SAVE_VERSION = 11;
constexpr int SAVE_VERSION = 12;
std::string get_save_path();
bool exists(const std::string &filename) noexcept;
@@ -110,6 +110,7 @@
#include "machinery/oscillator_t.hpp"
#include "machinery/node_graph_position.hpp"
#include "buildings/construct_provides_support.hpp"
#include "hunger_t.hpp"
namespace bengine {
template<class ... Components>
@@ -131,7 +132,8 @@ namespace bengine {
item_food_t, item_hide_t, item_leather_t, item_melee_t, item_ranged_t, item_seed_t, item_skull_t, item_spice_t,
item_topsoil_t, item_t, item_carried_t, item_creator_t, item_quality_t, item_stored_t, item_wear_t, designated_miner_t,
mining_designations_t, ai_tag_work_stockpiles_t, item_food_prepared_t, flying_t, ai_tag_work_deconstruct, sends_signal_t,
signal_processor_t, float_gauge_t, pressure_plate_t, proximity_sensor_t, oscillator_t, node_graph_position_t, construct_support_t
signal_processor_t, float_gauge_t, pressure_plate_t, proximity_sensor_t, oscillator_t, node_graph_position_t, construct_support_t,
hunger_t
>;
}
}
@@ -0,0 +1,7 @@
#pragma once
struct hunger_t {
int hunger_clock = 24 * 60; // 24 hours in minutes
bool is_hungry = false;
bool is_starving = false;
};
@@ -401,6 +401,12 @@ void serialize(Archive & archive, health_t &h)
archive(h.max_hitpoints, h.current_hitpoints, h.unconscious, h.blind, h.immobile, h.slow, h.no_grasp, h.parts, h.stunned_counter); // serialize things by passing them to the archive
}
template<class Archive>
void serialize(Archive & archive, hunger_t &h)
{
archive(h.hunger_clock); // serialize things by passing them to the archive
}
template<class Archive>
void serialize(Archive & archive, initiative_t &i)
{
@@ -263,7 +263,8 @@ void create_settler(planet_t &planet, const int x, const int y, const int z, ben
->assign(viewshed_t{ 8, false })
->assign(initiative_t{})
->assign(ai_settler_new_arrival_t{})
->assign(sleep_clock_t{});
->assign(sleep_clock_t{})
->assign(hunger_t{});
// Create clothing items
//std::cout << settler->id << "\n";
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "ai_status_effects.hpp"
#include "systems/damage/damage_system.hpp"
namespace systems {
namespace ai_status_effects {
@@ -18,6 +19,12 @@ namespace systems {
--health.stunned_counter;
delete_component<ai_tag_my_turn_t>(e.id);
}
const auto hunger = e.component<hunger_t>();
if (hunger && hunger->is_starving)
{
damage_system::inflict_damage(damage_system::inflict_damage_message{e.id, 1, "Starvation"});
}
});
}
}
@@ -5,7 +5,7 @@
namespace systems {
namespace damage_system {
struct inflict_damage_message {
inflict_damage_message() {}
inflict_damage_message() = default;
inflict_damage_message(const int target, const int amount, const std::string &type) : victim(target), damage_amount(amount), damage_type(type) {}
int victim;
@@ -286,10 +286,10 @@ namespace systems {
sender.active = false;
for (const auto &id : view.visible_entities)
{
const auto e = entity(id);
if (e)
const auto detected_e = entity(id);
if (detected_e)
{
if (e->component<settler_ai_t>() || e->component<grazer_ai>() || e->component<sentient_ai>()) sender.active = true;
if (detected_e->component<settler_ai_t>() || detected_e->component<grazer_ai>() || detected_e->component<sentient_ai>()) sender.active = true;
}
}
}
@@ -88,6 +88,7 @@
#include "ai/settler/ai_work_stockpile.hpp"
#include "ai/settler/ai_deconstruct.hpp"
#include "gui/building_info.hpp"
#include "scheduler/hunger_system.hpp"
namespace systems {
constexpr int CAMERA_SYSTEM = 1;
@@ -171,6 +172,7 @@ namespace systems {
constexpr int AI_STOCKPILE_SYSTEM = 79;
constexpr int AI_DECONSTRUCT_SYSTEM = 80;
constexpr int BUILDING_INFO_SYS = 81;
constexpr int HUNGER_SYSTEM = 82;
boost::container::flat_map<int, std::pair<int, std::vector<float>>> run_time;
boost::container::flat_map<int, std::string> system_names;
@@ -275,6 +277,7 @@ namespace systems {
system_names[AI_STOCKPILE_SYSTEM] = "AI Stockpiling";
system_names[AI_DECONSTRUCT_SYSTEM] = "Deconstruction";
system_names[BUILDING_INFO_SYS] = "Building Info";
system_names[HUNGER_SYSTEM] = "Hunger System";
game_master_mode = PLAY;
}
@@ -318,6 +321,7 @@ namespace systems {
fluids::copy_to_gpu();
logging::age_log();
run_system(calendarsys::run, duration_ms, CALENDAR_SYSTEM);
run_system(hunger_system::run, duration_ms, HUNGER_SYSTEM);
if (hour_elapsed) run_system(settler_spawner::run, duration_ms, SETTLER_SPAWNER_SYSTEM);
if (day_elapsed || wildlife_population::first_run) run_system(wildlife_population::run, duration_ms, WILDLIFE_POPULATION_SYSTEM);
run_system(fluids::run, duration_ms, FLUID_SYSTEM);
@@ -0,0 +1,17 @@
#include "hunger_system.hpp"
#include "components/hunger_t.hpp"
#include "global_assets/game_ecs.hpp"
namespace systems {
namespace hunger_system {
void run(const double &duration_ms)
{
bengine::each<hunger_t>([] (bengine::entity_t &e, hunger_t &h)
{
--h.hunger_clock;
if (h.hunger_clock < 60) h.is_hungry = true;
if (h.hunger_clock < -(24 * 60 * 3)) h.is_starving = true;
});
}
}
}
@@ -0,0 +1,7 @@
#pragma once
namespace systems {
namespace hunger_system {
void run(const double &duration_ms);
}
}
@@ -84,7 +84,7 @@ buildings["proximity_sensor"] = {
description = "An electronic proximity sensor that triggers if movement occurs nearby.",
components = { { item="mechanism", qty=1 }, { item="circuit", qty=1 } },
skill = { name="Construction", difficulty=12 },
provides = { proximity_sensor={energy_cost=0} },
provides = { proximity_sensor={energy_cost=10} },
render_rex = "pressureplate.xp",
vox = voxelId("proximity_sensor")
};

0 comments on commit 3d979c6

Please sign in to comment.