Skip to content

Commit

Permalink
[game] Add Perk definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Lysai authored and pingw33n committed Jun 3, 2020
1 parent 0d93b8f commit e5c64ae
Show file tree
Hide file tree
Showing 3 changed files with 1,064 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/game/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::game::object;
use crate::vm::{self, *};
use crate::vm::value::Value;

pub const GVAR_PLAYER_REPUTATION: i32 = 0;

#[derive(Clone, Copy, Debug, Enum, Eq, PartialEq, Ord, PartialOrd, Primitive)]
pub enum ScriptKind {
System = 0x0,
Expand Down
17 changes: 17 additions & 0 deletions src/game/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const SKILL_NAME_MSG_BASE: MessageId = 100;
const SKILL_DESCR_MSG_BASE: MessageId = 200;
const SKILL_FORMULA_MSG_BASE: MessageId = 300;
const LEVEL_UP_MSG: MessageId = 600;
const PERK_NAME_MSG_BASE: MessageId = 101;
const PERK_DESCR_MSG_BASE: MessageId = 1101;

struct Tagged {
tagged: bool,
Expand All @@ -43,8 +45,10 @@ impl Default for Tagged {
pub struct Stats {
stat_msgs: Messages,
skill_msgs: Messages,
perk_msgs: Messages,
stat_defs: EnumMap<Stat, StatDef>,
skill_defs: EnumMap<Skill, SkillDef>,
perk_defs: EnumMap<Perk, PerkDef>,
traits: EnumMap<Trait, bool>,
perks: HashMap<ProtoId, EnumMap<Perk, bool>>,
tagged: EnumMap<Skill, Tagged>,
Expand All @@ -58,13 +62,18 @@ impl Stats {
let skill_msgs = Messages::read_file(fs, language, "game/skill.msg")?;
let skill_defs = SkillDef::defaults();

let perk_msgs = Messages::read_file(fs, language, "game/perk.msg")?;
let perk_defs = PerkDef::defaults();

let mut perks = HashMap::new();
perks.insert(ProtoId::DUDE, Default::default());
Ok(Self {
stat_msgs,
skill_msgs,
perk_msgs,
stat_defs,
skill_defs,
perk_defs,
traits: Default::default(),
perks,
tagged: Default::default(),
Expand All @@ -83,6 +92,14 @@ impl Stats {
&self.skill_msgs.get(SKILL_FORMULA_MSG_BASE + skill as MessageId).unwrap().text
}

pub fn perk_name(&self, perk: Perk) -> &bstr {
&self.perk_msgs.get(PERK_NAME_MSG_BASE + perk as MessageId).unwrap().text
}

pub fn perk_description(&self, perk: Perk) -> &bstr {
&self.perk_msgs.get(PERK_DESCR_MSG_BASE + perk as MessageId).unwrap().text
}

pub fn has_perk(&self, perk: Perk, pid: ProtoId) -> bool {
self.perks.get(&pid).map(|m| m[perk]).unwrap_or(false)
}
Expand Down
Loading

0 comments on commit e5c64ae

Please sign in to comment.