source: abuse/branches/lol/src/extend.cpp @ 732

Last change on this file since 732 was 732, checked in by Sam Hocevar, 8 years ago

build: SDL2 compilation fixes.

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