… | |
… | |
40 | } |
40 | } |
41 | |
41 | |
42 | void |
42 | void |
43 | init_anim (void) |
43 | init_anim (void) |
44 | { |
44 | { |
45 | char |
|
|
46 | buf[MAX_BUF]; |
45 | char buf[MAX_BUF]; |
47 | FILE * |
46 | FILE * fp; |
48 | fp; |
|
|
49 | static int |
|
|
50 | anim_init = 0; |
47 | static int anim_init = 0; |
51 | int |
|
|
52 | num_frames = 0, faces[MAX_ANIMATIONS], i; |
48 | int num_frames = 0, faces[MAX_ANIMATIONS], i; |
53 | |
49 | |
54 | if (anim_init) |
50 | if (anim_init) |
55 | return; |
51 | return; |
|
|
52 | |
56 | num_animations = 0; |
53 | num_animations = 0; |
57 | /* Make a default. New animations start at one, so if something |
54 | /* Make a default. New animations start at one, so if something |
58 | * thinks it is animated but hasn't set the animation_id properly, |
55 | * thinks it is animated but hasn't set the animation_id properly, |
59 | * it will have a default value that should be pretty obvious. |
56 | * it will have a default value that should be pretty obvious. |
60 | */ |
57 | */ |
… | |
… | |
74 | animations.push_back (anim0); |
71 | animations.push_back (anim0); |
75 | } |
72 | } |
76 | |
73 | |
77 | sprintf (buf, "%s/animations", settings.datadir); |
74 | sprintf (buf, "%s/animations", settings.datadir); |
78 | LOG (llevDebug, "Reading animations from %s...\n", buf); |
75 | LOG (llevDebug, "Reading animations from %s...\n", buf); |
|
|
76 | |
79 | if ((fp = fopen (buf, "r")) == NULL) |
77 | if ((fp = fopen (buf, "r")) == NULL) |
80 | { |
78 | { |
81 | LOG (llevError, "Cannot open animations file %s: %s\n", buf, strerror (errno)); |
79 | LOG (llevError, "Cannot open animations file %s: %s\n", buf, strerror (errno)); |
82 | exit (-1); |
80 | exit (-1); |
83 | } |
81 | } |
|
|
82 | |
84 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
83 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
85 | { |
84 | { |
86 | if (*buf == '#') |
85 | if (*buf == '#') |
87 | continue; |
86 | continue; |
|
|
87 | |
88 | /* Kill the newline */ |
88 | /* Kill the newline */ |
89 | buf[strlen (buf) - 1] = '\0'; |
89 | buf[strlen (buf) - 1] = '\0'; |
90 | if (!strncmp (buf, "anim ", 5)) |
90 | if (!strncmp (buf, "anim ", 5)) |
91 | { |
91 | { |
92 | if (num_frames) |
92 | if (num_frames) |
93 | { |
93 | { |
94 | LOG (llevError, "Didn't get a mina before %s\n", buf); |
94 | LOG (llevError, "Didn't get a mina before %s\n", buf); |
95 | num_frames = 0; |
95 | num_frames = 0; |
96 | } |
96 | } |
|
|
97 | |
97 | num_animations++; |
98 | num_animations++; |
98 | |
99 | |
99 | animation anim; |
100 | animation anim; |
100 | |
101 | |
101 | anim.name = buf + 5; |
102 | anim.name = buf + 5; |
… | |
… | |
104 | animations.push_back (anim); |
105 | animations.push_back (anim); |
105 | } |
106 | } |
106 | else if (!strncmp (buf, "mina", 4)) |
107 | else if (!strncmp (buf, "mina", 4)) |
107 | { |
108 | { |
108 | animations[num_animations].faces = (uint16 *) malloc (sizeof (uint16) * num_frames); |
109 | animations[num_animations].faces = (uint16 *) malloc (sizeof (uint16) * num_frames); |
|
|
110 | |
109 | for (i = 0; i < num_frames; i++) |
111 | for (i = 0; i < num_frames; i++) |
110 | animations[num_animations].faces[i] = faces[i]; |
112 | animations[num_animations].faces[i] = faces[i]; |
|
|
113 | |
111 | animations[num_animations].num_animations = num_frames; |
114 | animations[num_animations].num_animations = num_frames; |
112 | if (num_frames % animations[num_animations].facings) |
115 | if (num_frames % animations[num_animations].facings) |
113 | { |
|
|
114 | LOG (llevDebug, "Animation %s frame numbers (%d) is not a multiple of facings (%d)\n", |
116 | LOG (llevDebug, "Animation %s frame numbers (%d) is not a multiple of facings (%d)\n", |
115 | &animations[num_animations].name, num_frames, animations[num_animations].facings); |
117 | &animations[num_animations].name, num_frames, animations[num_animations].facings); |
116 | } |
118 | |
117 | num_frames = 0; |
119 | num_frames = 0; |
118 | } |
120 | } |
119 | else if (!strncmp (buf, "facings", 7)) |
121 | else if (!strncmp (buf, "facings ", 8)) |
120 | { |
122 | { |
121 | if (!(animations[num_animations].facings = atoi (buf + 7))) |
123 | if (!(animations[num_animations].facings = atoi (buf + 8))) |
122 | { |
124 | { |
123 | LOG (llevDebug, "Animation %s has 0 facings, line=%s\n", &animations[num_animations].name, buf); |
125 | LOG (llevDebug, "Animation %s has 0 facings, line=%s\n", &animations[num_animations].name, buf); |
124 | animations[num_animations].facings = 1; |
126 | animations[num_animations].facings = 1; |
125 | } |
127 | } |
126 | |
128 | |
127 | } |
129 | } |
128 | else |
130 | else |
129 | { |
131 | { |
130 | if (!(faces[num_frames++] = FindFace (buf, 0))) |
132 | if (!(faces[num_frames++] = face_find (buf))) |
131 | LOG (llevDebug, "Could not find face %s for animation %s\n", buf, &animations[num_animations].name); |
133 | LOG (llevDebug, "Could not find face %s for animation %s\n", buf, &animations[num_animations].name); |
132 | } |
134 | } |
133 | } |
135 | } |
|
|
136 | |
134 | fclose (fp); |
137 | fclose (fp); |
135 | LOG (llevDebug, "done. got (%d)\n", num_animations); |
138 | LOG (llevDebug, "done. got (%d)\n", num_animations); |
136 | } |
139 | } |
137 | |
140 | |
138 | static int |
141 | static int |
… | |
… | |
200 | /* 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 |
201 | * animations. Otherwise, we can use all the animations. |
204 | * animations. Otherwise, we can use all the animations. |
202 | */ |
205 | */ |
203 | max_state = NUM_ANIMATIONS (op) / NUM_FACINGS (op); |
206 | max_state = NUM_ANIMATIONS (op) / NUM_FACINGS (op); |
204 | base_state = 0; |
207 | base_state = 0; |
205 | /* at least in the older aniamtions that used is_turning, the first half |
208 | /* at least in the older animations that used is_turning, the first half |
206 | * of the animations were left facing, the second half right facing. |
209 | * of the animations were left facing, the second half right facing. |
207 | * 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 |
208 | * 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 |
209 | * is facing. |
212 | * is facing. |
210 | */ |
213 | */ |
… | |
… | |
243 | /* This block covers monsters (eg, pixies) which are supposed to |
246 | /* This block covers monsters (eg, pixies) which are supposed to |
244 | * cycle from visible to invisible and back to being visible. |
247 | * cycle from visible to invisible and back to being visible. |
245 | * as such, disable it for players, as then players would become |
248 | * as such, disable it for players, as then players would become |
246 | * visible. |
249 | * visible. |
247 | */ |
250 | */ |
248 | else if (op->type != PLAYER && QUERY_FLAG ((&op->arch->clone), FLAG_ALIVE)) |
251 | else if (op->type != PLAYER && op->arch->clone.flag [FLAG_ALIVE]) |
249 | { |
252 | { |
250 | if (op->face->number == 0) |
253 | if (op->face == 0) |
251 | { |
254 | { |
252 | op->invisible = 1; |
255 | op->invisible = 1; |
253 | CLEAR_FLAG (op, FLAG_ALIVE); |
256 | CLEAR_FLAG (op, FLAG_ALIVE); |
254 | } |
257 | } |
255 | else |
258 | else |