-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ppl_default.asc
273 lines (222 loc) · 9.61 KB
/
Ppl_default.asc
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// new module script
import cpeople_types people_types[MAX_PEOPLE];
import cWeapons weapon[eWLastWeapon];
import short people_id[MAX_PEOPLE];
import cpeople people[MAX_PEOPLE];
import short people_index;
import DynamicSprite *Foreground; // Layer 2
import ctile tile[NUM_MAX_TILES];
import int tile_offset_x, tile_offset_y;
import int size_tile_x, size_tile_y;
import int num_tiles_x, num_tiles_y;
import cwaypoint waypoint[MAX_WAYPOINTS];
import short wp_index;
import citems item[MAX_ITEMS];
import ctile_set tile_set;
import bool topdown_mode;
int total(int number)
{
if ( number > 0) return number;
else return number*(-1);
}
//*******************************************************************************
//* move_people
//* Moves people around
//*
//*******************************************************************************
static void PPL_default::move(int i)
{
int l = 0;
float xmodifier = 1.0;
float ymodifier = 1.0;
int left_right_factor = -1;
int footwidth = 3;
int tile_index, tile_index_people;
people[i].OnRamp = false;
if (people[i].midair && !people[i].can_fly) xmodifier = 2.0;
if (people[i].direction == eTengDirLeft)left_right_factor = left_right_factor * (-1);
// get tile in front and beneath npc
tile_index = TILES.get_tile_at ( character[people[i].char_id].x - footwidth * left_right_factor, character[people[i].char_id].y - footwidth, 1, people[i].current_tile );
tile_index_people = TILES.get_tile_at (character[people[i].char_id].x - footwidth * left_right_factor, character[people[i].char_id].y + footwidth, 1, people[i].current_tile );
PPL_helper.check_ramp(i, tile_index_people);
// let people move slower on ramps
if (people[i].OnRamp == true) {
xmodifier = 2.0;
}
// apply gravity
if (!topdown_mode && !people[i].can_fly) PPL_helper.apply_gravity(i, tile_index, tile_index_people);
// WALKING (loop 4 & 5 =dying)
if ( character[people[i].char_id].Loop != 4 && character[people[i].char_id].Loop != 5 )
{
if (people[i].direction_old != people[i].direction)
people[i].antishake++;
else people[i].antishake = 0;
if (people[i].antishake > 2) {
people[i].timer = 5;
people[i].antishake = 0;
}
people[i].direction_old = people[i].direction;
// move people left/right
if (people[i].xspeed!=0.0 || people[i].walkto_x!=0) {
if ( people[i].timer == -1 ) {
float delta = IntToFloat (people[i].x) - people[i].xspeed / xmodifier * IntToFloat(left_right_factor);
delta += people[i].x_remain;
people[i].x_remain = delta - IntToFloat(FloatToInt(delta, eRoundDown));
people[i].x = FloatToInt(delta, eRoundDown);
if (people[i].walkto_x > 0) people[i].walkto_x -= total(FloatToInt(people[i].xspeed));
int index_itm = ITM.get_item_at (character[people[i].char_id].x - footwidth * left_right_factor, character[people[i].char_id].y- 2 );
people[i].current_tile = tile_index_people;
int w = 0;
if (!people[i].ignore_wp) {
while ( w < wp_index )
{
if ( waypoint[w].x == tile[tile_index_people].x[l] && waypoint[w].y == tile[tile_index_people].y[l] )
people[i].timer = people[i].wait_timer;
w++;
}
}
////////////// turn on obstacles
if ( (tile[tile_index].is_solid[l] && !people[i].OnRamp && !tile[tile_index].is_ramp[l] ) || (index_itm > -1 && item[index_itm].is_solid )) {
if (people[i].direction == eTengDirLeft) people[i].direction = eTengDirRight;
else people[i].direction = eTengDirLeft;
}
////////////// turn on cliffs if smart enough
else if ((!topdown_mode || !people[i].can_fly) && !tile[tile_index + num_tiles_x].is_solid[l] && people[i].walkto_x == 0 && !people[i].OnRamp) {
if (!people[i].ignore_cliffs) {
if (people[i].direction == eTengDirLeft) people[i].direction = eTengDirRight;
else people[i].direction = eTengDirLeft;
}
}
//////////////////
// animate people
if ( people[i].timer == -1 ) PPL_helper.animate_people(i);
}
else
people[i].timer--;
}
// move people down
if ( people[i].direction == eTengDirDown && (people[i].yspeed!=0.0 || people[i].walkto_y!=0))
{
if ( people[i].timer == -1 ) {
if (people[i].walkto_y > 0) {
float temp_y = COLL.check_walls(character[people[i].char_id], people[i].yspeed / ymodifier, 0.0, i );
people[i].y += FloatToInt(temp_y) ;
if (people[i].walkto_y > 0) people[i].walkto_y -= FloatToInt(temp_y);
}
else people[i].y += FloatToInt(people[i].yspeed/ ymodifier);
tile_index = TILES.get_tile_at (character[people[i].char_id].x, ( character[people[i].char_id].y + 2 ), 1, people[i].current_tile );
tile_index_people = TILES.get_tile_at ( character[people[i].char_id].x, character[people[i].char_id].y - 2, 1, people[i].current_tile );
int index_itm = ITM.get_item_at (character[people[i].char_id].x, (character[people[i].char_id].y +2 ));
people[i].current_tile = tile_index_people;
if ( tile[tile_index].is_solid[l] || (index_itm > -1 && item[index_itm].is_solid )) {
people[i].direction = eTengDirUp;
}
if ( people[i].timer == -1 ) PPL_helper.animate_people(i);
}
else people[i].timer--;
}
// move people up
else if ( people[i].direction == eTengDirUp && (people[i].yspeed!=0.0 || people[i].walkto_y!=0))
{
if ( people[i].timer == -1 ) {
if (people[i].walkto_y > 0) {
float temp_y = COLL.check_walls(character[people[i].char_id], people[i].yspeed / ymodifier, 0.0, i );
people[i].y -= FloatToInt(temp_y);
if (people[i].walkto_y > 0) people[i].walkto_y -= FloatToInt(temp_y);
}
else people[i].y -= FloatToInt(people[i].yspeed / ymodifier);
tile_index = TILES.get_tile_at (character[people[i].char_id].x, ( character[people[i].char_id].y + 2 )-(INFO.get_char_height(character[people[i].char_id])/3), 1, people[i].current_tile );
tile_index_people = TILES.get_tile_at ( character[people[i].char_id].x, character[people[i].char_id].y - 2 , 1, people[i].current_tile );
int index_itm = ITM.get_item_at (character[people[i].char_id].x, ( character[people[i].char_id].y + 2 )-(INFO.get_char_height(character[people[i].char_id])/3));
people[i].current_tile = tile_index_people;
if ( tile[tile_index].is_solid[l] || (index_itm > -1 && item[index_itm].is_solid )) {
people[i].direction = eTengDirDown;
}
if ( people[i].timer == -1 ) PPL_helper.animate_people(i);
}
else people[i].timer--;
}
//switch directions after reaching an end
if ( people[i].timer == 0)
{
if (people[i].walkto_x <= 0) {
if ( people[i].direction == eTengDirLeft )
people[i].direction = eTengDirRight;
else if ( people[i].direction == eTengDirRight )
people[i].direction = eTengDirLeft;
}
else if (people[i].walkto_y <= 0) {
if (people[i].direction == eTengDirUp)
people[i].direction = eTengDirDown;
else if (people[i].direction == eTengDirDown) people[i].direction = eTengDirUp;
}
people[i].timer = -1;
}
// Turning?
if ( people[i].timer > -1 && people[i].walkto_x == 0 && people[i].walkto_y == 0)
{
if ( people[i].direction == eTengDirLeft && character[people[i].char_id].Loop != eTengDirDown ) {
character[people[i].char_id].Loop = eTengDirDown;
people[i].loop = eTengDirDown;
}
if ( people[i].direction == eTengDirRight && character[people[i].char_id].Loop != eTengDirUp ) {
character[people[i].char_id].Loop = eTengDirUp;
people[i].loop = eTengDirUp;
}
}
}
if (people[i].walkto_x <= 0 && people[i].walkto_start) {
people[i].walkto_x = 0;
people[i].xspeed = 0.0;
if (people[i].walkto_y <= 0) {
people[i].walkto_start = false;
people[i].walkto_y = 0;
people[i].yspeed = 0.0;
}
}
if (people[i].walkto_y <= 0 && people[i].walkto_start) {
people[i].walkto_y = 0;
people[i].yspeed = 0.0;
if (people[i].walkto_x <= 0) {
people[i].walkto_start = false;
people[i].walkto_x = 0;
people[i].xspeed = 0.0;
}
}
}
//*******************************************************************************
//* process
//*
//*******************************************************************************
static void PPL_default::process(int index)
{
if (people[index].hit_timer == -1 ) {
if (people[index].is_alarmable) {
PPL_helper.check_alarm(index);
if (!people[index].alarmed) PPL_default.move(index);
else {
if ( people[index].alarm_timer > 0 ) {
people[index].alarm_timer--;
PPL_helper.check_attack(index);
}
if ( people[index].alarm_timer == 0 )
{
people[index].alarmed = false;
people[index].alarm_timer = -1;
}
}
}
else PPL_default.move(index);
}
else {
if (people[index].direction == eTengDirLeft) {
character[people[index].char_id].Loop = 0;
people[index].loop = 0;
}
else {
character[people[index].char_id].Loop = 3;
people[index].loop = 3;
}
character[people[index].char_id].Frame = 1;
}
}