Add Initiative component

This commit is contained in:
Timothy Warren 2022-01-11 09:28:45 -05:00
parent f558112836
commit 107f190a39
5 changed files with 12 additions and 0 deletions

View File

@ -291,6 +291,11 @@ pub struct LightSource {
pub range: i32, pub range: i32,
} }
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Initiative {
pub current: i32,
}
// Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an // Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an
// Entity. // Entity.

View File

@ -467,6 +467,7 @@ fn main() -> ::rltk::BError {
HungerClock, HungerClock,
InBackpack, InBackpack,
InflictsDamage, InflictsDamage,
Initiative,
Item, Item,
LightSource, LightSource,
LootTable, LootTable,

View File

@ -293,6 +293,9 @@ pub fn spawn_named_mob(
// Spawn in the specified location // Spawn in the specified location
eb = spawn_position(pos, eb, key, raws); eb = spawn_position(pos, eb, key, raws);
// Initiative of 2
eb = eb.with(Initiative { current: 2 });
// Renderable // Renderable
if let Some(renderable) = &mob_template.renderable { if let Some(renderable) = &mob_template.renderable {
eb = eb.with(get_renderable_component(renderable)); eb = eb.with(get_renderable_component(renderable));

View File

@ -79,6 +79,7 @@ pub fn save_game(ecs: &mut World) {
HungerClock, HungerClock,
InBackpack, InBackpack,
InflictsDamage, InflictsDamage,
Initiative,
Item, Item,
LightSource, LightSource,
LootTable, LootTable,
@ -184,6 +185,7 @@ pub fn load_game(ecs: &mut World) {
HungerClock, HungerClock,
InBackpack, InBackpack,
InflictsDamage, InflictsDamage,
Initiative,
Item, Item,
LightSource, LightSource,
LootTable, LootTable,

View File

@ -54,6 +54,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
color: RGB::from_f32(1.0, 1.0, 0.5), color: RGB::from_f32(1.0, 1.0, 0.5),
range: 8, range: 8,
}) })
.with(Initiative { current: 0 })
.marked::<SimpleMarker<SerializeMe>>() .marked::<SimpleMarker<SerializeMe>>()
.build(); .build();