source: golgotha/src/golg/objs/gun_port.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.3 KB
RevLine 
[80]1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "objs/def_object.hh"
10#include "lisp/li_init.hh"
11#include "lisp/li_class.hh"
12#include "li_objref.hh"
13#include "map_man.hh"
14#include "map.hh"
15#include "math/pi.hh"
16
17static li_int_class_member health("health"), explode_health("explode_health"),
18  fire_delay("fire_delay"), total_burst("total_burst"),  burst_delay("burst_delay"),
19  cost("cost"),  range("range");
20
21static li_symbol_class_member fire_type("bullet");
22
23 
24
25li_object *g1_gunport_damage(li_object *o, li_environment *env)
26{
27  g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
28  int hp=li_int::get(li_car(li_cdr(li_cdr(o))))->value();
29
30  health()-=hp;
31
32  me->request_think();
33  return 0;
34}
35
36li_object *g1_gunport_enter_range(li_object *o, li_environment *env)
37{
38  return 0;
39}
40
41
42
43li_object *g1_gunport_think(li_object *o, li_environment *env)
44{
45  g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
46  li_class *v=me->vars;
47
48  if (health() < 0)
49  {
50    if (health() < explode_health())
51    {
52      me->unoccupy_location();
53      me->request_remove();
54    }
55    else
56    {
57      me->set_flag(g1_object_class::DANGEROUS,0);
58      health()--;
59      me->request_think();
60    }
61  }
62
63  return 0;
64}
65
66
67static li_float_class_member turn_speed("turn_speed"), speed("speed"),
68  max_speed("max_speed"), hill_scale("hill_scale"), damage_speedup("damage_speedup");
69
70li_object *g1_speed_damage(li_object *o, li_environment *env)
71{
72  g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
73  int hp=li_int::get(li_car(li_cdr(li_cdr(o))))->value();
74
75  speed()+=hp * damage_speedup();
76
77  me->request_think();
78  return 0;
79}
80
81li_object *g1_circle_think(li_object *o, li_environment *env)
82{
83  g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
84
85
86  me->grab_old();
87  me->unoccupy_location();
88 
89  float s=speed();
90
91  me->x += cos(me->theta)*s;
92  me->y += sin(me->theta)*s;
93
94  float h=g1_get_map()->terrain_height(me->x, me->y);
95 
96  if (h<me->h)   // going down hill speed up
97  {
98    s += (me->h-h) * hill_scale();
99
100    if (s>max_speed())
101      s=max_speed();
102
103    speed()=s;
104    me->h=h;
105  }
106  else if (h>me->h)  // going up hill, slow down
107  {
108    s += (me->h-h) * hill_scale();
109    if (s<0)
110    {
111      me->theta+=i4_pi();     // turn around
112      s=0.001;
113    }
114
115    speed()=s;
116    me->h=h;
117  }
118
119  me->theta += turn_speed();
120
121  if (me->occupy_location())
122    me->request_think();
123
124
125  return 0;
126}
127
128li_automatic_add_function(g1_speed_damage, "speed_damage");
129li_automatic_add_function(g1_circle_think, "circle_think");
130li_automatic_add_function(g1_gunport_damage, "gunport_damage");
131li_automatic_add_function(g1_gunport_think, "gunport_think");
132li_automatic_add_function(g1_gunport_enter_range, "gunport_enter_range");
133
Note: See TracBrowser for help on using the repository browser.