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

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

game: prefix a few class members with m_ to avoid confusion.

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-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, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "common.h"
16
17#include "extend.h"
18#include "view.h"
19#include "objects.h"
20#include "lisp.h"
21
22/*
23
24
25
26  Simple object             (power ups, non-moving objects)
27    int32_t x,y;
28    int8_t direction;
29    uint16_t otype,state
30    uint16_t current_frame;
31    extension *
32
33
34  Moving object             (simple lisp controlled characters)
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,
40     extension *
41
42
43  Complex objects          (can controll lights, other characters, and have a neural net ai)
44    uint8_t tobjs,tlights;
45    object_list *
46    light_list *
47    nnet_info *
48    int8_t fade_dir, frame_dir;
49    uint8_t fade_count,fade_max;
50    morph_char *morph_status;
51
52
53*/
54
55void simple_object::add_light(light_source *ls)
56{
57  if (!ls) return ;
58  ls->known=1;
59  for (int i=0; i<tlights; i++) if (lights[i]==ls) return;
60  tlights++;
61  lights=(light_source **)realloc(lights,sizeof(light_source *)*tlights);
62  lights[tlights-1]=ls;
63}
64
65void simple_object::add_object(game_object *o)
66{
67  if (!o) return ;
68  for (int i=0; i<tobjs; i++) if (objs[i]==o) return;
69  o->set_flags(o->flags()|KNOWN_FLAG);
70  if(_team != -1)
71    o->set_team(_team);
72  if(_tint != -1)
73    o->set_tint(_tint);
74  tobjs++;
75  objs=(game_object **)realloc(objs,sizeof(game_object *)*tobjs);
76  objs[tobjs-1]=o;
77}
78
79
80void simple_object::remove_light(light_source *ls)
81{
82  for (int i=0; i<tlights; i++)
83  {
84    if (lights[i]==ls)
85    {
86      tlights--;
87      for (int j=i; j<tlights; j++)     // don't even think about it :)
88        lights[j]=lights[j+1];
89      lights=(light_source **)realloc(lights,sizeof(light_source *)*tlights);
90      return ;
91    }
92  }
93}
94
95void simple_object::remove_object(game_object *o)
96{
97  for (int i=0; i<tobjs; i++)
98  {
99    if (objs[i]==o)
100    {
101      tobjs--;
102      for (int j=i; j<tobjs; j++)     // don't even think about it :)
103        objs[j]=objs[j+1];
104      objs=(game_object **)realloc(objs,sizeof(game_object *)*tobjs);
105      return ;
106    }
107  }
108}
109
110
111simple_object::simple_object()
112{
113
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;
137  _tint = -1;
138  _team = -1;
139  grav_on=1;
140  targetable_on=1;
141}
142
143
144
145void simple_object::set_morph_status(morph_char *Mc)
146{
147  mc=Mc;
148}
149
150void simple_object::clean_up()
151{
152  if (tlights) free(lights);
153  if (tobjs)   free(objs);
154  if (Controller)
155    Controller->m_focus=NULL;
156}
157
158
159simple_object default_simple;
160
161
Note: See TracBrowser for help on using the repository browser.