1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
… | |
… | |
91 | animate_object (object *op, int dir) |
92 | animate_object (object *op, int dir) |
92 | { |
93 | { |
93 | int max_state; /* Max animation state object should be drawn in */ |
94 | int max_state; /* Max animation state object should be drawn in */ |
94 | int base_state; /* starting index # to draw from */ |
95 | int base_state; /* starting index # to draw from */ |
95 | |
96 | |
96 | if (!op->animation_id || !NUM_ANIMATIONS (op)) |
97 | if (!op->animation_id || !op->anim_frames ()) |
97 | { |
98 | { |
98 | LOG (llevError, "Object %s lacks animation.\n", op->debug_desc ()); |
99 | LOG (llevError, "Object %s lacks animation.\n", op->debug_desc ()); |
99 | op->clr_flag (FLAG_ANIMATE); |
100 | op->clr_flag (FLAG_ANIMATE); |
100 | return; |
101 | return; |
101 | } |
102 | } |
102 | |
103 | |
103 | if (op->head_ () != op) |
104 | if (op->head_ () != op) |
104 | { |
105 | { |
105 | dir = op->head->direction; |
106 | dir = op->head->direction; |
106 | |
107 | |
107 | if (NUM_ANIMATIONS (op) == NUM_ANIMATIONS (op->head)) |
108 | if (op->anim_frames () == op->head->anim_frames ()) |
108 | op->state = op->head->state; |
109 | op->state = op->head->state; |
109 | else |
110 | else |
110 | ++op->state; |
111 | ++op->state; |
111 | } |
112 | } |
112 | else |
113 | else |
113 | ++op->state; /* increase draw state */ |
114 | ++op->state; /* increase draw state */ |
114 | |
115 | |
115 | /* If object is turning, then max animation state is half through the |
116 | /* If object is turning, then max animation state is half through the |
116 | * animations. Otherwise, we can use all the animations. |
117 | * animations. Otherwise, we can use all the animations. |
117 | */ |
118 | */ |
118 | max_state = NUM_ANIMATIONS (op) / NUM_FACINGS (op); |
119 | max_state = op->anim_frames () / op->anim_facings (); |
119 | base_state = 0; |
120 | base_state = 0; |
120 | /* at least in the older animations that used is_turning, the first half |
121 | /* at least in the older animations that used is_turning, the first half |
121 | * of the animations were left facing, the second half right facing. |
122 | * of the animations were left facing, the second half right facing. |
122 | * Note in old the is_turning, it was set so that the animation for a monster |
123 | * Note in old the is_turning, it was set so that the animation for a monster |
123 | * was always towards the enemy - now it is whatever direction the monster |
124 | * was always towards the enemy - now it is whatever direction the monster |
124 | * is facing. |
125 | * is facing. |
125 | */ |
126 | */ |
126 | |
127 | |
127 | if (dir > 0) |
128 | if (dir > 0) |
128 | switch (NUM_FACINGS (op)) |
129 | switch (op->anim_facings ()) |
129 | { |
130 | { |
130 | case 2: base_state = ((dir - 1) / (8 / 2)) * (NUM_ANIMATIONS (op) / 2); break; |
131 | case 2: base_state = ((dir - 1) / (8 / 2)) * (op->anim_frames () / 2); break; |
131 | case 4: base_state = ((dir - 1) / (8 / 4)) * (NUM_ANIMATIONS (op) / 4); break; |
132 | case 4: base_state = ((dir - 1) / (8 / 4)) * (op->anim_frames () / 4); break; |
132 | case 8: base_state = ((dir - 1) / (8 / 8)) * (NUM_ANIMATIONS (op) / 8); break; |
133 | case 8: base_state = ((dir - 1) / (8 / 8)) * (op->anim_frames () / 8); break; |
133 | } |
134 | } |
134 | else |
135 | else |
135 | base_state = 0; |
136 | base_state = 0; |
136 | |
137 | |
137 | /* If beyond drawable states, reset */ |
138 | /* If beyond drawable states, reset */ |
138 | if (op->state >= max_state) |
139 | if (op->state >= max_state) |
139 | op->state = 0; |
140 | op->state = 0; |
140 | |
141 | |
141 | SET_ANIMATION (op, op->state + base_state); |
142 | op->set_anim_frame (op->state + base_state); |
142 | |
143 | |
143 | if (op->face == blank_face) |
144 | if (op->face == blank_face) |
144 | op->invisible = 1; |
145 | op->invisible = 1; |
145 | |
146 | |
146 | /* This block covers monsters (eg, pixies) which are supposed to |
147 | /* This block covers monsters (eg, pixies) which are supposed to |