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.31 by root, Thu Sep 17 01:57:31 2009 UTC vs.
Revision 1.44 by root, Sun Nov 18 15:19:47 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008 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,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{
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.
97animate_object (object *op, int dir) 92animate_object (object *op, int dir)
98{ 93{
99 int max_state; /* Max animation state object should be drawn in */ 94 int max_state; /* Max animation state object should be drawn in */
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 || !op->anim_frames ())
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 {
111 dir = op->head->direction; 106 dir = op->head->direction;
112 107
113 if (NUM_ANIMATIONS (op) == NUM_ANIMATIONS (op->head)) 108 if (op->anim_frames () == op->head->anim_frames ())
114 op->state = op->head->state; 109 op->state = op->head->state;
115 else 110 else
116 ++op->state; 111 ++op->state;
117 } 112 }
118 else 113 else
119 ++op->state; /* increase draw state */ 114 ++op->state; /* increase draw state */
120 115
121 /* 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
122 * animations. Otherwise, we can use all the animations. 117 * animations. Otherwise, we can use all the animations.
123 */ 118 */
124 max_state = NUM_ANIMATIONS (op) / NUM_FACINGS (op); 119 max_state = op->anim_frames () / op->anim_facings ();
125 base_state = 0; 120 base_state = 0;
126 /* 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
127 * of the animations were left facing, the second half right facing. 122 * of the animations were left facing, the second half right facing.
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
133 if (dir > 0) 128 if (dir > 0)
134 switch (NUM_FACINGS (op)) 129 switch (op->anim_facings ())
135 { 130 {
136 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;
137 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;
138 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;
139 } 134 }
140 else 135 else
141 base_state = 0; 136 base_state = 0;
142 137
143 /* If beyond drawable states, reset */ 138 /* If beyond drawable states, reset */
144 if (op->state >= max_state) 139 if (op->state >= max_state)
145 op->state = 0; 140 op->state = 0;
146 141
147 SET_ANIMATION (op, op->state + base_state); 142 op->set_anim_frame (op->state + base_state);
148 143
149 if (op->face == blank_face) 144 if (op->face == blank_face)
150 op->invisible = 1; 145 op->invisible = 1;
151 146
152 /* This block covers monsters (eg, pixies) which are supposed to 147 /* This block covers monsters (eg, pixies) which are supposed to
157 else if (op->type != PLAYER && op->arch->flag [FLAG_ALIVE]) 152 else if (op->type != PLAYER && op->arch->flag [FLAG_ALIVE])
158 { 153 {
159 if (op->face == 0) 154 if (op->face == 0)
160 { 155 {
161 op->invisible = 1; 156 op->invisible = 1;
162 CLEAR_FLAG (op, FLAG_ALIVE); 157 op->clr_flag (FLAG_ALIVE);
163 } 158 }
164 else 159 else
165 { 160 {
166 op->invisible = 0; 161 op->invisible = 0;
167 SET_FLAG (op, FLAG_ALIVE); 162 op->set_flag (FLAG_ALIVE);
168 } 163 }
169 } 164 }
170 165
171 if (op->more) 166 if (op->more)
172 animate_object (op->more, dir); 167 animate_object (op->more, dir);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines