source: abuse/trunk/src/extend.cpp @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

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