Research in the library: rooms, spells, towers, traps and doors are discovered in a fixed order
- studying creatures collect research points (mages and owls best, higher levels faster); studying gives less mana than before - free play starts with the basics; campaign missions know what their story allows and can research what the next four missions would bring - research shown in the top bar; the library's info lists the current item and what comes next; locked tools say whether they can be researched Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f20223c93
commit
a54316c86e
8 files changed
+210
-3
No files matched your search
+140
@@ -0,0 +1,140 @@
|
||||
// Research: creatures studying in the library collect research points, and rooms, spells,
|
||||
// towers, traps and doors are discovered one after another in a fixed order. Free play starts
|
||||
// with the basics; a campaign mission knows what its story allows and may research what the
|
||||
// next few missions would bring.
|
||||
|
||||
use crate::game::*;
|
||||
|
||||
// what is researched, in this order: (index in ui::TOOLS, research points)
|
||||
pub const RESEARCH: &[(usize, f32)] = &[
|
||||
(5, 200.0), // training hall
|
||||
(10, 250.0), // heal
|
||||
(21, 300.0), // forge
|
||||
(22, 250.0), // spike pit
|
||||
(29, 250.0), // wooden door
|
||||
(15, 400.0), // cannon tower
|
||||
(12, 450.0), // torture chamber
|
||||
(26, 300.0), // alarm bell
|
||||
(11, 500.0), // summon
|
||||
(13, 550.0), // temple
|
||||
(23, 500.0), // poison vent
|
||||
(30, 500.0), // iron door
|
||||
(18, 550.0), // aerie
|
||||
(16, 650.0), // magic tower
|
||||
(24, 650.0), // fire jet
|
||||
(25, 650.0), // stone roller
|
||||
(19, 700.0), // steel walls
|
||||
(28, 800.0), // frost glow
|
||||
(27, 900.0), // rune mine
|
||||
(31, 1100.0), // magic door
|
||||
];
|
||||
|
||||
// known from the start in free play
|
||||
pub const BASE_TOOLS: &[usize] = &[0, 1, 2, 3, 4, 6, 7, 8, 9, 14, 17, 20];
|
||||
|
||||
// campaign: what the next missions bring may be researched early
|
||||
const LOOKAHEAD: usize = 4;
|
||||
|
||||
impl Game {
|
||||
// free play (None) or campaign mission i: what is known, what can be researched
|
||||
pub fn init_research(&mut self, mission: Option<usize>) {
|
||||
let n = crate::ui::TOOLS.len();
|
||||
match mission {
|
||||
None => {
|
||||
self.known = (0..n).map(|i| BASE_TOOLS.contains(&i)).collect();
|
||||
self.researchable = vec![true; n];
|
||||
}
|
||||
Some(m) => {
|
||||
let unlock = |i: usize| crate::campaign::TOOL_UNLOCK.get(i).copied().unwrap_or(0);
|
||||
self.known = (0..n).map(|i| unlock(i) <= m).collect();
|
||||
self.researchable = (0..n).map(|i| unlock(i) <= m + LOOKAHEAD && i != crate::game::RUNE_TOOL).collect();
|
||||
}
|
||||
}
|
||||
self.research = 0.0;
|
||||
}
|
||||
|
||||
pub fn known(&self, tool: usize) -> bool {
|
||||
self.known.get(tool).copied().unwrap_or(true)
|
||||
}
|
||||
|
||||
// the item being researched now: (index in RESEARCH)
|
||||
pub fn research_target(&self) -> Option<usize> {
|
||||
if self.known.is_empty() {
|
||||
return None;
|
||||
}
|
||||
RESEARCH.iter().position(|&(t, _)| !self.known(t) && self.researchable.get(t).copied().unwrap_or(false))
|
||||
}
|
||||
|
||||
// the next items after the current one (for the library's info)
|
||||
pub fn research_queue(&self, n: usize) -> Vec<usize> {
|
||||
RESEARCH.iter().enumerate().filter(|(_, &(t, _))| !self.known(t) && self.researchable.get(t).copied().unwrap_or(false)).map(|(k, _)| k).take(n).collect()
|
||||
}
|
||||
|
||||
// could this tool still be researched (for the locked-tool message)?
|
||||
pub fn can_research(&self, tool: usize) -> bool {
|
||||
!self.known(tool) && self.researchable.get(tool).copied().unwrap_or(false) && RESEARCH.iter().any(|&(t, _)| t == tool)
|
||||
}
|
||||
|
||||
pub(crate) fn add_research(&mut self, points: f32) {
|
||||
if self.research_target().is_some() {
|
||||
self.research += points;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn update_research(&mut self) {
|
||||
let Some(k) = self.research_target() else { return };
|
||||
let (tool, cost) = RESEARCH[k];
|
||||
if self.research >= cost {
|
||||
self.research -= cost;
|
||||
if let Some(v) = self.known.get_mut(tool) {
|
||||
*v = true;
|
||||
}
|
||||
let name = crate::ui::tool_info(crate::ui::TOOLS[tool]).name;
|
||||
self.msg("msg.researched", vec![name]);
|
||||
self.sfx_ui(Sfx::LevelUp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::map::*;
|
||||
|
||||
#[test]
|
||||
fn studying_discovers_the_next_item() {
|
||||
let mut g = Game::new(9, 64, 64);
|
||||
assert!(!g.tool_allowed(5), "training hall must be researched");
|
||||
assert!(g.tool_allowed(2) && g.tool_allowed(6));
|
||||
let (cx, cy) = g.map.core;
|
||||
for y in cy - 8..=cy - 5 {
|
||||
for x in cx..=cx + 4 {
|
||||
let t = &mut g.map.t[idx(x, y)];
|
||||
t.kind = Kind::Library;
|
||||
t.owner = Owner::Player;
|
||||
}
|
||||
}
|
||||
g.recount();
|
||||
for k in 0..4 {
|
||||
g.spawn(EK::Mage, false, cx as f32 + 0.5 + k as f32, cy as f32 - 6.5, 3);
|
||||
}
|
||||
let mut found = false;
|
||||
for _ in 0..(20 * 400) {
|
||||
g.update(0.05);
|
||||
if g.tool_allowed(5) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert!(found, "research points {}", g.research);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missions_know_their_tools_and_research_ahead() {
|
||||
let g = crate::campaign::start_mission(2, None);
|
||||
assert!(g.tool_allowed(5), "training hall known from mission 3");
|
||||
assert!(!g.tool_allowed(12));
|
||||
assert!(g.can_research(10), "heal comes soon and can be researched");
|
||||
assert!(!g.can_research(31), "magic doors are far away");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user