44/*
55Made By: Patrick J. Rye
66Purpose: A header to hold functions that are pretty basic and likely won't change very often or at all.
7- Current Revision: 2.1.4
7+ Current Revision: 1.0.1
88Change Log---------------------------------------------------------------------------------------------------------------------------------------------------
99Date Revision Changed By Changes
1010------ --------- ------------ ---------------------------------------------------------------------------------------------------------------------
11- =============================================================================================================================================================
12- 2015/02/20 1.0 Patrick Rye -Original from 3.1a
13- =============================================================================================================================================================
14- 2015/03/02 2.0 Patrick Rye -Renamed to Basic.h
15- -Added save file checker function.
16- =============================================================================================================================================================
17- 2015/03/02 2.1 Patrick Rye -Changed save file checker to be able to check for any file name.
18- =============================================================================================================================================================
19- 2015/03/04 2.1.1 Patrick Rye -Removed save exists function as it was replaced by file exists.
20- =============================================================================================================================================================
21- 2015/03/05 2.1.2 Patrick Rye -Changed change log date format from MM/DD/YY to YYYY/MM/DD because I like it better.
11+ =============================================================================================================================================================
12+ -------------------------------------------------------------------------------------------------------------------------------------------------------------
13+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~MOVED FROM BETA TO GAMMA~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14+ -------------------------------------------------------------------------------------------------------------------------------------------------------------
2215=============================================================================================================================================================
23- 2015/03/09 2.1.3 Patrick Rye -Moved win / opening messages here .
24- -Moved enums here.
16+ 2015/03/16 1.0 Patrick Rye -Move from beta revisions to gamma revisions .
17+ -Changed some int to smaller variables because they don't need to be that big.
2518=============================================================================================================================================================
26- 2015/03/09 2.1.4 Patrick Rye -Added more effects.
27- -Updated some other stuff.
28- -Function to return string of start / end of status effect.
29- =============================================================================================================================================================
19+ 2015/03/17 1.0.1 Patrick Rye -Changed order of elements
20+ -Made function that shows bar representing health.
21+ -Made function that returns multiplier depending on attacking and defending elements.
22+ -Added function which returns string name of element
23+ -Added function which returns string name of status
24+ =============================================================================================================================================================
25+
3026*/
3127
3228/* ********************************************************************************************************/
@@ -66,7 +62,7 @@ enum effects
6662 effectWet,
6763 effectPoison,
6864 effectBleeding,
69- effectConfused
65+ effectConfused,
7066};
7167
7268enum stats
@@ -80,19 +76,20 @@ enum stats
8076 statMaxHealth,
8177 statStatus,
8278 statStatusCounter,
79+ statElement
8380};
8481
8582enum elements
8683{
87- elementFire = 0 ,
84+ elementLight = 0 ,
85+ elementWind,
8886 elementIce,
89- elementEnergy ,
87+ elementWater ,
9088 elementDarkness,
91- elementLight,
9289 elementEarth,
93- elementWind ,
94- elementWater ,
95- elementPhysical, // Currently does nothing. (Will factor in when I make elemental weaknesses)
90+ elementFire ,
91+ elementEnergy ,
92+ elementPhysical,
9693 elementNone // For spells that don't do damage.
9794};
9895
@@ -106,25 +103,110 @@ enum spelltypes
106103
107104using namespace std ;
108105
109- bool DodgeCheck (int LUK, int DEX)
106+ string StatusName (unsigned char effect)
107+ {
108+ switch (effect)
109+ {
110+ case effectNone :
111+ return " no status" ;
112+ case effectBlinded :
113+ return " blinded" ;
114+ case effectFrozen :
115+ return " frozen" ;
116+ case effectBurned :
117+ return " burned" ;
118+ case effectWet :
119+ return " wet" ;
120+ case effectPoison :
121+ return " poisoned" ;
122+ case effectBleeding :
123+ return " bleeding" ;
124+ case effectConfused :
125+ return " confused" ;
126+ };
127+ return " ERROR" ;
128+ }
129+
130+ string ElementName (unsigned char element)
131+ {
132+ switch (element)
133+ {
134+ case elementLight :
135+ return " light" ;
136+ case elementWind :
137+ return " wind" ;
138+ case elementIce :
139+ return " ice" ;
140+ case elementWater :
141+ return " water" ;
142+ case elementDarkness :
143+ return " darkness" ;
144+ case elementEarth :
145+ return " earth" ;
146+ case elementFire :
147+ return " fire" ;
148+ case elementEnergy :
149+ return " energy" ;
150+ case elementPhysical :
151+ return " physical" ;
152+ case elementNone :
153+ return " none" ;
154+ };
155+ return " ERROR" ;
156+ }
157+
158+ string BarMarker (unsigned int CurrentValue, unsigned int MaxValue)
159+ {
160+ string TempHealthBar = " <" ;
161+ int HealthPercent = floor ((CurrentValue * 100 )/MaxValue);
162+ for (unsigned char Bar = 0 ; Bar < 20 ; Bar++)
163+ {
164+ if (HealthPercent >= 5 ) {TempHealthBar += " =" ;}
165+ else {TempHealthBar += " " ;}
166+ HealthPercent -= 5 ;
167+ }
168+ TempHealthBar += " >" ;
169+ // cout<<TempHealthBar<<endl;
170+ return TempHealthBar;
171+ }
172+
173+ float ElementMulti (unsigned char AttackingElement, unsigned char DefendingElement)
174+ {
175+ /* The further away two elements are the more damage that they do to each other.
176+ For example a fire attack on an ice monster will be 125% damage, while a fire
177+ attack on fire monster will only do 75% damage. 2 Spaces away will do normal damage
178+ And None elements or physical do normal damage as well.*/
179+ if (AttackingElement == elementNone || DefendingElement == elementNone) {return 1.0 ;}
180+ if (AttackingElement == elementPhysical || DefendingElement == elementPhysical) {return 1.0 ;}
181+ switch (abs (AttackingElement - DefendingElement))
182+ {
183+ case 0 :
184+ return 0.75 ;
185+ case 1 :
186+ return 0.875 ;
187+ case 2 :
188+ return 1 ;
189+ case 3 :
190+ return 1.125 ;
191+ case 4 :
192+ return 1.25 ;
193+ default :
194+ return 1 ;
195+ };
196+ return 1 ;
197+ }
198+
199+ bool DodgeCheck (unsigned char LUK, unsigned char DEX)
110200{
111201 // The way I worked out this dodge calc is that if the Dex and Luk both equal 150 (which isn't possible under the current levelling up system),
112202 // then they have a 25% chance to dodge. I also wanted Dex to factor into 75% of the chance and Luk only 25%
113203 // Can return true, that they dodged or false that they did not.
114- double douDodgeChance = ((DEX/2 )+(LUK/6 )/4 );
204+ float douDodgeChance = ((DEX/2 )+(LUK/6 )/4 );
115205 if (rand () % 101 <= douDodgeChance) {return true ;}
116206 else {return false ;}
117207}
118208
119- bool RemoveStatusEffect (int TargetLuk, int CurrentEffect, int EffectTurns)
120- {
121- // Check if status effect should be removed based on turns and luck.
122- if (EffectTurns >= 5 ) {return true ;} // Get rid of effect if it has been there for more than 5 turns.
123- if (rand () % 101 <= (TargetLuk) + (EffectTurns *2.5 ) - (intBattleLevel * 2 )) {return true ;}
124- return false ;
125- }
126-
127- float DamageHealthPercent (int CurrentHealth, int MaximumHealth)
209+ float DamageHealthPercent (unsigned int CurrentHealth, unsigned int MaximumHealth)
128210{
129211 /* Function that returns a percentage value that will be multiplied by the damage.
130212 The value will vary with health so that the less health something has
@@ -153,20 +235,20 @@ string HitName()
153235 return " hit" ;
154236}
155237
156- bool StunCheck (int intAttackerLuck, int intDefenderLuck)
238+ bool StunCheck (unsigned char intAttackerLuck, unsigned char intDefenderLuck)
157239{
158240 if (intDefenderLuck < intAttackerLuck) {if (rand ()% 101 < (intAttackerLuck - intDefenderLuck) / 3 ) {return true ;}}
159241 return false ;
160242}
161243
162- string StateOfBeing (int intCurrHealth, int intMaxHealth)
244+ string StateOfBeing (unsigned int intCurrHealth, unsigned int intMaxHealth)
163245{
164246 /* Outputs a string that gives a description of how the monster is doing
165247 Example: at full health can return "Healthy"
166248 while below 10% of max health it might return "dying" or "badly wounded"*/
167- long flHealthPercent = (intCurrHealth * 100 )/intMaxHealth;
249+ float flHealthPercent = (intCurrHealth * 100 )/intMaxHealth;
168250 string strState;
169- int intRandomState;
251+ unsigned char intRandomState;
170252
171253 const string FullHealthOutput[3 ] = {" steady" ," well" ," healthy" };
172254 const string SeventyPHealthOutput[3 ] = {" wounded" ," damaged" ," hurt" };
@@ -187,7 +269,7 @@ string StateOfBeing(int intCurrHealth, int intMaxHealth)
187269 return strState;
188270}
189271
190- string EndOfEffectString (std::string Target, int Effect)
272+ string EndOfEffectString (std::string Target, unsigned char Effect)
191273{
192274 string TempStr = " " ;
193275 // Returns string describing status effect ending.
@@ -211,7 +293,7 @@ string EndOfEffectString(std::string Target, int Effect)
211293 return " Your body ejects the last of the poison." ;
212294 break ;
213295 case effectBleeding :
214- return " Your bleeding wounds being to close." ;
296+ return " Your bleeding wounds begin to close." ;
215297 break ;
216298 case effectConfused :
217299 return " Your head is now clear." ;
@@ -271,7 +353,7 @@ string EndOfEffectString(std::string Target, int Effect)
271353 return " ERROR" ;
272354}
273355
274- string StartOfEffectString (std::string Target, int Effect)
356+ string StartOfEffectString (std::string Target, unsigned char Effect)
275357{
276358 string TempStr = " " ;
277359 // Returns string describing status effect ending.
@@ -355,7 +437,7 @@ string StartOfEffectString(std::string Target, int Effect)
355437 return " ERROR" ;
356438}
357439
358- bool fileexists (const char *fileName)
440+ inline bool fileexists (const char *fileName)
359441{
360442 std::ifstream infile (fileName);
361443 return infile.good ();
@@ -366,15 +448,15 @@ std::string ConvertToUpper(std::string& str)
366448 // Thanks to codekiddy for his post at http://www.cplusplus.com/forum/beginner/70692/
367449 std::locale settings;
368450 std::string converted;
369- for (short i = 0 ; i < str.size (); ++i) {converted += (toupper (str[i], settings));}
451+ for (unsigned char i = 0 ; i < str.size (); ++i) {converted += (toupper (str[i], settings));}
370452 return converted;
371453}
372454
373455std::string ConvertToLower (std::string& str)
374456{
375457 std::locale settings;
376458 std::string converted;
377- for (short i = 0 ; i < str.size (); ++i) {converted += (tolower (str[i], settings));}
459+ for (unsigned char i = 0 ; i < str.size (); ++i) {converted += (tolower (str[i], settings));}
378460 return converted;
379461}
380462
@@ -383,7 +465,7 @@ std::string ProperCase(std::string& str)
383465 std::locale settings;
384466 std::string converted;
385467 converted+= (toupper (str[1 ], settings));
386- for (short i = 1 ; i < str.size (); ++i) {converted += (tolower (str[i], settings));}
468+ for (unsigned char i = 1 ; i < str.size (); ++i) {converted += (tolower (str[i], settings));}
387469 return converted;
388470}
389471
@@ -396,8 +478,8 @@ char CharConvertToUpper(char chrCheck)
396478 return converted;
397479}
398480
399- void ShowOpeningMessage () {for (int i = 0 ; i < 16 ; i++){cout<<OpeningMessage[i];}}
481+ inline void ShowOpeningMessage () {for (unsigned char i = 0 ; i < 16 ; i++){cout<<OpeningMessage[i];}}
400482
401- void ShowWinningMessage () {for (int i = 0 ; i < 6 ; i++) {cout<<WinningMessage[i];}}
483+ inline void ShowWinningMessage () {for (unsigned char i = 0 ; i < 6 ; i++) {cout<<WinningMessage[i];}}
402484
403485#endif // If header was already called load nothing
0 commit comments