2022-01-11 09:24:20 -05:00
|
|
|
mod ai;
|
2021-12-17 16:35:30 -05:00
|
|
|
pub mod camera;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod components;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod damage_system;
|
2021-11-04 10:44:52 -04:00
|
|
|
mod game_log;
|
2022-01-03 15:21:12 -05:00
|
|
|
mod gamesystem;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod gui;
|
2021-11-18 10:28:49 -05:00
|
|
|
mod hunger_system;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod inventory_system;
|
2022-01-10 10:21:19 -05:00
|
|
|
mod lighting_system;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod map;
|
2021-12-01 10:47:41 -05:00
|
|
|
pub mod map_builders;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod map_indexing_system;
|
|
|
|
mod melee_combat_system;
|
2021-11-16 11:33:58 -05:00
|
|
|
mod particle_system;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod player;
|
2021-11-12 14:06:55 -05:00
|
|
|
pub mod random_table;
|
2021-12-23 11:00:37 -05:00
|
|
|
pub mod raws;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod rect;
|
2021-11-29 14:59:46 -05:00
|
|
|
mod rex_assets;
|
2021-11-08 13:58:40 -05:00
|
|
|
pub mod saveload_system;
|
2022-01-12 10:45:13 -05:00
|
|
|
mod spatial;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod spawner;
|
2021-11-29 16:00:07 -05:00
|
|
|
mod trigger_system;
|
2021-10-25 15:26:39 -04:00
|
|
|
mod visibility_system;
|
2021-11-03 16:04:36 -04:00
|
|
|
|
2021-12-23 11:38:37 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
2021-12-24 10:20:29 -05:00
|
|
|
use ::rltk::{GameState, Point, RandomNumberGenerator, Rltk};
|
|
|
|
use ::specs::prelude::*;
|
|
|
|
use ::specs::saveload::{SimpleMarker, SimpleMarkerAllocator};
|
2021-11-05 14:32:14 -04:00
|
|
|
use components::*;
|
2021-10-29 15:15:22 -04:00
|
|
|
use damage_system::DamageSystem;
|
2021-11-04 10:44:52 -04:00
|
|
|
pub use game_log::GameLog;
|
2022-01-07 09:39:47 -05:00
|
|
|
use gui::{show_cheat_mode, CheatMenuResult};
|
2022-01-05 11:46:39 -05:00
|
|
|
use hunger_system::HungerSystem;
|
2021-12-01 14:45:27 -05:00
|
|
|
use inventory_system::{ItemCollectionSystem, ItemDropSystem, ItemRemoveSystem, ItemUseSystem};
|
2022-01-10 10:21:19 -05:00
|
|
|
use lighting_system::LightingSystem;
|
2021-11-03 16:04:36 -04:00
|
|
|
pub use map::*;
|
|
|
|
use map_indexing_system::MapIndexingSystem;
|
|
|
|
use melee_combat_system::MeleeCombatSystem;
|
2022-01-05 11:46:39 -05:00
|
|
|
use particle_system::ParticleSpawnSystem;
|
2021-11-03 16:04:36 -04:00
|
|
|
use player::*;
|
|
|
|
pub use rect::Rect;
|
2022-01-05 11:46:39 -05:00
|
|
|
use trigger_system::TriggerSystem;
|
2021-11-03 16:04:36 -04:00
|
|
|
use visibility_system::VisibilitySystem;
|
2021-10-25 15:26:39 -04:00
|
|
|
|
2021-11-04 11:27:44 -04:00
|
|
|
/// Cut down on the amount of syntax to register components
|
|
|
|
macro_rules! register {
|
|
|
|
// $gs is needed to get the scope at the usage point
|
|
|
|
// $Type is the Component type that is being registered
|
2021-11-04 11:38:13 -04:00
|
|
|
($gs: ident <- $( $Type: ty ),*,) => {
|
2021-11-04 11:27:44 -04:00
|
|
|
$(
|
|
|
|
$gs.ecs.register::<$Type>();
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-04 12:12:08 -05:00
|
|
|
const SHOW_MAPGEN_VISUALIZER: bool = false;
|
2021-12-01 14:45:27 -05:00
|
|
|
|
2021-10-26 15:43:59 -04:00
|
|
|
#[derive(PartialEq, Copy, Clone)]
|
|
|
|
pub enum RunState {
|
2021-10-29 15:15:22 -04:00
|
|
|
AwaitingInput,
|
|
|
|
PreRun,
|
2022-01-11 10:01:37 -05:00
|
|
|
Ticking,
|
2021-11-03 15:11:19 -04:00
|
|
|
ShowInventory,
|
2021-11-04 09:40:58 -04:00
|
|
|
ShowDropItem,
|
2021-11-08 10:22:11 -05:00
|
|
|
ShowTargeting {
|
|
|
|
range: i32,
|
|
|
|
item: Entity,
|
|
|
|
},
|
|
|
|
MainMenu {
|
|
|
|
menu_selection: gui::MainMenuSelection,
|
|
|
|
},
|
2021-11-08 13:58:40 -05:00
|
|
|
SaveGame,
|
2021-11-09 15:50:42 -05:00
|
|
|
NextLevel,
|
2022-01-06 09:13:40 -05:00
|
|
|
PreviousLevel,
|
2021-11-15 11:32:09 -05:00
|
|
|
ShowRemoveItem,
|
2021-11-15 13:27:40 -05:00
|
|
|
GameOver,
|
2021-11-29 14:39:15 -05:00
|
|
|
MagicMapReveal {
|
|
|
|
row: i32,
|
|
|
|
},
|
2021-12-01 14:45:27 -05:00
|
|
|
MapGeneration,
|
2022-01-07 09:39:47 -05:00
|
|
|
ShowCheatMenu,
|
2021-10-26 15:43:59 -04:00
|
|
|
}
|
|
|
|
|
2021-10-22 10:05:06 -04:00
|
|
|
pub struct State {
|
2021-10-26 15:43:59 -04:00
|
|
|
pub ecs: World,
|
2021-12-01 14:45:27 -05:00
|
|
|
mapgen_next_state: Option<RunState>,
|
|
|
|
mapgen_history: Vec<Map>,
|
|
|
|
mapgen_index: usize,
|
|
|
|
mapgen_timer: f32,
|
2021-10-21 12:54:39 -04:00
|
|
|
}
|
2021-10-20 12:01:15 -04:00
|
|
|
|
2021-10-25 14:23:19 -04:00
|
|
|
impl State {
|
2021-11-04 15:06:04 -04:00
|
|
|
fn new() -> Self {
|
2021-12-01 14:45:27 -05:00
|
|
|
State {
|
|
|
|
ecs: World::new(),
|
|
|
|
mapgen_next_state: Some(RunState::MainMenu {
|
|
|
|
menu_selection: gui::MainMenuSelection::NewGame,
|
|
|
|
}),
|
|
|
|
mapgen_index: 0,
|
|
|
|
mapgen_history: Vec::new(),
|
|
|
|
mapgen_timer: 0.0,
|
|
|
|
}
|
2021-11-04 15:06:04 -04:00
|
|
|
}
|
|
|
|
|
2021-10-25 14:23:19 -04:00
|
|
|
fn run_systems(&mut self) {
|
2022-01-11 10:01:37 -05:00
|
|
|
let mut mapindex = MapIndexingSystem {};
|
|
|
|
mapindex.run_now(&self.ecs);
|
|
|
|
|
2021-10-25 15:26:39 -04:00
|
|
|
let mut vis = VisibilitySystem {};
|
|
|
|
vis.run_now(&self.ecs);
|
|
|
|
|
2022-01-11 10:01:37 -05:00
|
|
|
let mut initiative = ai::InitiativeSystem {};
|
|
|
|
initiative.run_now(&self.ecs);
|
|
|
|
|
2022-01-11 10:30:32 -05:00
|
|
|
let mut turnstatus = ai::TurnStatusSystem {};
|
|
|
|
turnstatus.run_now(&self.ecs);
|
|
|
|
|
|
|
|
let mut quipper = ai::QuipSystem {};
|
|
|
|
quipper.run_now(&self.ecs);
|
|
|
|
|
2022-01-11 14:16:23 -05:00
|
|
|
let mut adjacent = ai::AdjacentAI {};
|
|
|
|
adjacent.run_now(&self.ecs);
|
2021-10-26 15:43:59 -04:00
|
|
|
|
2022-01-11 14:16:23 -05:00
|
|
|
let mut visible = ai::VisibleAI {};
|
|
|
|
visible.run_now(&self.ecs);
|
2022-01-05 11:46:39 -05:00
|
|
|
|
2022-01-11 14:16:23 -05:00
|
|
|
let mut approach = ai::ApproachAI {};
|
|
|
|
approach.run_now(&self.ecs);
|
|
|
|
|
|
|
|
let mut flee = ai::FleeAI {};
|
|
|
|
flee.run_now(&self.ecs);
|
|
|
|
|
2022-01-11 15:35:59 -05:00
|
|
|
let mut chase = ai::ChaseAI {};
|
|
|
|
chase.run_now(&self.ecs);
|
|
|
|
|
2022-01-11 14:16:23 -05:00
|
|
|
let mut defaultmove = ai::DefaultMoveAI {};
|
|
|
|
defaultmove.run_now(&self.ecs);
|
2022-01-03 09:54:32 -05:00
|
|
|
|
2022-01-05 11:46:39 -05:00
|
|
|
let mut triggers = TriggerSystem {};
|
|
|
|
triggers.run_now(&self.ecs);
|
|
|
|
|
2021-10-29 15:15:22 -04:00
|
|
|
let mut melee = MeleeCombatSystem {};
|
|
|
|
melee.run_now(&self.ecs);
|
|
|
|
|
|
|
|
let mut damage = DamageSystem {};
|
|
|
|
damage.run_now(&self.ecs);
|
|
|
|
|
2021-11-03 15:11:19 -04:00
|
|
|
let mut pickup = ItemCollectionSystem {};
|
|
|
|
pickup.run_now(&self.ecs);
|
|
|
|
|
2021-11-04 15:06:04 -04:00
|
|
|
let mut items = ItemUseSystem {};
|
|
|
|
items.run_now(&self.ecs);
|
2021-11-03 15:59:23 -04:00
|
|
|
|
2021-11-04 09:40:58 -04:00
|
|
|
let mut drop_items = ItemDropSystem {};
|
|
|
|
drop_items.run_now(&self.ecs);
|
|
|
|
|
2021-11-15 11:32:09 -05:00
|
|
|
let mut item_remove = ItemRemoveSystem {};
|
|
|
|
item_remove.run_now(&self.ecs);
|
|
|
|
|
2022-01-05 11:46:39 -05:00
|
|
|
let mut hunger = HungerSystem {};
|
2021-11-18 10:28:49 -05:00
|
|
|
hunger.run_now(&self.ecs);
|
|
|
|
|
2022-01-05 11:46:39 -05:00
|
|
|
let mut particles = ParticleSpawnSystem {};
|
2021-11-16 11:33:58 -05:00
|
|
|
particles.run_now(&self.ecs);
|
|
|
|
|
2022-01-10 10:21:19 -05:00
|
|
|
let mut lighting = LightingSystem {};
|
|
|
|
lighting.run_now(&self.ecs);
|
|
|
|
|
2021-10-25 14:23:19 -04:00
|
|
|
self.ecs.maintain();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 12:01:15 -04:00
|
|
|
impl GameState for State {
|
|
|
|
fn tick(&mut self, ctx: &mut Rltk) {
|
2021-11-08 10:22:11 -05:00
|
|
|
let mut newrunstate;
|
2021-11-04 10:00:42 -04:00
|
|
|
{
|
2021-11-08 10:22:11 -05:00
|
|
|
let runstate = self.ecs.fetch::<RunState>();
|
|
|
|
newrunstate = *runstate;
|
|
|
|
}
|
2021-11-04 10:00:42 -04:00
|
|
|
|
2021-11-08 10:22:11 -05:00
|
|
|
ctx.cls();
|
2021-11-16 11:33:58 -05:00
|
|
|
particle_system::cull_dead_particles(&mut self.ecs, ctx);
|
2021-11-08 10:22:11 -05:00
|
|
|
|
|
|
|
match newrunstate {
|
2021-11-09 10:38:56 -05:00
|
|
|
RunState::MainMenu { .. } => {}
|
2021-11-29 16:00:07 -05:00
|
|
|
RunState::GameOver { .. } => {}
|
2021-11-08 10:22:11 -05:00
|
|
|
_ => {
|
2021-12-17 16:35:30 -05:00
|
|
|
camera::render_camera(&self.ecs, ctx);
|
|
|
|
gui::draw_ui(&self.ecs, ctx);
|
2021-11-04 10:00:42 -04:00
|
|
|
}
|
2021-10-29 15:15:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
match newrunstate {
|
2021-12-01 14:45:27 -05:00
|
|
|
RunState::MapGeneration => {
|
|
|
|
if !SHOW_MAPGEN_VISUALIZER {
|
|
|
|
newrunstate = self.mapgen_next_state.unwrap();
|
|
|
|
}
|
|
|
|
ctx.cls();
|
2021-12-17 16:54:36 -05:00
|
|
|
if self.mapgen_index < self.mapgen_history.len() {
|
|
|
|
camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);
|
|
|
|
}
|
2021-12-01 14:45:27 -05:00
|
|
|
|
|
|
|
self.mapgen_timer += ctx.frame_time_ms;
|
|
|
|
if self.mapgen_timer > 300.0 {
|
|
|
|
self.mapgen_timer = 0.0;
|
|
|
|
self.mapgen_index += 1;
|
|
|
|
if self.mapgen_index >= self.mapgen_history.len() {
|
|
|
|
newrunstate = self.mapgen_next_state.unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-29 15:15:22 -04:00
|
|
|
RunState::PreRun => {
|
|
|
|
self.run_systems();
|
2021-11-03 15:59:23 -04:00
|
|
|
self.ecs.maintain();
|
2021-10-29 15:15:22 -04:00
|
|
|
newrunstate = RunState::AwaitingInput;
|
|
|
|
}
|
|
|
|
RunState::AwaitingInput => {
|
|
|
|
newrunstate = player_input(self, ctx);
|
|
|
|
}
|
2022-01-11 10:01:37 -05:00
|
|
|
RunState::Ticking => {
|
2022-01-11 15:35:59 -05:00
|
|
|
while newrunstate == RunState::Ticking {
|
|
|
|
self.run_systems();
|
|
|
|
self.ecs.maintain();
|
|
|
|
|
|
|
|
newrunstate = match *self.ecs.fetch::<RunState>() {
|
|
|
|
RunState::AwaitingInput => RunState::AwaitingInput,
|
|
|
|
RunState::MagicMapReveal { .. } => RunState::MagicMapReveal { row: 0 },
|
|
|
|
_ => RunState::Ticking,
|
|
|
|
};
|
|
|
|
}
|
2021-10-29 15:15:22 -04:00
|
|
|
}
|
2021-11-03 15:11:19 -04:00
|
|
|
RunState::ShowInventory => {
|
2021-11-03 15:59:23 -04:00
|
|
|
let result = gui::show_inventory(self, ctx);
|
|
|
|
match result.0 {
|
|
|
|
gui::ItemMenuResult::Cancel => newrunstate = RunState::AwaitingInput,
|
|
|
|
gui::ItemMenuResult::NoResponse => {}
|
|
|
|
gui::ItemMenuResult::Selected => {
|
|
|
|
let item_entity = result.1.unwrap();
|
2021-11-05 10:42:44 -04:00
|
|
|
let is_ranged = self.ecs.read_storage::<Ranged>();
|
|
|
|
|
2021-11-19 19:52:15 -05:00
|
|
|
if let Some(is_item_ranged) = is_ranged.get(item_entity) {
|
2021-11-05 10:42:44 -04:00
|
|
|
newrunstate = RunState::ShowTargeting {
|
|
|
|
range: is_item_ranged.range,
|
|
|
|
item: item_entity,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
let mut intent = self.ecs.write_storage::<WantsToUseItem>();
|
|
|
|
intent
|
|
|
|
.insert(
|
|
|
|
*self.ecs.fetch::<Entity>(),
|
|
|
|
WantsToUseItem {
|
|
|
|
item: item_entity,
|
|
|
|
target: None,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.expect("failed to add intent to use item");
|
|
|
|
|
2022-01-11 10:01:37 -05:00
|
|
|
newrunstate = RunState::Ticking;
|
2021-11-05 10:42:44 -04:00
|
|
|
}
|
2021-11-03 15:59:23 -04:00
|
|
|
}
|
2021-11-03 15:11:19 -04:00
|
|
|
}
|
|
|
|
}
|
2021-11-04 09:40:58 -04:00
|
|
|
RunState::ShowDropItem => {
|
|
|
|
let result = gui::drop_item_menu(self, ctx);
|
|
|
|
match result.0 {
|
|
|
|
gui::ItemMenuResult::Cancel => newrunstate = RunState::AwaitingInput,
|
|
|
|
gui::ItemMenuResult::NoResponse => {}
|
|
|
|
gui::ItemMenuResult::Selected => {
|
|
|
|
let item_entity = result.1.unwrap();
|
|
|
|
let mut intent = self.ecs.write_storage::<WantsToDropItem>();
|
|
|
|
intent
|
|
|
|
.insert(
|
|
|
|
*self.ecs.fetch::<Entity>(),
|
|
|
|
WantsToDropItem { item: item_entity },
|
|
|
|
)
|
|
|
|
.expect("failed to add intent to drop item");
|
|
|
|
|
2022-01-11 10:01:37 -05:00
|
|
|
newrunstate = RunState::Ticking;
|
2021-11-04 09:40:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-15 13:55:31 -05:00
|
|
|
RunState::ShowRemoveItem => {
|
|
|
|
let result = gui::remove_item_menu(self, ctx);
|
|
|
|
match result.0 {
|
|
|
|
gui::ItemMenuResult::Cancel => newrunstate = RunState::AwaitingInput,
|
|
|
|
gui::ItemMenuResult::NoResponse => {}
|
|
|
|
gui::ItemMenuResult::Selected => {
|
|
|
|
let item_entity = result.1.unwrap();
|
|
|
|
let mut intent = self.ecs.write_storage::<WantsToRemoveItem>();
|
|
|
|
intent
|
|
|
|
.insert(
|
|
|
|
*self.ecs.fetch::<Entity>(),
|
|
|
|
WantsToRemoveItem { item: item_entity },
|
|
|
|
)
|
|
|
|
.expect("Unable to insert intent to remove item");
|
|
|
|
|
2022-01-11 10:01:37 -05:00
|
|
|
newrunstate = RunState::Ticking;
|
2021-11-15 13:55:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-05 10:42:44 -04:00
|
|
|
RunState::ShowTargeting { range, item } => {
|
|
|
|
let result = gui::ranged_target(self, ctx, range);
|
|
|
|
match result.0 {
|
|
|
|
gui::ItemMenuResult::Cancel => newrunstate = RunState::AwaitingInput,
|
|
|
|
gui::ItemMenuResult::NoResponse => {}
|
|
|
|
gui::ItemMenuResult::Selected => {
|
|
|
|
let mut intent = self.ecs.write_storage::<WantsToUseItem>();
|
|
|
|
|
|
|
|
intent
|
|
|
|
.insert(
|
|
|
|
*self.ecs.fetch::<Entity>(),
|
|
|
|
WantsToUseItem {
|
|
|
|
item,
|
|
|
|
target: result.1,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.expect("failed to add intent to use item");
|
|
|
|
|
2022-01-11 10:01:37 -05:00
|
|
|
newrunstate = RunState::Ticking;
|
2021-11-05 10:42:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-09 10:38:56 -05:00
|
|
|
RunState::MainMenu { .. } => match gui::main_menu(self, ctx) {
|
|
|
|
gui::MainMenuResult::NoSelection { selected } => {
|
|
|
|
newrunstate = RunState::MainMenu {
|
|
|
|
menu_selection: selected,
|
2021-11-08 10:22:11 -05:00
|
|
|
}
|
|
|
|
}
|
2021-11-09 10:38:56 -05:00
|
|
|
gui::MainMenuResult::Selected { selected } => match selected {
|
|
|
|
gui::MainMenuSelection::NewGame => newrunstate = RunState::PreRun,
|
|
|
|
gui::MainMenuSelection::LoadGame => {
|
|
|
|
saveload_system::load_game(&mut self.ecs);
|
|
|
|
newrunstate = RunState::AwaitingInput;
|
|
|
|
saveload_system::delete_save();
|
|
|
|
}
|
|
|
|
gui::MainMenuSelection::Quit => {
|
|
|
|
::std::process::exit(0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-11-15 13:55:31 -05:00
|
|
|
RunState::GameOver => match gui::game_over(ctx) {
|
|
|
|
gui::GameOverResult::NoSelection => {}
|
|
|
|
gui::GameOverResult::QuitToMenu => {
|
|
|
|
self.game_over_cleanup();
|
|
|
|
newrunstate = RunState::MainMenu {
|
|
|
|
menu_selection: gui::MainMenuSelection::NewGame,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
2021-11-08 13:58:40 -05:00
|
|
|
RunState::SaveGame => {
|
|
|
|
saveload_system::save_game(&mut self.ecs);
|
|
|
|
|
|
|
|
newrunstate = RunState::MainMenu {
|
|
|
|
menu_selection: gui::MainMenuSelection::LoadGame,
|
|
|
|
}
|
|
|
|
}
|
2021-11-09 15:50:42 -05:00
|
|
|
RunState::NextLevel => {
|
2022-01-06 09:34:17 -05:00
|
|
|
self.goto_level(1);
|
2021-11-09 15:50:42 -05:00
|
|
|
newrunstate = RunState::PreRun;
|
|
|
|
}
|
2022-01-06 09:13:40 -05:00
|
|
|
RunState::PreviousLevel => {
|
2022-01-06 09:34:17 -05:00
|
|
|
self.goto_level(-1);
|
2022-01-06 09:13:40 -05:00
|
|
|
self.mapgen_next_state = Some(RunState::PreRun);
|
|
|
|
newrunstate = RunState::MapGeneration;
|
|
|
|
}
|
2021-11-29 14:39:15 -05:00
|
|
|
RunState::MagicMapReveal { row } => {
|
|
|
|
let mut map = self.ecs.fetch_mut::<Map>();
|
2021-12-17 16:35:30 -05:00
|
|
|
for x in 0..map.width {
|
2021-11-29 14:39:15 -05:00
|
|
|
let idx = map.xy_idx(x as i32, row);
|
|
|
|
map.revealed_tiles[idx] = true;
|
|
|
|
}
|
|
|
|
|
2021-12-17 16:35:30 -05:00
|
|
|
if row == map.height - 1 {
|
2022-01-11 10:01:37 -05:00
|
|
|
newrunstate = RunState::Ticking;
|
2021-11-29 14:39:15 -05:00
|
|
|
} else {
|
|
|
|
newrunstate = RunState::MagicMapReveal { row: row + 1 };
|
|
|
|
}
|
|
|
|
}
|
2022-01-07 09:39:47 -05:00
|
|
|
RunState::ShowCheatMenu => match show_cheat_mode(self, ctx) {
|
|
|
|
CheatMenuResult::Cancel => newrunstate = RunState::AwaitingInput,
|
|
|
|
CheatMenuResult::NoResponse => {}
|
|
|
|
CheatMenuResult::TeleportToExit => {
|
|
|
|
self.goto_level(1);
|
|
|
|
self.mapgen_next_state = Some(RunState::PreRun);
|
|
|
|
newrunstate = RunState::MapGeneration
|
|
|
|
}
|
|
|
|
},
|
2021-10-29 15:15:22 -04:00
|
|
|
}
|
2021-10-21 14:24:40 -04:00
|
|
|
|
2021-10-29 15:15:22 -04:00
|
|
|
{
|
|
|
|
let mut runwriter = self.ecs.write_resource::<RunState>();
|
|
|
|
*runwriter = newrunstate;
|
2021-10-26 15:43:59 -04:00
|
|
|
}
|
2021-10-21 14:24:40 -04:00
|
|
|
|
2021-10-29 15:15:22 -04:00
|
|
|
damage_system::delete_the_dead(&mut self.ecs);
|
2021-10-21 14:24:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 15:50:42 -05:00
|
|
|
impl State {
|
2022-01-06 09:34:17 -05:00
|
|
|
fn goto_level(&mut self, offset: i32) {
|
|
|
|
freeze_level_entities(&mut self.ecs);
|
2021-11-09 15:50:42 -05:00
|
|
|
|
|
|
|
// Build a new map and place the player
|
2022-01-06 09:34:17 -05:00
|
|
|
let current_depth = self.ecs.fetch::<Map>().depth;
|
|
|
|
self.generate_world_map(current_depth + offset, offset);
|
2022-01-06 09:13:40 -05:00
|
|
|
|
|
|
|
// Notify the player
|
|
|
|
let mut gamelog = self.ecs.fetch_mut::<GameLog>();
|
2022-01-06 09:34:17 -05:00
|
|
|
gamelog.append("You change level.");
|
2022-01-06 09:13:40 -05:00
|
|
|
}
|
|
|
|
|
2021-11-15 13:27:40 -05:00
|
|
|
fn game_over_cleanup(&mut self) {
|
|
|
|
// Delete everything
|
|
|
|
let mut to_delete = Vec::new();
|
|
|
|
for e in self.ecs.entities().join() {
|
|
|
|
to_delete.push(e);
|
|
|
|
}
|
|
|
|
for del in to_delete.iter() {
|
|
|
|
self.ecs
|
|
|
|
.delete_entity(*del)
|
|
|
|
.expect("Failed to delete entity");
|
|
|
|
}
|
|
|
|
|
2021-12-01 14:45:27 -05:00
|
|
|
// Spawn a new player
|
|
|
|
{
|
|
|
|
let player_entity = spawner::player(&mut self.ecs, 0, 0);
|
|
|
|
let mut player_entity_writer = self.ecs.write_resource::<Entity>();
|
|
|
|
*player_entity_writer = player_entity;
|
|
|
|
}
|
|
|
|
|
2022-01-05 16:44:44 -05:00
|
|
|
// Replace the world maps
|
|
|
|
self.ecs.insert(map::MasterDungeonMap::new());
|
|
|
|
|
2021-11-15 13:27:40 -05:00
|
|
|
// Build a new map and place the player
|
2022-01-06 09:34:17 -05:00
|
|
|
self.generate_world_map(1, 0);
|
2021-12-01 14:45:27 -05:00
|
|
|
}
|
|
|
|
|
2022-01-06 09:34:17 -05:00
|
|
|
fn generate_world_map(&mut self, new_depth: i32, offset: i32) {
|
2021-12-01 14:45:27 -05:00
|
|
|
self.mapgen_index = 0;
|
|
|
|
self.mapgen_timer = 0.0;
|
|
|
|
self.mapgen_history.clear();
|
|
|
|
|
2022-01-06 09:34:17 -05:00
|
|
|
if let Some(history) = map::level_transition(&mut self.ecs, new_depth, offset) {
|
2022-01-05 16:44:44 -05:00
|
|
|
self.mapgen_history = history;
|
2022-01-06 09:34:17 -05:00
|
|
|
} else {
|
|
|
|
map::thaw_level_entities(&mut self.ecs);
|
2021-11-15 13:27:40 -05:00
|
|
|
}
|
|
|
|
}
|
2021-11-09 15:50:42 -05:00
|
|
|
}
|
|
|
|
|
2021-12-24 10:38:44 -05:00
|
|
|
fn main() -> ::rltk::BError {
|
2022-01-04 12:12:08 -05:00
|
|
|
let context = ::rltk::RltkBuilder::simple(80, 60)
|
|
|
|
.unwrap()
|
2021-10-20 12:01:15 -04:00
|
|
|
.with_title("Roguelike Tutorial")
|
|
|
|
.build()?;
|
|
|
|
|
2021-11-04 15:06:04 -04:00
|
|
|
let mut gs = State::new();
|
2021-10-21 12:54:39 -04:00
|
|
|
|
2021-11-04 11:27:44 -04:00
|
|
|
register!(
|
2021-11-04 11:38:13 -04:00
|
|
|
gs <-
|
2021-11-05 13:12:22 -04:00
|
|
|
AreaOfEffect,
|
2022-01-05 11:46:39 -05:00
|
|
|
Attributes,
|
|
|
|
BlocksTile,
|
|
|
|
BlocksVisibility,
|
2022-01-11 15:35:59 -05:00
|
|
|
Chasing,
|
2021-11-05 14:32:14 -04:00
|
|
|
Confusion,
|
2022-01-05 11:46:39 -05:00
|
|
|
Consumable,
|
|
|
|
Door,
|
2022-01-06 10:00:42 -05:00
|
|
|
DMSerializationHelper,
|
2022-01-05 11:46:39 -05:00
|
|
|
EntityMoved,
|
|
|
|
EntryTrigger,
|
2021-11-15 09:19:22 -05:00
|
|
|
Equippable,
|
2021-11-15 09:45:12 -05:00
|
|
|
Equipped,
|
2022-01-11 14:16:23 -05:00
|
|
|
Faction,
|
2022-01-05 11:46:39 -05:00
|
|
|
Hidden,
|
|
|
|
HungerClock,
|
|
|
|
InBackpack,
|
|
|
|
InflictsDamage,
|
2022-01-11 09:28:45 -05:00
|
|
|
Initiative,
|
2022-01-05 11:46:39 -05:00
|
|
|
Item,
|
2022-01-10 10:21:19 -05:00
|
|
|
LightSource,
|
2022-01-05 11:46:39 -05:00
|
|
|
LootTable,
|
|
|
|
MagicMapper,
|
2022-01-04 10:08:06 -05:00
|
|
|
MeleeWeapon,
|
2022-01-11 14:16:23 -05:00
|
|
|
MoveMode,
|
2022-01-11 09:33:21 -05:00
|
|
|
MyTurn,
|
2022-01-05 11:46:39 -05:00
|
|
|
Name,
|
|
|
|
NaturalAttackDefense,
|
2022-01-06 09:34:17 -05:00
|
|
|
OtherLevelPosition,
|
2021-11-16 11:33:58 -05:00
|
|
|
ParticleLifetime,
|
2022-01-05 11:46:39 -05:00
|
|
|
Player,
|
|
|
|
Pools,
|
|
|
|
Position,
|
2021-11-18 15:25:29 -05:00
|
|
|
ProvidesFood,
|
2022-01-05 11:46:39 -05:00
|
|
|
ProvidesHealing,
|
2022-01-03 10:49:12 -05:00
|
|
|
Quips,
|
2022-01-05 11:46:39 -05:00
|
|
|
Ranged,
|
|
|
|
Renderable,
|
|
|
|
SerializationHelper,
|
|
|
|
SimpleMarker<SerializeMe>,
|
|
|
|
SingleActivation,
|
2022-01-03 15:24:38 -05:00
|
|
|
Skills,
|
2022-01-05 11:46:39 -05:00
|
|
|
SufferDamage,
|
|
|
|
Viewshed,
|
2022-01-11 14:16:23 -05:00
|
|
|
WantsToApproach,
|
2022-01-05 11:46:39 -05:00
|
|
|
WantsToDropItem,
|
2022-01-11 14:16:23 -05:00
|
|
|
WantsToFlee,
|
2022-01-05 11:46:39 -05:00
|
|
|
WantsToMelee,
|
|
|
|
WantsToPickupItem,
|
|
|
|
WantsToRemoveItem,
|
|
|
|
WantsToUseItem,
|
|
|
|
Wearable,
|
2021-11-04 11:27:44 -04:00
|
|
|
);
|
2021-10-21 12:54:39 -04:00
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new());
|
|
|
|
|
2021-12-23 11:00:37 -05:00
|
|
|
raws::load_raws();
|
|
|
|
|
2022-01-05 16:44:44 -05:00
|
|
|
gs.ecs.insert(map::MasterDungeonMap::new());
|
2022-01-04 12:12:08 -05:00
|
|
|
gs.ecs.insert(Map::new(1, 64, 64, "New Map"));
|
2021-12-01 15:25:48 -05:00
|
|
|
gs.ecs.insert(Point::zero());
|
2021-12-24 10:38:44 -05:00
|
|
|
gs.ecs.insert(RandomNumberGenerator::new());
|
2021-12-02 14:59:35 -05:00
|
|
|
|
|
|
|
let player_entity = spawner::player(&mut gs.ecs, 0, 0);
|
|
|
|
gs.ecs.insert(player_entity);
|
|
|
|
|
2021-12-01 14:45:27 -05:00
|
|
|
gs.ecs.insert(RunState::MapGeneration {});
|
2021-11-05 14:32:14 -04:00
|
|
|
gs.ecs.insert(GameLog::new("Welcome to Rusty Roguelike"));
|
2021-11-16 11:33:58 -05:00
|
|
|
gs.ecs.insert(particle_system::ParticleBuilder::new());
|
2021-11-29 14:59:46 -05:00
|
|
|
gs.ecs.insert(rex_assets::RexAssets::new());
|
2021-10-26 14:38:30 -04:00
|
|
|
|
2022-01-06 09:34:17 -05:00
|
|
|
gs.generate_world_map(1, 0);
|
2021-12-01 14:45:27 -05:00
|
|
|
|
2022-01-11 10:30:32 -05:00
|
|
|
::rltk::main_loop(context, gs)
|
2021-10-21 12:54:39 -04:00
|
|
|
}
|