moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / game / wskill.cpp
blob128aa8dc661494f059739beb6023cc12f67281e8
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #include "wskill.h"
13 #include "message.h"
14 #include "fesave.h"
15 #include "feparse.h"
16 #include "item.h"
18 int CWeaponSkillLevelMap[] = {
19 0, 1500, 2000, 3000, 5000, 7500, 10000, 15000,
20 20000, 30000, 50000, 75000, 100000, 150000,
21 200000, 300000, 500000, 750000, 1000000,
22 1500000, 2000000
25 feuLong CWeaponSkillUnuseTickMap[] = {
26 500000, 400000, 300000, 250000, 200000,
27 150000, 125000, 100000, 80000, 62500,
28 50000, 40000, 30000, 25000, 20000,
29 15000, 12500, 10000, 8000, 6250, 5000
32 int CWeaponSkillUnusePenaltyMap[] = {
33 100, 125, 150, 200, 250, 300, 400, 500,
34 625, 800, 1000, 1250, 1500, 2000, 2500,
35 3000, 4000, 5000, 6250, 8000, 10000
38 cchar *CWeaponSkillName[WEAPON_SKILL_CATEGORIES] = {
39 "unarmed combat",
40 "kicking",
41 "biting",
42 "uncategorized",
43 "small swords",
44 "large swords",
45 "blunt weapons",
46 "axes",
47 "polearms",
48 "whips",
49 "shields"
52 int SWeaponSkillLevelMap[] = {
53 0, 500, 750, 1000, 1500, 2000, 3000, 5000,
54 7500, 10000, 15000, 20000, 30000, 50000,
55 75000, 100000, 150000, 200000, 300000,
56 500000, 750000
59 feuLong SWeaponSkillUnuseTickMap[] = {
60 250000, 200000, 150000, 125000, 100000,
61 80000, 62500, 50000, 40000, 30000,
62 25000, 20000, 15000, 12500, 10000,
63 8000, 6250, 5000, 4000, 3000, 2500
66 int SWeaponSkillUnusePenaltyMap[] = {
67 250, 300, 400, 500, 625, 800, 1000,
68 1250, 1500, 2000, 2500, 3000, 4000,
69 5000, 6250, 8000, 10000, 12500, 15000,
70 20000, 25000
74 int cweaponskill::GetLevelMap (int I) const { return CWeaponSkillLevelMap[I]; }
75 feuLong cweaponskill::GetUnuseTickMap (int I) const { return CWeaponSkillUnuseTickMap[I]; }
76 int cweaponskill::GetUnusePenaltyMap (int I) const { return CWeaponSkillUnusePenaltyMap[I]; }
77 cchar *cweaponskill::GetName (int Category) const { return CWeaponSkillName[Category]; }
79 sweaponskill::sweaponskill (citem *Item) : ID(Item->GetID()), Weight(Item->GetWeight()), Config(Item->GetConfig()) {}
80 int sweaponskill::GetLevelMap (int I) const { return SWeaponSkillLevelMap[I]; }
81 feuLong sweaponskill::GetUnuseTickMap (int I) const { return SWeaponSkillUnuseTickMap[I]; }
82 int sweaponskill::GetUnusePenaltyMap (int I) const { return SWeaponSkillUnusePenaltyMap[I]; }
84 void weaponskill::Save (outputfile &SaveFile) const { SaveFile << (int)Level << (int)Hits << (int)HitCounter; }
85 void weaponskill::Load (inputfile &SaveFile) { SaveFile >> (int&)Level >> (int&)Hits >> (int&)HitCounter; }
87 truth weaponskill::AddHit (int AddHits) {
88 if (!AddHits) return false;
89 HitCounter = 0;
90 if (Hits <= 5000000-AddHits) Hits += AddHits; else Hits = 5000000;
91 int OldLevel = Level;
92 while (Level < 20 && Hits >= GetLevelMap(Level + 1)) ++Level;
93 return Level != OldLevel;
97 truth weaponskill::SubHit (int SubHits) {
98 if (!SubHits) return false;
99 if (Hits >= SubHits) Hits -= SubHits; else Hits = 0;
100 int OldLevel = Level;
101 while (Level && Hits < GetLevelMap(Level)) --Level;
102 return Level != OldLevel;
106 void cweaponskill::AddLevelUpMessage (int Category) const {
107 ADD_MESSAGE("You advance to skill level %d with %s!", Level, CWeaponSkillName[Category]);
111 void cweaponskill::AddLevelDownMessage (int Category) const {
112 ADD_MESSAGE("You have not practised enough with %s lately. Your skill level is reduced to %d!", CWeaponSkillName[Category], Level);
116 void sweaponskill::AddLevelUpMessage (cchar *WeaponName) const {
117 ADD_MESSAGE("You advance to skill level %d with your %s!", Level, WeaponName);
121 void sweaponskill::AddLevelDownMessage (cchar *WeaponName) const {
122 ADD_MESSAGE("You have not practised enough with your %s lately. Your skill level is reduced to %d!", WeaponName, Level);
126 void sweaponskill::Save (outputfile &SaveFile) const {
127 weaponskill::Save(SaveFile);
128 SaveFile << ID << Weight << (int)Config;
132 void sweaponskill::Load (inputfile &SaveFile) {
133 weaponskill::Load(SaveFile);
134 SaveFile >> ID >> Weight >> (int&)Config;
138 truth weaponskill::Tick () {
139 if (Hits && HitCounter++ >= GetUnuseTickMap(Level)) {
140 HitCounter -= GetUnuseTickMap(Level);
141 if (SubHit(GetUnusePenaltyMap(Level))) return true;
143 return false;
147 truth sweaponskill::IsSkillOf (citem *Item) const {
148 return (ID == Item->GetID() && Weight == Item->GetWeight() && Config == Item->GetConfig());
152 truth sweaponskill::IsSkillOfCloneMother (citem *Item, feuLong CMID) const {
153 return (ID == CMID && Weight == Item->GetWeight() && Config == Item->GetConfig());