-
Notifications
You must be signed in to change notification settings - Fork 1
/
objects.cpp
1640 lines (1379 loc) · 37 KB
/
objects.cpp
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Abuse - dark 2D side-scrolling platform game
* Copyright (c) 1995 Crack dot Com
* Copyright (c) 2005-2011 Sam Hocevar <[email protected]>
*
* This software was released into the Public Domain. As with most public
* domain software, no warranty is made or implied by Crack dot Com, by
* Jonathan Clark, or by Sam Hocevar.
*/
#if defined HAVE_CONFIG_H
# include "config.h"
#endif
#include "common.h"
#include "transimage.h"
#include "objects.h"
#include "chars.h"
#include "game.h"
#include "intsect.h"
#include "ability.h"
#include "lisp.h"
#include "jrand.h"
#include "light.h"
#include "dprint.h"
#include "clisp.h"
#include "lisp_gc.h"
#include "profile.h"
char **object_names;
int total_objects;
game_object *current_object;
view *current_view;
game_object *game_object::copy()
{
game_object *o=create(otype,x,y);
o->state=state;
int i=0;
for (; i<TOTAL_OBJECT_VARS; i++)
o->set_var(i,get_var(i));
memcpy(o->lvars,lvars,4*figures[otype]->tv);
for (i=0; i<total_objects(); i++)
o->add_object(get_object(i));
for (i=0; i<total_lights(); i++)
o->add_light(get_light(i));
return o;
}
int simple_object::total_vars() { return TOTAL_OBJECT_VARS; }
obj_desc object_descriptions[TOTAL_OBJECT_VARS] =
{
{ "fade_dir", RC_8 },
{ "frame_dir", RC_8 },
{ "direction", RC_8 },
{ "gravity_on", RC_8 },
{ "fade_count", RC_8 },
{ "fade_max", RC_8 },
{ "active", RC_8 },
{ "flags", RC_8 },
{ "aitype", RC_8 },
{ "xvel", RC_32 },
{ "fxvel", RC_8 },
{ "yvel", RC_32 },
{ "fyvel", RC_8 },
{ "xacel", RC_32 },
{ "fxacel", RC_8 },
{ "yacel", RC_32 },
{ "fyacel", RC_8 },
{ "x", RC_32 },
{ "fx", RC_8 },
{ "y", RC_32 },
{ "fy", RC_8 },
{ "hp", RC_16 },
{ "mp", RC_16 },
{ "fmp", RC_16 },
{ "cur_frame", RC_16 },
{ "aistate", RC_16 },
{ "aistate_time", RC_16 },
{ "targetable", RC_8 }
};
int32_t game_object::get_var_by_name(char *name, int &error)
{
error=0;
int i=0;
for (; i<TOTAL_OBJECT_VARS; i++)
{
if (!strcmp(object_descriptions[i].name,name))
return get_var(i);
}
for (i=0; i<figures[otype]->tiv; i++)
{
if (!strcmp(lstring_value(((LSymbol *)figures[otype]->vars[i])->GetName()),name))
{
return lvars[figures[otype]->var_index[i]];
/* LObjectVar *cobj=(LObjectVar *)symbol_value(figures[otype]->vars[i]);
CharacterType *t=figures[otype];
int number=cobj->number;
if (t->tiv<=number || !t->vars[number])
{
lbreak("access : variable does not exists for this class\n");
return 0;
}
return lvars[t->var_index[number]]; */
}
}
error=1;
return 0;
}
int game_object::set_var_by_name(char *name, int32_t value)
{
int i=0;
for (; i<TOTAL_OBJECT_VARS; i++)
{
if (!strcmp(object_descriptions[i].name,name))
{
set_var(i,value);
return 1;
}
}
for (i=0; i<figures[otype]->tiv; i++)
if (!strcmp(lstring_value(((LSymbol *)figures[otype]->vars[i])->GetName()),name))
{
lvars[figures[otype]->var_index[i]]=value;
return 1;
}
return 0;
}
char const *simple_object::var_name(int x)
{
return object_descriptions[x].name;
}
int simple_object::var_type(int x)
{
return object_descriptions[x].type;
}
void simple_object::set_var(int xx, uint32_t v)
{
switch (xx)
{
case 0 : set_fade_dir(v); break;
case 1 : set_frame_dir(v); break;
case 2 : direction=v; break;
case 3 : set_gravity(v); break;
case 4 : set_fade_count(v); break;
case 5 : set_fade_max(v); break;
case 6 : active=v; break;
case 7 : set_flags(v); break;
case 8 : set_aitype(v); break;
case 9 : set_xvel(v); break;
case 10 : set_fxvel(v); break;
case 11 : set_yvel(v); break;
case 12 : set_fyvel(v); break;
case 13 : set_xacel(v); break;
case 14 : set_fxacel(v); break;
case 15 : set_yacel(v); break;
case 16 : set_fyacel(v); break;
case 17 : x=v; break;
case 18 : set_fx(v); break;
case 19 : y=v; break;
case 20 : set_fy(v); break;
case 21 : set_hp(v); break;
case 22 : set_mp(v); break;
case 23 : set_fmp(v); break;
case 24 : current_frame=v; break;
case 25 : set_aistate(v); break;
case 26 : set_aistate_time(v); break;
case 27 : set_targetable(v); break;
}
}
int32_t simple_object::get_var(int xx)
{
switch (xx)
{
case 0 : return fade_dir(); break;
case 1 : return frame_dir(); break;
case 2 : return direction; break;
case 3 : return gravity(); break;
case 4 : return fade_count(); break;
case 5 : return fade_max(); break;
case 6 : return active; break;
case 7 : return flags(); break;
case 8 : return aitype(); break;
case 9 : return xvel(); break;
case 10 : return fxvel(); break;
case 11 : return yvel(); break;
case 12 : return fyvel(); break;
case 13 : return xacel(); break;
case 14 : return fxacel(); break;
case 15 : return yacel(); break;
case 16 : return fyacel(); break;
case 17 : return x; break;
case 18 : return fx(); break;
case 19 : return y; break;
case 20 : return fy(); break;
case 21 : return hp(); break;
case 22 : return mp(); break;
case 23 : return fmp(); break;
case 24 : return current_frame; break;
case 25 : return aistate(); break;
case 26 : return aistate_time(); break;
case 27 : return targetable();
}
return 0;
}
int RC_type_size(int type)
{
switch (type)
{
case RC_8 :
{ return 1; } break;
case RC_16 :
{ return 2; } break;
case RC_32 :
{ return 4; } break;
}
CHECK(0);
return 1;
}
void game_object::reload_notify()
{
void *ns=figures[otype]->get_fun(OFUN_RELOAD);
if (ns)
{
game_object *o=current_object;
current_object=this;
void *m = LSpace::Tmp.Mark();
((LSymbol *)ns)->EvalFunction(NULL);
LSpace::Tmp.Restore(m);
current_object=o;
}
}
void game_object::next_sequence()
{
void *ns = figures[otype]->get_fun( OFUN_NEXT_STATE );
if( ns )
{
current_object = this;
void *m = LSpace::Tmp.Mark();
((LSymbol *)ns)->EvalFunction(NULL);
LSpace::Tmp.Restore(m);
}
else
{
switch( state )
{
case dieing:
{
set_state( dead );
} break;
case end_run_jump:
{
set_state( running );
} break;
case dead:
case run_jump:
case run_jump_fall:
case running:
{
set_state(state);
} break;
case start_run_jump:
{
set_yvel(get_ability(type(),jump_yvel));
if( xvel() > 0 )
set_xvel(get_ability(type(),jump_xvel));
else if( xvel() < 0 )
set_xvel(-get_ability(type(),jump_xvel));
set_xacel(0);
set_fxacel(0);
set_gravity(1);
set_state(run_jump);
} break;
case flinch_up:
case flinch_down:
{
if( gravity() )
{
if( has_sequence( end_run_jump ) )
set_state(end_run_jump);
else
set_state(stopped);
}
else
{
set_state(stopped);
}
} break;
default:
{
set_state(stopped);
} break;
}
}
}
game_object::~game_object()
{
if (lvars) free(lvars);
clean_up();
}
void game_object::add_power(int amount)
{
int max_power=lnumber_value(symbol_value(l_max_power));
int n=mp()+amount;
if (n<0) n=0;
if (n>max_power) n=max_power;
set_mp(n);
}
void game_object::add_hp(int amount)
{
if (controller() && controller()->god) return ;
int max_hp=lnumber_value(symbol_value(l_max_hp));
int n=hp()+amount;
if (n<0) n=0;
if (n>max_hp)
n=max_hp;
set_hp(n);
}
int game_object::can_morph_into(int type)
{
if (type!=otype && mp()>=figures[type]->morph_power)
return 1;
else return 0;
}
void game_object::morph_into(int type, void (*stat_fun)(int), int anneal, int frames)
{
set_morph_status(new morph_char(this,type,stat_fun,anneal,frames));
otype=type;
set_state(stopped);
}
void game_object::draw_above(view *v)
{
int32_t x1, y1, x2, y2;
picture_space(x1,y1,x2,y2);
ivec2 pos1 = the_game->GameToMouse(ivec2(x1, y1), v);
if (pos1.y >= v->m_aa.y)
{
int32_t draw_to = y1 - (pos1.y - v->m_aa.y), tmp = x;
current_level->foreground_intersect(x, y1, tmp, draw_to);
// calculate pos2.y
ivec2 pos2 = the_game->GameToMouse(ivec2(x1, draw_to), v);
pos2.y = Max(v->m_aa.y, pos2.y);
pos1.y = Min(v->m_bb.y, pos1.y);
TransImage *p = picture();
for (int i = pos2.y; i <= pos1.y; i++)
p->PutScanLine(main_screen, ivec2(pos1.x, i), 0);
}
}
int game_object::push_range()
{
return get_ability(otype,push_xrange);
}
int game_object::decide()
{
if (figures[otype]->get_fun(OFUN_AI))
{
int old_aistate;
old_aistate=aistate();
current_object=this;
void *m = LSpace::Tmp.Mark();
time_marker *prof1=NULL;
if (profiling())
prof1=new time_marker;
LObject *ret = ((LSymbol *)figures[otype]->get_fun(OFUN_AI))->EvalFunction(NULL);
if (profiling())
{
time_marker now;
profile_add_time(this->otype,now.diff_time(prof1));
delete prof1;
}
LSpace::Tmp.Restore(m);
if (keep_ai_info())
{
if (aistate()!=old_aistate)
set_aistate_time(0);
else set_aistate_time(aistate_time()+1);
}
if (!NILP(ret)) return 1;
else return 0;
}
else move(0,0,0);
return 1;
}
// collision checking will ask first to see if you
int game_object::can_hurt(game_object *who)
{
int is_attacker = current_level->is_attacker(this);
// it's you against them! Damage only if it you are attacking or they are
// attacking you, ie. don't let them hurt themselves. This can change if
// you override this virtual function
if(who->hurtable()
&& ((_team == -1) || (_team != who->get_team()))
&& (is_attacker || current_level->is_attacker(who) || hurt_all()))
return 1;
return 0;
}
void game_object::note_attack(game_object *whom)
{
return; // nevermind
}
void game_object::do_flinch(game_object *from)
{
if (jrandom(2) && has_sequence(flinch_down))
set_state(flinch_down);
else if (has_sequence(flinch_up))
set_state(flinch_up);
}
void game_object::do_damage(int amount, game_object *from, int32_t hitx, int32_t hity,
int32_t push_xvel, int32_t push_yvel)
{
// No friendly fire
if((_team != -1) && (_team == from->get_team()))
return;
void *d=figures[otype]->get_fun(OFUN_DAMAGE);
if (d)
{
LList *am, *frm, *hx, *hy, *px, *py;
game_object *o = current_object;
current_object = this;
void *m = LSpace::Tmp.Mark();
am = LList::Create();
PtrRef r1(am);
am->m_car = LNumber::Create(amount);
frm = LList::Create();
PtrRef r2(frm);
frm->m_car = LPointer::Create(from);
hx = LList::Create();
PtrRef r3(hx);
hx->m_car = LNumber::Create(hitx);
hy = LList::Create();
PtrRef r4(hy);
hy->m_car = LNumber::Create(hity);
px = LList::Create();
PtrRef r5(px);
px->m_car = LNumber::Create(push_xvel);
py = LList::Create();
PtrRef r6(py);
py->m_car = LNumber::Create(push_yvel);
px->m_cdr = py;
hy->m_cdr = px;
hx->m_cdr = hy;
frm->m_cdr = hx;
am->m_cdr = frm;
time_marker *prof1 = NULL;
if (profiling())
prof1 = new time_marker;
((LSymbol *)d)->EvalUserFunction(am);
if (profiling())
{
time_marker now;
profile_add_time(this->otype, now.diff_time(prof1));
delete prof1;
}
LSpace::Tmp.Restore(m);
current_object = o;
} else damage_fun(amount,from,hitx,hity,push_xvel,push_yvel);
}
void game_object::damage_fun(int amount, game_object *from, int32_t hitx, int32_t hity,
int32_t push_xvel, int32_t push_yvel)
{
if (!hurtable() || !alive()) return ;
add_hp(-amount);
set_flags(flags()|FLAG_JUST_HIT);
do_flinch(from);
set_xvel(xvel()+push_xvel);
if (push_yvel<0 && !gravity())
set_gravity(1);
set_yvel(yvel()+push_yvel);
view *c=controller();
if (c && hp()<=0)
{
view *v=from->controller();
if (v) v->kills++; // attack from another player?
else if (from->total_objects()>0)
{
v=from->get_object(0)->controller(); // weapon from another player?
if (v && v!=c) v->kills++;
else
{
v=c; // suicide
if (v) v->kills--;
}
}
}
}
int game_object::facing_attacker(int attackerx)
{
return ((attackerx<x && direction<0) || (attackerx>=x && direction>0));
}
void game_object::picture_space(int32_t &x1, int32_t &y1,int32_t &x2, int32_t &y2)
{
int xc=x_center(),w=picture()->Size().x,h=picture()->Size().y;
if (direction>0)
x1=x-xc;
else x1=x-(w-xc-1);
x2=x1+w-1;
y1=y-h+1;
y2=y;
}
int game_object::next_picture()
{
int ret=1;
if (frame_dir()>0)
{
if (!current_sequence()->next_frame(current_frame))
{
next_sequence();
ret=0;
}
}
else
{
if (!current_sequence()->last_frame(current_frame))
{
next_sequence();
ret=0;
}
}
frame_advance();
return ret;
}
int32_t game_object::x_center()
{
return current_sequence()->x_center(current_frame);
}
void game_object::draw()
{
if (figures[otype]->get_fun(OFUN_DRAW))
{
current_object=this;
void *m = LSpace::Tmp.Mark();
time_marker *prof1=NULL;
if (profiling())
prof1=new time_marker;
((LSymbol *)figures[otype]->get_fun(OFUN_DRAW))->EvalFunction(NULL);
if (profiling())
{
time_marker now;
profile_add_time(this->otype,now.diff_time(prof1));
delete prof1;
}
LSpace::Tmp.Restore(m);
} else drawer();
}
void game_object::map_draw()
{
if (figures[otype]->get_fun(OFUN_MAP_DRAW))
{
current_object=this;
void *m = LSpace::Tmp.Mark();
time_marker *prof1=NULL;
if (profiling())
prof1=new time_marker;
((LSymbol *)figures[otype]->get_fun(OFUN_MAP_DRAW))->EvalFunction(NULL);
if (profiling())
{
time_marker now;
profile_add_time(this->otype,now.diff_time(prof1));
delete prof1;
}
LSpace::Tmp.Restore(m);
}
}
void game_object::draw_trans(int count, int max)
{
TransImage *cpict=picture();
cpict->PutFade(main_screen,
ivec2((direction<0 ? x-(cpict->Size().x-x_center()-1) : x-x_center())-current_vxadd,
y-cpict->Size().y+1-current_vyadd),
count,max,
color_table,the_game->current_palette());
}
void game_object::draw_tint(int tint_id)
{
TransImage *cpict=picture();
if (fade_count())
cpict->PutFadeTint(main_screen,
ivec2((direction<0 ? x-(cpict->Size().x-x_center()-1) : x-x_center())-current_vxadd,
y-cpict->Size().y+1-current_vyadd),
fade_count(),fade_max(),
cache.ctint(tint_id)->data,
color_table,the_game->current_palette());
else
cpict->PutRemap(main_screen,
ivec2((direction<0 ? x-(cpict->Size().x-x_center()-1) : x-x_center())-current_vxadd,
y-cpict->Size().y+1-current_vyadd),
cache.ctint(tint_id)->data);
}
void game_object::draw_double_tint(int tint_id, int tint2)
{
TransImage *cpict=picture();
if (fade_count())
cpict->PutFadeTint(main_screen,
ivec2((direction<0 ? x-(cpict->Size().x-x_center()-1) : x-x_center())-current_vxadd,
y-cpict->Size().y+1-current_vyadd),
fade_count(),fade_max(),
cache.ctint(tint_id)->data,
color_table,the_game->current_palette());
else
cpict->PutDoubleRemap(main_screen,
ivec2((direction<0 ? x-(cpict->Size().x-x_center()-1) : x-x_center())-current_vxadd,
y-cpict->Size().y+1-current_vyadd),
cache.ctint(tint_id)->data,
cache.ctint(tint2)->data);
}
void game_object::draw_predator()
{
TransImage *cpict=picture();
cpict->PutPredator(main_screen,
ivec2((direction<0 ? x-(cpict->Size().x-x_center()-1) : x-x_center())-current_vxadd,
y-cpict->Size().y+1-current_vyadd));
}
void game_object::drawer()
{
if (morph_status())
{
morph_status()->draw(this,current_view);
if (morph_status()->frames_left()<1)
set_morph_status(NULL);
}
else
{
//view *v=controller();
if (fade_count())
draw_trans(fade_count(),fade_max());
else
{
TransImage *cpict=picture();
cpict->PutImage(main_screen,
ivec2((direction<0 ? x-(cpict->Size().x-x_center()-1) : x-x_center())-current_vxadd,
y-cpict->Size().y+1-current_vyadd));
}
}
}
game_object *game_object::try_move(int32_t x, int32_t y, int32_t &xv, int32_t &yv, int checks)
{
if (xv || yv) // make sure they are suggesting movement
{
game_object *who1=NULL,*who2=NULL; // who did we intersect?
int32_t x2,y2,h;
if (checks&1)
{
x2=x+xv;
y2=y+yv;
current_level->foreground_intersect(x,y,x2,y2);
if (!stoppable())
who1=current_level->boundary_setback(this,x,y,x2,y2);
else
who1=current_level->all_boundary_setback(this,x,y,x2,y2);
xv=x2-x;
yv=y2-y;
}
if (checks&2)
{
h=picture()->Size().y;
x2=x+xv;
y2=y-h+1+yv;
current_level->foreground_intersect(x,y-h+1,x2,y2);
if (!stoppable())
who2=current_level->all_boundary_setback(this,x,y-h+1,x2,y2);
else
who2=current_level->boundary_setback(this,x,y-h+1,x2,y2);
xv=x2-x;
yv=y2-y+h-1;
}
if (who2) return who2;
else return who1;
}
else return NULL;
}
void *game_object::float_tick() // returns 1 if you hit something, 0 otherwise
{
int32_t ret=0;
if (hp()<=0)
{
if (state!=dead)
{
set_xacel(0);
set_fxacel(0);
if (has_sequence(dieing))
{
if (state!=dieing)
{
set_state(dieing);
set_xvel(0);
}
} else
{ set_xvel(0);
set_fxvel(0);
if (has_sequence(dead))
set_state(dead);
else return 0;
}
}
}
int32_t fxv=sfxvel()+sfxacel(),fyv=sfyvel()+sfyacel();
int32_t xv=xvel()+xacel()+(fxv>>8),yv=yvel()+yacel()+(fyv>>8);
if (xv!=xvel() || yv!=yvel()) // only store vel's if changed so we don't increase object size
{
set_xvel(xv);
set_yvel(yv);
}
if (fxv!=sfxvel() || fyv!=sfyvel())
{
set_fxvel(fxv&0xff);
set_fyvel(fyv&0xff);
}
if (fxv || fyv || xv || yv) // don't even try if there is no velocity
{
int32_t ffx=fx()+sfxvel(),ffy=fy()+sfyvel();
int32_t nxv=xvel()+(ffx>>8);
int32_t nyv=yvel()+(ffy>>8);
set_fx(ffx&0xff);
set_fy(ffy&0xff);
int32_t old_nxv=nxv,old_nyv=nyv;
game_object *hit_object=try_move(x,y,nxv,nyv,3); // now find out what velocity is safe to use
/* if (get_cflag(CFLAG_STOPPABLE))
{
game_object *r=current_level->boundary_setback(exclude,x,y,nxv,nyv,1);
if (r) hit_object=r;
}*/
x+=nxv;
y+=nyv;
if (old_nxv!=nxv || old_nyv!=nyv)
{
int32_t lx=last_tile_hit_x,ly=last_tile_hit_y;
stop();
if (old_nxv==0)
{
if (old_nyv>0) ret|=BLOCKED_DOWN;
else if (old_nyv<0) ret|=BLOCKED_UP;
} else if (old_nyv==0)
{
if (old_nxv>0) ret|=BLOCKED_RIGHT;
else if (old_nxv<0) ret|=BLOCKED_LEFT;
} else
{
int32_t tx=(old_nxv>0 ? 1 : -1),ty=0;
try_move(x,y,tx,ty,3);
if (!tx)
ret|=(old_nxv>0 ? BLOCKED_RIGHT : BLOCKED_LEFT);
else tx=0;
ty=(old_nyv>0 ? 1 : -1);
try_move(x,y,tx,ty,3);
if (!ty)
ret|=(old_nyv>0 ? BLOCKED_DOWN : BLOCKED_UP);
if (!ret)
ret|=(old_nyv>0 ? BLOCKED_DOWN : BLOCKED_UP) | (old_nxv>0 ? BLOCKED_RIGHT : BLOCKED_LEFT);
}
void *rlist=NULL; // return list
PtrRef r1(rlist);
if (hit_object)
{
push_onto_list(LPointer::Create(hit_object),rlist);
push_onto_list(l_object,rlist);
} else
{
push_onto_list(LNumber::Create(ly),rlist);
push_onto_list(LNumber::Create(lx),rlist);
push_onto_list(l_tile,rlist);
}
push_onto_list(LNumber::Create(ret),rlist);
return rlist;
} else return true_symbol;
}
return true_symbol;
}
int game_object::tick() // returns blocked status
{
int blocked=0;
int32_t xt=0,yt=2;
try_move(x,y-2,xt,yt,1); // make sure we are not falling through the floor
y=y-2+yt;
if (flags()&FLAG_JUST_BLOCKED)
set_flags(flags()-FLAG_JUST_BLOCKED);
if (gravity() && !floating())
{
int fya;
if (yacel()>=0)
fya=sfyacel()+200;
else
fya=sfyacel()-200;
set_yacel(yacel()+(fya>>8));
set_fyacel(fya&255);
}
// first let's move the guy acording to his physics
int32_t xa=xacel(),ya=yacel(),fxa=sfxacel(),fya=sfyacel();
if (xa || ya || fxa || fya)
{
int fxv=sfxvel(),fyv=sfyvel();
fxv+=fxa; fyv+=fya;
//int32_t xv=xvel()+xa+(fxv>>8);
set_xvel(xvel()+xa+(fxv>>8));
set_yvel(yvel()+ya+(fyv>>8));
set_fxvel(fxv&0xff);
set_fyvel(fyv&0xff);
}
// check to see if this advancement causes him to collide with objects
int32_t old_vy=yvel(),old_vx=xvel(); // save the correct veloicties
if (old_vx || old_vy)
{
int up=0;
if (yvel()<=0) // if we are going up or a strait across check up and down
up=2;
int32_t xv=xvel(),yv=yvel();
game_object *h=try_move(x,y,xv,yv,1|up); // now find out what velocity is safe to use
set_xvel(xv);
set_yvel(yv);
x+=xv;
y+=yv;
if (h && stoppable()) return BLOCKED_LEFT|BLOCKED_RIGHT;
if (xv!=old_vx || yv!=old_vy) // he collided with something
{
if (gravity()) // was he going up or down?
{
int32_t fall_xv=0,old_fall_vy,fall_vy;
old_fall_vy=fall_vy=old_vy-yvel(); // make sure he gets all of his yvel
try_move(x,y,fall_xv,fall_vy,1|up);
if (old_vy>0 && fall_vy<old_fall_vy) // he was trying to fall, but he hit the ground
{
if (old_vy>0)
{
blocked|=BLOCKED_DOWN;
if (!xvel() && has_sequence(end_run_jump))
{
set_xvel(old_vx);
set_state(end_run_jump);
}
else set_state(stopped);
}
else blocked|=BLOCKED_UP;
if (state==run_jump_fall)
{
if (has_sequence(running))
set_state(running);
else
{
stop_x();
set_state(stopped);
}
}
else
{
set_yacel(0);
set_fyacel(0);
set_yvel(0);
set_fyvel(0);