118 lines
2.3 KiB
Rust
118 lines
2.3 KiB
Rust
|
#[derive(Serialize)]
|
||
|
struct TechFunc {
|
||
|
on_cycle: Option<fn(Player)>,
|
||
|
on_tick: Option<fn(Player)>,
|
||
|
passive: Option<fn(Player)>
|
||
|
}
|
||
|
|
||
|
impl Default for TechFunc {
|
||
|
fn default() -> TechFunc {
|
||
|
TechFunc {
|
||
|
on_cycle: None,
|
||
|
on_tick: None,
|
||
|
passive: None
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Serialize)]
|
||
|
struct Player {
|
||
|
name: String,
|
||
|
color: (u8, u8, u8),
|
||
|
tech: HashMap<String, (u16, TechFunc)>,
|
||
|
research_queue: vec<String>,
|
||
|
money: u16
|
||
|
}
|
||
|
|
||
|
|
||
|
fn scanning(player: Player) -> u16 {
|
||
|
let scan_level = player.tech.get("Scanning").0/144;
|
||
|
scan_level + 2
|
||
|
}
|
||
|
|
||
|
fn hyperspace(player: Player) -> u16 {
|
||
|
let hyperspace_level = player.tech.get("Hyperspace Range").0/144;
|
||
|
hyperspace_level + 3
|
||
|
}
|
||
|
|
||
|
fn terraforming(player: Player) -> u16 {
|
||
|
let terraforming_level = player.tech.get("Terraforming").0/144;
|
||
|
terrafirming*5
|
||
|
}
|
||
|
|
||
|
fn experimentation(player: Player) {
|
||
|
let terraforming_level = player.tech.get("Experimentation").0/144;
|
||
|
|
||
|
let n = player.tech.len();
|
||
|
let mut rng = rand::thread_rng();
|
||
|
tech = rng.gen_range(0, n);
|
||
|
}
|
||
|
|
||
|
impl Default for Player {
|
||
|
fn default() -> Player {
|
||
|
let mut techs = HashMap::new();
|
||
|
|
||
|
techs.insert("Scanning", (144, TechFunc{passive: scanning});
|
||
|
techs.insert("Hyperspace Range", (144, TechFunc{passive: hyperspace}));
|
||
|
techs.insert("Terraforming", (144, TechFunc{passive: terraforming}));
|
||
|
techs.insert("Experimentation", (144, TechFunc));
|
||
|
techs.insert("Weapons", (144, TechFunc));
|
||
|
techs.insert("Banking", (144, TechFunc));
|
||
|
techs.insert("Manufactoring", (144, TechFunc));
|
||
|
|
||
|
Player {
|
||
|
tech: techs
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl process for Weapons {
|
||
|
fn passive() -> (u16, u16) {
|
||
|
(self.amount/144, self.effect2)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Player.techs.get("Weapons").passive()
|
||
|
|
||
|
impl Player {
|
||
|
fn payday() {
|
||
|
let banking_level = self.techs.get("Banking")/144;
|
||
|
self.money = banking_level*75;
|
||
|
|
||
|
let experimentation_level = self.techs.get("Experimentation")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Serialize)]
|
||
|
struct Infrastructure {
|
||
|
name: String,
|
||
|
amount: u16
|
||
|
}
|
||
|
|
||
|
#[derive(Serialize)]
|
||
|
struct Star {
|
||
|
id: u16,
|
||
|
name: String,
|
||
|
coordinates: (u32, u32),
|
||
|
resources: u16,
|
||
|
owner: Option<u8>,
|
||
|
buildings: vec<Infrastructure>
|
||
|
}
|
||
|
|
||
|
impl Default for Star {
|
||
|
fn default() {
|
||
|
let infrastructures = [
|
||
|
Infrastructure {name: "Economy", amount: 0},
|
||
|
Infrastructure {name: "Industry", amount: 0},
|
||
|
Infrastructure {name: "Science", amount: 0}
|
||
|
];
|
||
|
|
||
|
Star {
|
||
|
owner: None,
|
||
|
buildings: infrastructures
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|