Research

<
>
October 19, 2021

Up until now technologies could directly be marked as researched witout any material or time cost for the player.
For now I added the new Material ResearchToken that has to be spent for researching:

pub enum Material {
    Ore(Ore),
    Plate(Plate),
    ...
    ResearchToken,
}

With individual Technologies having a research cost:

impl Tech {
    ...
    pub fn research_cost(&self) -> u32 {
        match self {
            Self::BetterBelts => 3000,
        }
    }
}

I also added a new type Research that tracks each Tech‘s research progress, allows setting the active research and spending of tokens to move research forward:

pub enum ResearchError {
    AlreadyResearched,
    CantResearch,
    PayingTooMuch,
    NoActiveResearch,
}

type ResearchResult<T> = std::result::Result<T, ResearchError>;

pub struct Research {
    current: Option<Tech>,
    tech_tree: TechTree,
    progress: BTreeMap<Tech, u32>,
}

impl Research {
    pub fn set_active_research(&mut self, tech: Tech) -> ResearchResult<()> {
        ...
    }

    pub fn stop_research(&mut self) {
        ...
    }

    pub fn pay(&mut self, amount: u32) -> ResearchResult<()> {
        ...
    }

    ...
}

The event was renamed from MarkResearched(Tech) to StartResearch(Tech) to reflect the change in behavior.

To invest ResearchToken from within the game I added the new Structure Lab.
I’m now also rendering the currently active research and its progress in the bottom left corner: