Debian Codegraph @

src/live_sprite.cpp

raw
1 /**
2 * Displayed sprite
3
4 * Copyright (C) 1997, 1998, 1999, 2002, 2003 Seth A. Robinson
5 * Copyright (C) 2005, 2007, 2008, 2009, 2014, 2015 Sylvain Beucler
6
7 * This file is part of GNU FreeDink
8
9 * GNU FreeDink is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 3 of the
12 * License, or (at your option) any later version.
13
14 * GNU FreeDink is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "live_sprite.h"
29 #include "live_sprites_manager.h"
30 #include "gfx_sprites.h"
31 #include "dinkini.h" /* check_seq_status */
32 #include "log.h"
33
34 /**
35 * Get the current graphic (current sequence/current frame) for sprite
36 * 'sprite_no'
37 */
38 int getpic(int sprite_no)
39 {
40 if (spr[sprite_no].pseq == 0)
41 return 0;
42
43 if (spr[sprite_no].pseq >= MAX_SEQUENCES)
44 {
45 log_error("Sequence %d? But max is %d!", spr[sprite_no].pseq, MAX_SEQUENCES);
46 return 0;
47 }
48
49 return seq[spr[sprite_no].pseq].frame[spr[sprite_no].pframe];
50 }
51
52 /**
53 * Checks for all seq's used by the (base) commands
54 * Game only
55 */
56 void check_sprite_status_full(int sprite_no)
57 {
58 //is sprite in memory?
59 check_seq_status(spr[sprite_no].pseq);
60
61 if (spr[sprite_no].base_walk > -1)
62 check_base(spr[sprite_no].base_walk);
63 }
64
65
66 /* Editor only */
67 void check_sprite_status(int h)
68 {
69 //is sprite in memory?
70 if (spr[h].pseq > 0)
71 {
72 // Msg("Smartload: Loading seq %d..", spr[h].seq);
73 if (seq[spr[h].pseq].frame[1] == 0)
74 {
75 if (seq[spr[h].pseq].is_active)
76 figure_out(seq[spr[h].pseq].ini);
77 else
78 log_error("Error: sprite %d references non-existent sequence %d",
79 spr[h].sp_index, spr[h].pseq);
80 }
81 else
82 {
83 //it's been loaded before.. is it lost or still there?
84 }
85 }
86 }
87
88 void live_sprite_set_kill_start(int h, Uint32 thisTickCount) {
89 //inc delay, used by "skip" by all sprites
90 /* box_crap = k[getpic(h)].box; */
91 if (spr[h].kill_ttl > 0 && spr[h].kill_start == 0) {
92 spr[h].kill_start = thisTickCount;
93 }
94 }
95
96 bool live_sprite_is_expired(int h, Uint32 thisTickCount) {
97 return spr[h].kill_ttl > 0 && (spr[h].kill_start + spr[h].kill_ttl < thisTickCount);
98 }
99
100 /**
101 * Play live sprite sequence.
102 * Set *p_isHitting to true if hit a 'special' frame
103 */
104 void live_sprite_animate(int h, Uint32 thisTickCount, bool* p_isHitting) {
105 if (spr[h].reverse) {
106 //reverse instructions
107 if (spr[h].seq > 0) {
108 if (spr[h].frame < 1) {
109 // new anim
110 spr[h].pseq = spr[h].seq;
111 spr[h].pframe = seq[spr[h].seq].len;
112 spr[h].frame = seq[spr[h].seq].len;
113 if (spr[h].frame_delay != 0)
114 spr[h].delay = (thisTickCount+ spr[h].frame_delay);
115 else
116 spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[seq[spr[h].seq].len]);
117 } else {
118 // not new anim
119 //is it time?
120 if (thisTickCount > spr[h].delay) {
121 spr[h].frame--;
122 if (spr[h].frame_delay != 0)
123 spr[h].delay = (thisTickCount + spr[h].frame_delay);
124 else
125 spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[spr[h].frame]);
126
127 spr[h].pseq = spr[h].seq;
128 spr[h].pframe = spr[h].frame;
129
130 if (seq[spr[h].seq].frame[spr[h].frame] < 2) {
131 spr[h].pseq = spr[h].seq;
132 spr[h].pframe = spr[h].frame+1;
133
134 spr[h].frame = 0;
135 spr[h].seq_orig = spr[h].seq;
136 spr[h].seq = 0;
137 spr[h].nocontrol = /*false*/0;
138 }
139
140 if (spr[h].seq > 0 && seq[spr[h].seq].special[spr[h].frame] == 1)
141 *p_isHitting = true;
142 }
143 }
144 }
145 } else {
146 if (spr[h].seq > 0 && spr[h].picfreeze == 0) {
147 if (spr[h].frame < 1) {
148 // new anim
149 spr[h].pseq = spr[h].seq;
150 spr[h].pframe = 1;
151 spr[h].frame = 1;
152 if (spr[h].frame_delay != 0)
153 spr[h].delay = thisTickCount + spr[h].frame_delay;
154 else
155 spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[1]);
156 } else {
157 // not new anim
158 //is it time?
159 if (thisTickCount > spr[h].delay) {
160 spr[h].frame++;
161 if (spr[h].frame_delay != 0)
162 spr[h].delay = thisTickCount + spr[h].frame_delay;
163 else
164 spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[spr[h].frame]);
165
166 spr[h].pseq = spr[h].seq;
167 spr[h].pframe = spr[h].frame;
168
169 if (seq[spr[h].seq].frame[spr[h].frame] == -1) {
170 spr[h].frame = 1;
171 spr[h].pseq = spr[h].seq;
172 spr[h].pframe = spr[h].frame;
173 if (spr[h].frame_delay != 0)
174 spr[h].delay = thisTickCount + spr[h].frame_delay;
175 else
176 spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[spr[h].frame]);
177 }
178
179 if (seq[spr[h].seq].frame[spr[h].frame] < 1) {
180 spr[h].pseq = spr[h].seq;
181 spr[h].pframe = spr[h].frame-1;
182
183 spr[h].frame = 0;
184 spr[h].seq_orig = spr[h].seq;
185 spr[h].seq = 0;
186 spr[h].nocontrol = /*false*/0;
187 }
188
189 if (spr[h].seq > 0 && seq[spr[h].seq].special[spr[h].frame] == 1)
190 *p_isHitting = true;
191 }
192 }
193 }
194 }
195 }