Dumb-ways-to-memorize
2D game
parsepowerup.h
Go to the documentation of this file.
1 #ifndef __PARSE_POWER_UP_H
2 #define __PARSE_POWER_UP_H
3 
4 #include "parseobject.h"
5 #include "entity.h"
6 
7 #define POWER_TARGET_STR "target"
8 #define POWER_USE_TYPE_STR "use-type"
9 #define POWER_INTERACTION_STR "interaction"
10 #define POWER_INPUT_TYPE_STR "input-type"
11 #define POWER_ENTITY_STR "entity"
12 
13 /** Values that represent use types for power_ups */
15 {
16  INFINITE = -2, /**< An enum constant representing infinite use of a power_up, which implies activation prior to use */
17  STATIC /**< An enum constant representing static use of a power_up, which implies passive activation */
18 };
19 
20 /** Defines an alias representing the types of info the power_up needs */
21 typedef enum
22 {
23  INFO_NONE = 0x0,
24  INFO_BUTTON = 0x1,
25  INFO_MOUSE = 0x2,
27 
29 
30 typedef struct power_s power_t;
31 
32 /**
33  * The structure for our power_up system.
34  *
35  * @author Anthony Rios
36  * @date 3/30/2016
37  */
38 
39 struct power_s
40 {
41  char *name; /**< The name of the power up */
42  void (*UpdateInput)(power_t *self); /**< The function to update the input for the power_up */
43  void (*GetTarg)(entity_t *self, entity_t **targ); /**< The function which calculates who or what is the specified target */
44  void (*UpdateUse)(power_t *power); /**< The function which updates the power_up */
45  void (*DoPower)(entity_t *targ, entity_t *info); /**< The function which does the power_up , called after all the updates */
46  int uses; /**< The number of times this power can get used - @see use_type_t*/
47  info_type_t info_type; /**< The type of info the powe up needs*/
48  entity_t *target; /**< Target for the power_up */
49  entity_t *info; /**< The information that the power_up uses*/
50 
51 };
52 extern power_t *gPowerUps; /**< The loaded power ups */
53 extern power_t *gCurrentPowerUp; /**< The currently loaded power_up */
54 
55 //Power Specific
56 /**
57  * Call information functions for the power_up.
58  *
59  * @param [in,out] self If non-null, the class instance that this method operates on.
60  *
61  * @author Anthony Rios
62  * @date 3/30/2016
63  */
64 void CallInfo(power_t *self);
65 
66 /**
67  * Updates a normal use power_up, with uses > 0.
68  *
69  * @param [in,out] power If non-null, the power.
70  *
71  * @author Anthony Rios
72  * @date 3/30/2016
73  */
74 void UpdateNormal(power_t *power);
75 
76 /**
77  * Updates an infinite use power_up
78  *
79  * @param [in,out] power If non-null, the power.
80  *
81  * @author Anthony Rios
82  * @date 3/30/2016
83  */
84 void UpdateInfinite(power_t *power);
85 
86 /**
87  * Gets the usetype from var, and puts it in useType.
88  *
89  * @param var The variable.
90  * @param [in,out] useType If non-null, type of the use.
91  *
92  * @return The use type.
93  *
94  * @author Anthony Rios
95  * @date 3/30/2016
96  */
97 int GetUseType(const char *var, int *useType);
98 
99 /**
100  * Parses object/str data to a power up.
101  *
102  * @param [in,out] power If non-null, the power.
103  * @param [in,out] str If non-null, the string.
104  *
105  * @return null if it fails, else a pointer to a power_t.
106  *
107  * @author Anthony Rios
108  * @date 3/30/2016
109  */
110 power_t *ParseToPowerUp(object_t *power, char *str);
111 
112 /**
113  * Searches for the first power with matching name str.
114  *
115  * @param [in,out] str If non-null, the string.
116  *
117  * @return null if it fails, else the found power.
118  *
119  * @author Anthony Rios
120  * @date 3/30/2016
121  */
122 power_t *FindPower(char *str);
123 
124 /**
125  * Uses the power, more like a macro then anything.
126  *
127  * @param [in,out] power If non-null, the power.
128  *
129  * @author Anthony Rios
130  * @date 3/30/2016
131  */
132 void UsePower(power_t *power);
133 
134 //Interactions
135 /**
136  * Moves the target to position given by info.
137  *
138  * @param [in,out] targ If non-null, the targ.
139  * @param [in,out] info If non-null, the information.
140  *
141  * @author Anthony Rios
142  * @date 3/30/2016
143  */
144 void Move(entity_t *targ, entity_t *info);
145 
146 /**
147  * Destroys target.
148  *
149  * @param [in,out] targ If non-null, the targ.
150  * @param [in,out] info If non-null, the information.
151  *
152  * @author Anthony Rios
153  * @date 3/30/2016
154  */
155 void Destroy(entity_t *targ, entity_t *info);
156 
157 /**
158  * Spawns entity from info to position of targ.
159  *
160  * @param [in,out] targ If non-null, the targ.
161  * @param [in,out] info If non-null, the information.
162  *
163  * @author Anthony Rios
164  * @date 3/30/2016
165  */
166 void Spawn(entity_t *targ, entity_t *info);
167 
168 /**
169  * Edits the target with values from info.
170  *
171  * @param [in,out] targ If non-null, the targ.
172  * @param [in,out] info If non-null, the information.
173  *
174  * @author Anthony Rios
175  * @date 3/30/2016
176  */
177 void Edit(entity_t *targ, entity_t *info);
178 
179 /**
180  * Nullifies the entity by removing the think function of targ.
181  *
182  * @param [in,out] targ If non-null, the targ.
183  * @param [in,out] info If non-null, the information.
184  *
185  * @author Anthony Rios
186  * @date 3/30/2016
187  */
188 void Nullify(entity_t *targ, entity_t *info);
189 
190 //Interactions Array
191 extern char *InteractionNames[]; /**< The interaction names, which deal with what function power does */
192 extern void (*InteractionSymbols[]); /**< The interaction symbol for the functions */
193 
194 #endif
info_type_t info_type
Definition: parsepowerup.h:47
char * name
Definition: parsepowerup.h:41
power_t * gPowerUps
Definition: game.c:42
void Spawn(entity_t *targ, entity_t *info)
Definition: parsepowerup.c:41
void *[] InteractionSymbols
Definition: parsepowerup.c:14
void Edit(entity_t *targ, entity_t *info)
Definition: parsepowerup.c:68
entity_t * info
Definition: parsepowerup.h:49
power_t * gCurrentPowerUp
Definition: parsepowerup.c:16
char * InteractionNames[]
Definition: parsepowerup.c:13
void Destroy(entity_t *targ, entity_t *info)
Definition: parsepowerup.c:32
void(* DoPower)(entity_t *targ, entity_t *info)
Definition: parsepowerup.h:45
void(* GetTarg)(entity_t *self, entity_t **targ)
Definition: parsepowerup.h:43
void CallInfo(power_t *self)
Definition: parsepowerup.c:142
void Nullify(entity_t *targ, entity_t *info)
Definition: parsepowerup.c:90
void(* UpdateInput)(power_t *self)
Definition: parsepowerup.h:42
int uses
Definition: parsepowerup.h:46
void UsePower(power_t *power)
Definition: parsepowerup.c:285
void UpdateNormal(power_t *power)
Definition: parsepowerup.c:99
int GetUseType(const char *var, int *useType)
Definition: parsepowerup.c:124
info_type_t
Definition: parsepowerup.h:21
void Move(entity_t *targ, entity_t *info)
Definition: parsepowerup.c:20
void UpdateInfinite(power_t *power)
Definition: parsepowerup.c:119
use_type_t
Definition: parsepowerup.h:14
power_t * ParseToPowerUp(object_t *power, char *str)
Definition: parsepowerup.c:157
void(* UpdateUse)(power_t *power)
Definition: parsepowerup.h:44
power_t * FindPower(char *str)
Definition: parsepowerup.c:264
entity_t * target
Definition: parsepowerup.h:48