[2] | 1 | /* |
---|
[56] | 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
[494] | 4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
[56] | 5 | * |
---|
| 6 | * This software was released into the Public Domain. As with most public |
---|
[555] | 7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
| 8 | * Jonathan Clark, or by Sam Hocevar. |
---|
[56] | 9 | */ |
---|
[2] | 10 | |
---|
[555] | 11 | #if defined HAVE_CONFIG_H |
---|
| 12 | # include "config.h" |
---|
| 13 | #endif |
---|
[2] | 14 | |
---|
[512] | 15 | #include "common.h" |
---|
| 16 | |
---|
[481] | 17 | #include "extend.h" |
---|
| 18 | #include "view.h" |
---|
| 19 | #include "objects.h" |
---|
| 20 | #include "lisp.h" |
---|
[2] | 21 | |
---|
[56] | 22 | /* |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
[2] | 26 | Simple object (power ups, non-moving objects) |
---|
[17] | 27 | int32_t x,y; |
---|
| 28 | int8_t direction; |
---|
| 29 | uint16_t otype,state |
---|
| 30 | uint16_t current_frame; |
---|
[2] | 31 | extension * |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | Moving object (simple lisp controlled characters) |
---|
[17] | 35 | uint8_t flags; |
---|
| 36 | int32_t xvel,yvel,xacel,yacel; |
---|
| 37 | uint8_t fx,fy,fxvel,fyvel,fxacel,fyacel,aitype; |
---|
| 38 | uint16_t aistate,aistate_time; |
---|
| 39 | uint16_t hp,mp, |
---|
[2] | 40 | extension * |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | Complex objects (can controll lights, other characters, and have a neural net ai) |
---|
[17] | 44 | uint8_t tobjs,tlights; |
---|
[124] | 45 | object_list * |
---|
[2] | 46 | light_list * |
---|
| 47 | nnet_info * |
---|
[124] | 48 | int8_t fade_dir, frame_dir; |
---|
[17] | 49 | uint8_t fade_count,fade_max; |
---|
[2] | 50 | morph_char *morph_status; |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | */ |
---|
| 54 | |
---|
| 55 | void simple_object::add_light(light_source *ls) |
---|
[124] | 56 | { |
---|
[2] | 57 | if (!ls) return ; |
---|
| 58 | ls->known=1; |
---|
[494] | 59 | for (int i=0; i<tlights; i++) if (lights[i]==ls) return; |
---|
[124] | 60 | tlights++; |
---|
[129] | 61 | lights=(light_source **)realloc(lights,sizeof(light_source *)*tlights); |
---|
[2] | 62 | lights[tlights-1]=ls; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void simple_object::add_object(game_object *o) |
---|
| 66 | { |
---|
| 67 | if (!o) return ; |
---|
[494] | 68 | for (int i=0; i<tobjs; i++) if (objs[i]==o) return; |
---|
[2] | 69 | o->set_flags(o->flags()|KNOWN_FLAG); |
---|
[126] | 70 | if(_team != -1) |
---|
| 71 | o->set_team(_team); |
---|
| 72 | if(_tint != -1) |
---|
| 73 | o->set_tint(_tint); |
---|
[2] | 74 | tobjs++; |
---|
[129] | 75 | objs=(game_object **)realloc(objs,sizeof(game_object *)*tobjs); |
---|
[2] | 76 | objs[tobjs-1]=o; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | void simple_object::remove_light(light_source *ls) |
---|
| 81 | { |
---|
[494] | 82 | for (int i=0; i<tlights; i++) |
---|
[2] | 83 | { |
---|
| 84 | if (lights[i]==ls) |
---|
| 85 | { |
---|
| 86 | tlights--; |
---|
[494] | 87 | for (int j=i; j<tlights; j++) // don't even think about it :) |
---|
[2] | 88 | lights[j]=lights[j+1]; |
---|
[129] | 89 | lights=(light_source **)realloc(lights,sizeof(light_source *)*tlights); |
---|
[2] | 90 | return ; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | void simple_object::remove_object(game_object *o) |
---|
| 96 | { |
---|
[494] | 97 | for (int i=0; i<tobjs; i++) |
---|
[2] | 98 | { |
---|
| 99 | if (objs[i]==o) |
---|
| 100 | { |
---|
| 101 | tobjs--; |
---|
[494] | 102 | for (int j=i; j<tobjs; j++) // don't even think about it :) |
---|
[2] | 103 | objs[j]=objs[j+1]; |
---|
[129] | 104 | objs=(game_object **)realloc(objs,sizeof(game_object *)*tobjs); |
---|
[2] | 105 | return ; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | simple_object::simple_object() |
---|
| 112 | { |
---|
[124] | 113 | |
---|
[2] | 114 | x=y=0; |
---|
| 115 | direction=1; |
---|
| 116 | otype=0; |
---|
| 117 | state=stopped; |
---|
| 118 | current_frame=0; |
---|
| 119 | |
---|
| 120 | Fade_dir=0; |
---|
| 121 | Fade_count=0; |
---|
| 122 | Fade_max=16; |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | tobjs=tlights=0; |
---|
| 126 | objs=NULL; |
---|
| 127 | lights=NULL; |
---|
| 128 | Frame_dir=1; |
---|
| 129 | mc=NULL; |
---|
| 130 | Controller=NULL; |
---|
| 131 | |
---|
| 132 | Flags=0; |
---|
| 133 | Xvel=Yvel=Xacel=Yacel=0; |
---|
| 134 | Fx=Fy=Fxvel=Fyvel=Fxacel=Fyacel=Aitype=0; |
---|
| 135 | Aistate=Aistate_time=0; |
---|
| 136 | Hp=Mp=Fmp=0; |
---|
[126] | 137 | _tint = -1; |
---|
| 138 | _team = -1; |
---|
[2] | 139 | grav_on=1; |
---|
| 140 | targetable_on=1; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | void simple_object::set_morph_status(morph_char *Mc) |
---|
| 146 | { |
---|
| 147 | mc=Mc; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void simple_object::clean_up() |
---|
| 151 | { |
---|
[129] | 152 | if (tlights) free(lights); |
---|
| 153 | if (tobjs) free(objs); |
---|
[2] | 154 | if (Controller) |
---|
| 155 | Controller->focus=NULL; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | simple_object default_simple; |
---|
| 160 | |
---|
| 161 | |
---|