2022-12-27 20:16:35 +11:00
|
|
|
use super::StaticItem;
|
2022-12-27 23:35:27 +11:00
|
|
|
use once_cell::sync::OnceCell;
|
|
|
|
use std::collections::BTreeMap;
|
2022-12-28 20:00:55 +11:00
|
|
|
use ansi::ansi;
|
2022-12-27 23:35:27 +11:00
|
|
|
use crate::models::item::Item;
|
2022-12-27 20:16:35 +11:00
|
|
|
|
2022-12-27 23:35:27 +11:00
|
|
|
pub struct Zone {
|
|
|
|
pub code: &'static str,
|
|
|
|
pub display: &'static str,
|
|
|
|
pub outdoors: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
static STATIC_ZONE_DETAILS: OnceCell<BTreeMap<&'static str, Zone>> = OnceCell::new();
|
|
|
|
pub fn zone_details() -> &'static BTreeMap<&'static str, Zone> {
|
|
|
|
STATIC_ZONE_DETAILS.get_or_init(
|
|
|
|
|| vec!(
|
|
|
|
Zone { code: "melbs",
|
|
|
|
display: "Melbs",
|
|
|
|
outdoors: true },
|
|
|
|
Zone { code: "repro_xv",
|
|
|
|
display: "Reprolabs XV",
|
|
|
|
outdoors: true },
|
|
|
|
).into_iter().map(|x|(x.code, x)).collect())
|
|
|
|
}
|
|
|
|
|
2022-12-29 00:37:14 +11:00
|
|
|
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Debug)]
|
2022-12-27 23:35:27 +11:00
|
|
|
pub struct GridCoords {
|
2022-12-29 00:37:14 +11:00
|
|
|
pub x: i64,
|
|
|
|
pub y: i64,
|
|
|
|
pub z: i64
|
2022-12-27 23:35:27 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub enum ExitType {
|
|
|
|
Free, // Anyone can just walk it.
|
|
|
|
// Future ideas: Doors with locks, etc...
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Direction {
|
|
|
|
NORTH,
|
|
|
|
SOUTH,
|
|
|
|
EAST,
|
|
|
|
WEST,
|
|
|
|
NORTHEAST,
|
|
|
|
SOUTEAST,
|
|
|
|
NORTHWEST,
|
|
|
|
SOUTHWEST,
|
|
|
|
UP,
|
|
|
|
DOWN,
|
|
|
|
IN(&'static str)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum ExitTarget {
|
|
|
|
UseGPS,
|
|
|
|
Custom(&'static str)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Exit {
|
|
|
|
direction: Direction,
|
|
|
|
target: ExitTarget,
|
|
|
|
exit_type: ExitType
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Room {
|
|
|
|
pub zone: &'static str,
|
|
|
|
pub code: &'static str,
|
|
|
|
pub name: &'static str,
|
|
|
|
pub short: &'static str,
|
|
|
|
pub grid_coords: GridCoords,
|
|
|
|
pub description: &'static str,
|
2022-12-29 00:37:14 +11:00
|
|
|
pub description_less_explicit: Option<&'static str>,
|
2022-12-27 23:35:27 +11:00
|
|
|
pub exits: Vec<Exit>
|
|
|
|
}
|
|
|
|
|
|
|
|
static STATIC_ROOM_LIST: OnceCell<Vec<Room>> = OnceCell::new();
|
|
|
|
pub fn room_list() -> &'static Vec<Room> {
|
|
|
|
STATIC_ROOM_LIST.get_or_init(
|
|
|
|
|| vec!(
|
|
|
|
Room {
|
|
|
|
zone: "repro_xv",
|
|
|
|
code: "repro_xv_chargen",
|
2022-12-29 00:37:14 +11:00
|
|
|
name: ansi!("<yellow>Choice Room<reset>"),
|
2022-12-27 23:35:27 +11:00
|
|
|
short: ansi!("<green>CR<reset>"),
|
2022-12-29 00:37:14 +11:00
|
|
|
description: ansi!(
|
2022-12-29 16:20:34 +11:00
|
|
|
"A room brightly lit in unnaturally white light, covered in sparkling \
|
|
|
|
white tiles from floor to ceiling. A loudspeaker plays a message on \
|
|
|
|
loop:\n\
|
|
|
|
\t<blue>\"Citizen, you are here because your memory has been wiped and \
|
2022-12-29 00:37:14 +11:00
|
|
|
you are ready to start a fresh life. As a being enhanced by \
|
|
|
|
Gazos-Murlison Co technology, the emperor has granted you the power \
|
|
|
|
to choose 14 points of upgrades to yourself. Choose wisely, as it \
|
|
|
|
will impact who you end up being, and you would need to completely \
|
|
|
|
wipe your brain again to change them. Talk to Statbot to spend your \
|
|
|
|
14 points and create your body.\"<reset>\n\
|
|
|
|
[Try <bold>\"statbot hi<reset>, to send hi to statbot - the \" means \
|
|
|
|
to whisper to a particular person in the room]"),
|
|
|
|
description_less_explicit: None,
|
2022-12-27 23:35:27 +11:00
|
|
|
grid_coords: GridCoords { x: 0, y: 0, z: 2 },
|
|
|
|
exits: vec!()
|
|
|
|
},
|
|
|
|
).into_iter().collect())
|
|
|
|
}
|
|
|
|
|
|
|
|
static STATIC_ROOM_MAP_BY_CODE: OnceCell<BTreeMap<&'static str, &'static Room>> = OnceCell::new();
|
|
|
|
pub fn room_map_by_code() -> &'static BTreeMap<&'static str, &'static Room> {
|
|
|
|
STATIC_ROOM_MAP_BY_CODE.get_or_init(
|
|
|
|
|| room_list().iter().map(|r| (r.code, r)).collect())
|
|
|
|
}
|
|
|
|
|
2022-12-29 00:37:14 +11:00
|
|
|
static STATIC_ROOM_MAP_BY_LOC: OnceCell<BTreeMap<&'static GridCoords, &'static Room>> = OnceCell::new();
|
|
|
|
pub fn room_map_by_loc() -> &'static BTreeMap<&'static GridCoords, &'static Room> {
|
|
|
|
STATIC_ROOM_MAP_BY_LOC.get_or_init(
|
|
|
|
|| room_list().iter().map(|r| (&r.grid_coords, r)).collect())
|
|
|
|
}
|
|
|
|
|
2022-12-27 23:35:27 +11:00
|
|
|
pub fn room_static_items() -> Box<dyn Iterator<Item = StaticItem>> {
|
|
|
|
Box::new(room_list().iter().map(|r| StaticItem {
|
|
|
|
item_code: r.code,
|
|
|
|
initial_item: Box::new(|| Item {
|
|
|
|
item_code: r.code.to_owned(),
|
|
|
|
item_type: "room".to_owned(),
|
|
|
|
display: r.description.to_owned(),
|
2022-12-29 00:37:14 +11:00
|
|
|
location: format!("room/{}", r.code),
|
2022-12-27 23:35:27 +11:00
|
|
|
is_static: true,
|
|
|
|
..Item::default()
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
|
|
fn room_zones_should_exist() {
|
|
|
|
for room in room_list() {
|
|
|
|
zone_details().get(room.zone).expect(
|
|
|
|
&format!("zone {} for room {} should exist", room.zone, room.code));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn room_map_by_code_should_have_repro_xv_chargen() {
|
|
|
|
assert_eq!(room_map_by_code().get("repro_xv_chargen").expect("repro_xv_chargen to exist").code,
|
|
|
|
"repro_xv_chargen");
|
|
|
|
}
|
2022-12-27 20:16:35 +11:00
|
|
|
}
|