1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_anim_c = |
|
|
4 | * "$Id: anim.C,v 1.7 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002-2003 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002-2003 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | /* This file contains animation related code. */ |
24 | /* This file contains animation related code. */ |
31 | |
25 | |
32 | #include <global.h> |
26 | #include <global.h> |
33 | #include <stdio.h> |
27 | #include <stdio.h> |
34 | |
28 | |
35 | std::vector < Animations > animations; |
29 | std::vector<Animations> animations; |
36 | |
30 | |
37 | void |
31 | void |
38 | free_all_anim (void) |
32 | free_all_anim (void) |
39 | { |
33 | { |
40 | for (int i = 0; i <= num_animations; i++) |
34 | for (int i = 0; i <= num_animations; i++) |
… | |
… | |
68 | /* set the name so we don't try to dereferance null. |
62 | /* set the name so we don't try to dereferance null. |
69 | * Put # at start so it will be first in alphabetical |
63 | * Put # at start so it will be first in alphabetical |
70 | * order. |
64 | * order. |
71 | */ |
65 | */ |
72 | { |
66 | { |
73 | Animations |
67 | Animations anim0; |
74 | anim0; |
|
|
75 | |
68 | |
76 | anim0.name = "###none"; |
69 | anim0.name = "###none"; |
77 | anim0.num_animations = 1; |
70 | anim0.num_animations = 1; |
78 | anim0.faces = (Fontindex *) malloc (sizeof (Fontindex)); |
71 | anim0.faces = (Fontindex *) malloc (sizeof (Fontindex)); |
79 | anim0.faces[0] = 0; |
72 | anim0.faces[0] = 0; |
… | |
… | |
102 | LOG (llevError, "Didn't get a mina before %s\n", buf); |
95 | LOG (llevError, "Didn't get a mina before %s\n", buf); |
103 | num_frames = 0; |
96 | num_frames = 0; |
104 | } |
97 | } |
105 | num_animations++; |
98 | num_animations++; |
106 | |
99 | |
107 | Animations |
100 | Animations anim; |
108 | anim; |
|
|
109 | |
101 | |
110 | anim.name = buf + 5; |
102 | anim.name = buf + 5; |
111 | anim.num = num_animations; /* for bsearch */ |
103 | anim.num = num_animations; /* for bsearch */ |
112 | anim.facings = 1; |
104 | anim.facings = 1; |
113 | animations.push_back (anim); |
105 | animations.push_back (anim); |
… | |
… | |
190 | int |
182 | int |
191 | base_state; /* starting index # to draw from */ |
183 | base_state; /* starting index # to draw from */ |
192 | |
184 | |
193 | if (!op->animation_id || !NUM_ANIMATIONS (op)) |
185 | if (!op->animation_id || !NUM_ANIMATIONS (op)) |
194 | { |
186 | { |
195 | LOG (llevError, "Object lacks animation.\n"); |
187 | LOG (llevError, "Object %s lacks animation.\n", op->debug_desc ()); |
196 | dump_object (op); |
|
|
197 | return; |
188 | return; |
198 | } |
189 | } |
|
|
190 | |
199 | if (op->head) |
191 | if (op->head) |
200 | { |
192 | { |
201 | dir = op->head->direction; |
193 | dir = op->head->direction; |
202 | |
194 | |
203 | if (NUM_ANIMATIONS (op) == NUM_ANIMATIONS (op->head)) |
195 | if (NUM_ANIMATIONS (op) == NUM_ANIMATIONS (op->head)) |
204 | op->state = op->head->state; |
196 | op->state = op->head->state; |
205 | else |
197 | else |
206 | ++op->state; |
198 | ++op->state; |
207 | } |
199 | } |
208 | else |
200 | else |
209 | { |
|
|
210 | ++op->state; /* increase draw state */ |
201 | ++op->state; /* increase draw state */ |
211 | } |
|
|
212 | |
202 | |
213 | /* If object is turning, then max animation state is half through the |
203 | /* If object is turning, then max animation state is half through the |
214 | * animations. Otherwise, we can use all the animations. |
204 | * animations. Otherwise, we can use all the animations. |
215 | */ |
205 | */ |
216 | max_state = NUM_ANIMATIONS (op) / NUM_FACINGS (op); |
206 | max_state = NUM_ANIMATIONS (op) / NUM_FACINGS (op); |
… | |
… | |
219 | * of the animations were left facing, the second half right facing. |
209 | * of the animations were left facing, the second half right facing. |
220 | * Note in old the is_turning, it was set so that the animation for a monster |
210 | * Note in old the is_turning, it was set so that the animation for a monster |
221 | * was always towards the enemy - now it is whatever direction the monster |
211 | * was always towards the enemy - now it is whatever direction the monster |
222 | * is facing. |
212 | * is facing. |
223 | */ |
213 | */ |
|
|
214 | |
224 | if (NUM_FACINGS (op) == 2) |
215 | if (NUM_FACINGS (op) == 2) |
225 | { |
216 | { |
226 | if (dir < 5) |
217 | if (dir < 5) |
227 | base_state = 0; |
218 | base_state = 0; |
228 | else |
219 | else |