ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/anim.C
(Generate patch)

Comparing deliantra/server/common/anim.C (file contents):
Revision 1.28 by root, Thu Nov 8 19:43:23 2007 UTC vs.
Revision 1.43 by root, Sat Nov 17 23:39:59 2018 UTC

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 (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / 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,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002-2003 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 10 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
20 * 22 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 24 */
23 25
24/* This file contains animation related code. */ 26/* This file contains animation related code. */
25 27
26#include <global.h> 28#include <global.h>
27#include <stdio.h> 29#include <stdio.h>
28 30
29animhash_t animhash; 31static animhash_t animhash;
30std::vector<animation> animations; 32std::vector<animation> animations;
31 33
32void 34void
33animation::resize (int new_size) 35animation::resize (int new_size)
34{ 36{
35 sfree <faceidx> (faces, num_animations); 37 sfree<faceidx> (faces, num_animations);
36 num_animations = new_size; 38 num_animations = new_size;
37 faces = salloc<faceidx> (num_animations); 39 faces = salloc<faceidx> (num_animations);
38} 40}
39 41
40animation & 42animation &
55 animhash.insert (std::make_pair (anim.name, anim.number)); 57 animhash.insert (std::make_pair (anim.name, anim.number));
56 58
57 return anim; 59 return anim;
58} 60}
59 61
62/* Tries to find the animation id that matches name. Returns an integer match
63 * 0 if no match found (animation 0 is initialised as the 'bug' face
64 */
60animation & 65animation &
61animation::find (const char *name) 66animation::find (const char *name)
62{ 67{
63 if (!name) 68 if (!name)
64 return animations [0]; 69 return animations [0];
66 animhash_t::iterator i = animhash.find (name); 71 animhash_t::iterator i = animhash.find (name);
67 return animations [i == animhash.end () ? 0 : i->second]; 72 return animations [i == animhash.end () ? 0 : i->second];
68} 73}
69 74
70void 75void
71init_anim (void) 76init_anim ()
72{ 77{
73 animation &anim0 = animation::create ("none", 1, 0); 78 animation &anim0 = animation::create ("none", 1, 0);
74 anim0.faces [0] = 0; 79 anim0.faces [0] = 0;
75}
76
77/* Tries to find the animation id that matches name. Returns an integer match
78 * 0 if no match found (animation 0 is initialised as the 'bug' face
79 */
80//TODO: nuke this function and replace all occurences by animations::find
81int
82find_animation (const char *name)
83{
84 return animation::find (name).number;
85} 80}
86 81
87/* 82/*
88 * animate_object(object) updates the face-variable of an object. 83 * animate_object(object) updates the face-variable of an object.
89 * If the object is the head of a multi-object, all objects are animated. 84 * If the object is the head of a multi-object, all objects are animated.
100 int base_state; /* starting index # to draw from */ 95 int base_state; /* starting index # to draw from */
101 96
102 if (!op->animation_id || !NUM_ANIMATIONS (op)) 97 if (!op->animation_id || !NUM_ANIMATIONS (op))
103 { 98 {
104 LOG (llevError, "Object %s lacks animation.\n", op->debug_desc ()); 99 LOG (llevError, "Object %s lacks animation.\n", op->debug_desc ());
105 CLEAR_FLAG (op, FLAG_ANIMATE); 100 op->clr_flag (FLAG_ANIMATE);
106 return; 101 return;
107 } 102 }
108 103
109 if (op->head_ () != op) 104 if (op->head_ () != op)
110 { 105 {
128 * 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
129 * 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
130 * is facing. 125 * is facing.
131 */ 126 */
132 127
128 if (dir > 0)
133 if (NUM_FACINGS (op) == 2) 129 switch (NUM_FACINGS (op))
134 { 130 {
135 if (dir < 5) 131 case 2: base_state = ((dir - 1) / (8 / 2)) * (NUM_ANIMATIONS (op) / 2); break;
132 case 4: base_state = ((dir - 1) / (8 / 4)) * (NUM_ANIMATIONS (op) / 4); break;
133 case 8: base_state = ((dir - 1) / (8 / 8)) * (NUM_ANIMATIONS (op) / 8); break;
134 }
135 else
136 base_state = 0; 136 base_state = 0;
137 else
138 base_state = NUM_ANIMATIONS (op) / 2;
139 }
140 else if (NUM_FACINGS (op) == 4)
141 {
142 if (dir == 0)
143 base_state = 0;
144 else
145 base_state = ((dir - 1) / 2) * (NUM_ANIMATIONS (op) / 4);
146 }
147 else if (NUM_FACINGS (op) == 8)
148 {
149 if (dir == 0)
150 base_state = 0;
151 else
152 base_state = (dir - 1) * (NUM_ANIMATIONS (op) / 8);
153 }
154 137
155 /* If beyond drawable states, reset */ 138 /* If beyond drawable states, reset */
156 if (op->state >= max_state) 139 if (op->state >= max_state)
157 op->state = 0; 140 op->state = 0;
158 141
169 else if (op->type != PLAYER && op->arch->flag [FLAG_ALIVE]) 152 else if (op->type != PLAYER && op->arch->flag [FLAG_ALIVE])
170 { 153 {
171 if (op->face == 0) 154 if (op->face == 0)
172 { 155 {
173 op->invisible = 1; 156 op->invisible = 1;
174 CLEAR_FLAG (op, FLAG_ALIVE); 157 op->clr_flag (FLAG_ALIVE);
175 } 158 }
176 else 159 else
177 { 160 {
178 op->invisible = 0; 161 op->invisible = 0;
179 SET_FLAG (op, FLAG_ALIVE); 162 op->set_flag (FLAG_ALIVE);
180 } 163 }
181 } 164 }
182 165
183 if (op->more) 166 if (op->more)
184 animate_object (op->more, dir); 167 animate_object (op->more, dir);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines