1 /************************************************************************
2  *                                                                      *
3  *  FreeSynd - a remake of the classic Bullfrog game "Syndicate".       *
4  *                                                                      *
5  *   Copyright (C) 2012  Ryan Cocks <ryan@ryancocks.net>                *
6  *                                                                      *
7  *    This program is free software;  you can redistribute it and / or  *
8  *  modify it  under the  terms of the  GNU General  Public License as  *
9  *  published by the Free Software Foundation; either version 2 of the  *
10  *  License, or (at your option) any later version.                     *
11  *                                                                      *
12  *    This program is  distributed in the hope that it will be useful,  *
13  *  but WITHOUT  ANY WARRANTY;  without even  the implied  warranty of  *
14  *  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
15  *  General Public License for more details.                            *
16  *                                                                      *
17  *    You can view the GNU  General Public License, online, at the GNU  *
18  *  project's  web  site;  see <http://www.gnu.org/licenses/gpl.html>.  *
19  *  The full text of the license is also included in the file COPYING.  *
20  *                                                                      *
21  ************************************************************************/
22 
23 #ifndef FreeSynd_ipastim_h
24 #define FreeSynd_ipastim_h
25 
26 #include "utils/timer.h"
27 
28 // Stores the values for the Intelligence, Perception and
29 // Adrenaline bars. Also calculates the multipliers to things
30 // like speed that these give.
31 //
32 // Each IPAStim tracks a few values and via the processTicks() method
33 // these values will change over time as in the original Syndicate.
34 
35 class IPAStim
36 {
37 public:
38     typedef enum {
39         Adrenaline,
40         Perception,
41         Intelligence
42     } IPAType;
43     IPAStim(IPAType ipa_type, int amount = 50, int dependency = 50);
44 #ifdef _DEBUG
getName()45     const char * getName() const
46     {
47         return IPANames[(int)ipa_type_];
48     }
49 #endif
50 
51     // Return value varies from 0.5 to 2 and returns 1
52     // for 'neutral' adrenaline.
53     float getMultiplier() const;
54 
55     // We are using percentages, the original data files are using uint8 256 ranges
setLevels256(int amount,int dependency,int effect)56     void setLevels256(int amount, int dependency, int effect)
57     {
58         setLevels(
59             (int)((float)amount/256.0*100.0),
60             (int)((float)dependency/256.0*100.0),
61             (int)((float)effect/256.0*100.0)
62         );
63     }
64 
65     // Note: this method takes percentages as arguments, use
66     // setLevels256 to use the values from Syndicate's data files.
67     // "effect" may not currently be used.
68     void setLevels(int amount, int dependency, int effect = 0);
69 
setAmount(int percentage)70     void setAmount(int percentage) { amount_ = percentage; }
71 
getAmount()72     int getAmount()     const { return amount_; }
getDependency()73     int getDependency() const { return dependency_; }
getEffect()74     int getEffect()    const { return effect_; }
getType()75     IPAType getType()   const { return ipa_type_; }
76 
77     void processTicks(int elapsed);
78 
79 private:
80     // Used to select colors when rendering
81     IPAType ipa_type_;
82 #ifdef _DEBUG
83     // Allow pretty debug
84     static const char * IPANames[3];
85 #endif
86 
87     // These are percentages - 50% is the neutral mid-point
88     int amount_, dependency_;
89 
90     // The darker bar that grows to match 'amount'. If you watch
91     // the behaviour of this in the original Syndicate it grows from
92     // the dependency line to meet the currently set 'amount'. Once the
93     // two are equal it disappears and the 'amount' starts
94     // moving towards the dependency line.
95     int effect_;
96 
97     // Given a percentage returns that % of 1 to 2
98     // i.e. instead of 0 to 2
part_of_two(int percentage)99     float part_of_two(int percentage) const
100     {
101         return (((float)percentage)/100.0f) + 1.0f;
102     }
103 
104     enum IPADir {
105         IPA_boost,
106         IPA_reduce
107     };
direction()108     IPADir direction() const
109         { return amount_ - dependency_ >= 0 ? IPA_boost : IPA_reduce; }
110 
111     int getMagnitude() const;
112 
113     // A one second timer, IPA's seem to adjust themselves
114     // about once a second
115     fs_utils::Timer effect_timer_; // every second
116     fs_utils::Timer dependency_timer_; // once every 4.5 seconds
117 };
118 
119 #endif
120