-
Notifications
You must be signed in to change notification settings - Fork 0
/
acarcher.c
177 lines (137 loc) · 4.38 KB
/
acarcher.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Dragon - Archer actor
* Copyright (C) 2017 Sandor Zsuga (Jubatian)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "acarcher.h"
#include "acsupp.h"
#include "dragon.h"
#include "passable.h"
#include "eproj.h"
#include "fireball.h"
#include "random.h"
#include "sound.h"
#include "gstat.h"
#include <uzebox.h>
/*
** Processes the passed archer actor. Returns the health of the actor: if this
** is zero, the actor is destroyed.
*/
auint acarcher_process(mapact_t* actor)
{
auint rnd = random_get();
auint vis;
asint vy;
asint vx;
auint d0 = actor->d0;
auint d1 = actor->d1;
uint16 axp = actor->spr.xpos;
uint16 ayp = actor->spr.ypos;
/*
** Archer's layout:
**
** d0: bits 0-5: Animation frame & action timer
** bit 6: If set, shooting, otherwise idle
** bit 7: If set, on fire
** d1: bits 0-7: Health (negated as starting value is zero)
**
** Behaviour:
**
** Only active if the dragon is detectable for him. Tries to shoot arrows at
** him while attempting to stay farther away.
*/
actor->spr.xvel = 0;
if ((d0 & 0x80U) != 0U){ /* On fire: Flee! (don't caring about ledges or whatever) */
if (dragon_spr.xpos < axp){
actor->spr.xvel = 2;
}else{
actor->spr.xvel = -2;
}
}else if ((d0 & 0x40U) != 0U){ /* Firing */
if ((d0 & 0x0FU) == 0x00U){
if (dragon_spr.xpos < axp){ vx = -6 + (asint)(rnd & 1U); }
else { vx = 6 - (asint)(rnd & 1U); }
vy = acsupp_getshotvy(axp, ayp - 7U, &dragon_spr, vx);
eproj_new(axp, ayp - 7U, vx, vy, EPROJ_ARROW);
d0 &= ~0x40U;
sound_effect(SOUND_ARROW, 0x38U);
}
}else{ /* Look out for the dragon */
vis = acsupp_isvisible(&(actor->spr), &dragon_spr);
if (vis || (!dragon_issilent())){
vx = 0;
if ( (actor->spr.xacc == 0) && /* Not running against a wall */
((rnd & 0x3FU) != 0U) ){ /* Occasionally shoot even while moving away */
if ((dragon_spr.ypos) < (ayp + 16U)){ /* Dragon in level or above: danger! */
if ((dragon_spr.xpos) < (axp)){
if ((dragon_spr.xpos + 80U - (rnd & 15U)) > (axp)){ /* Within 80 px on the left */
vx = 2;
}else if ((dragon_spr.xpos + 90U - (rnd & 15U)) < (axp)){ /* Farther than 90 px on the left */
vx = -1;
}else{}
}else{
if ((dragon_spr.xpos) < (axp + 80U - (rnd & 15U))){ /* Within 80 px on the right */
vx = -2;
}else if ((dragon_spr.xpos) > (axp + 90U - (rnd & 15U))){ /* Farther than 90 px on the right */
vx = 1;
}else{}
}
}else{
if ((dragon_spr.ypos) > (ayp + 24U)){ /* Dragon is below: Get as near as possible */
if (dragon_spr.xpos < axp){
vx = -1;
}else if (dragon_spr.xpos > axp){
vx = 1;
}else{}
}
}
}
if ( (vx == 0) && vis ){ /* No movement and dragon is visible: Shoot! */
d0 = 0x40U | 0x01U;
}else{
actor->spr.xvel = vx;
}
acsupp_haltatledge(&(actor->spr));
}
}
return acsupp_procfin_fire(actor, ((uint16)(d1) << 8) | d0, 0x1930U, 0x8080U);
}
/*
** Renders the passed archer actor.
*/
void acarcher_render(mapact_t* actor)
{
auint fra;
auint d0 = actor->d0;
auint vab;
if (actor->spr.xvel > 0){ vab = (actor->spr.xvel); }
else { vab = -(actor->spr.xvel); }
if (vab == 1U){
if ((d0 & 0xFU) < 5U){ fra = 0x8AU; }
else if ((d0 & 0xFU) < 10U){ fra = 0x8BU; }
else { fra = 0x8CU; }
}else if (vab == 2U){
if ((d0 & 0x7U) < 3U){ fra = 0x8AU; }
else if ((d0 & 0x7U) < 6U){ fra = 0x8BU; }
else { fra = 0x8CU; }
}else if ((d0 & 0x40U) != 0U){
if ((d0 & 0xFU) < 4U){ fra = 0x89U; }
else if ((d0 & 0xFU) < 10U){ fra = 0x8DU; }
else { fra = 0x8EU; }
}else{
fra = 0x89U;
}
acsupp_rendernpc(actor, fra, d0);
}