source: golgotha/src/golg/objs/damager.cc

Last change on this file was 80, checked in by Sam Hocevar, 12 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: 4.5 KB
Line 
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 "object_definer.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#include "objs/model_draw.hh"
17#include "math/angle.hh"
18#include "li_objref.hh"
19#include "g1_render.hh"
20#include "lisp/li_vect.hh"
21#include "tick_count.hh"
22
23static li_int_class_member ticks_to_think("ticks_to_think"),
24                           damage_per_tick("damage_per_tick");
25
26static li_object_class_member person_being_damaged("person_being_damaged"),
27                              person_giving_damage("person_giving_damage"),
28                              attach_pos("attach_pos");
29
30static li_symbol_class_member smoke_type("smoke_type");
31
32static li_symbol_ref acid("acid"), napalm("napalm");
33static r1_texture_ref acid_smoke("acid");
34
35class g1_damager_class : public g1_object_class
36{
37public:
38 
39  g1_damager_class(g1_object_type id, g1_loader_class *fp)
40    : g1_object_class(id, fp)
41  {
42    draw_params.setup("trigger");   
43  }
44 
45  void draw(g1_draw_context_class *context)
46  {
47    if (smoke_type()==acid.get())
48    {
49      float size=0.4;
50      float sw=size*0.25, sh=size;
51      i4_3d_vector pos(i4_interpolate(lx,x, g1_render.frame_ratio),
52                       i4_interpolate(ly,y, g1_render.frame_ratio),
53                       i4_interpolate(lh,h, g1_render.frame_ratio)+sh/2.0), t_pos;
54      context->transform->transform(pos, t_pos); 
55      g1_render.render_sprite(t_pos, acid_smoke.get(), sw, sh,
56                               (g1_tick_counter%4)*0.25, 0,
57                               (g1_tick_counter%4)*0.25+0.25, 1);
58    }
59   
60  }
61 
62  void think()
63  {
64    g1_object_class *hurt_this_guy = li_g1_ref::get(person_being_damaged(),0)->value();
65    g1_object_class *this_guys_hurting_him = li_g1_ref::get(person_giving_damage(),0)->value();
66    if (!this_guys_hurting_him)
67      this_guys_hurting_him=this;
68
69    if (ticks_to_think() && hurt_this_guy && hurt_this_guy->valid())
70    {
71      unoccupy_location();
72      grab_old();
73     
74      i4_3d_vector ap=li_vect::get(attach_pos(),0)->value();
75      x=hurt_this_guy->x+ap.x;
76      y=hurt_this_guy->y+ap.y;
77      h=hurt_this_guy->h+ap.z;
78     
79      occupy_location();
80     
81      ticks_to_think()--;
82
83      hurt_this_guy->damage(this_guys_hurting_him, damage_per_tick(), i4_3d_vector(0,0,1));
84      if (this_guys_hurting_him)
85        this_guys_hurting_him->notify_damage(hurt_this_guy, damage_per_tick());
86       
87      request_think();
88    }
89    else
90    {
91      unoccupy_location();
92      request_remove();
93    }
94  }
95};
96
97
98g1_object_definer<g1_damager_class>
99g1_damager_def("damager", g1_object_definition_class::EDITOR_SELECTABLE);
100
101
102g1_object_class *g1_create_damager_object(const i4_3d_vector &pos,
103                                          int _damage_per_tick, int _ticks,
104                                          g1_object_class *_person_giving_damage,
105                                          g1_object_class *_person_being_damaged,
106                                          li_symbol *_smoke_type)
107{
108  g1_damager_class *d=(g1_damager_class *)g1_create_object(g1_damager_def.type);
109  if (!d) return 0;
110
111 
112  d->x=d->lx=pos.x;
113  d->y=d->ly=pos.y;
114  d->h=d->lh=pos.z;
115 
116  d->vars->get(attach_pos)=new li_vect(i4_3d_vector(pos.x-_person_being_damaged->x,
117                                                    pos.y-_person_being_damaged->y,
118                                                    pos.z-_person_being_damaged->h));
119 
120  d->vars->get(damage_per_tick)=_damage_per_tick;
121  d->vars->get(person_being_damaged)=new li_g1_ref(_person_being_damaged->global_id);
122  if (_person_giving_damage)
123    d->vars->get(person_giving_damage)=new li_g1_ref(_person_giving_damage->global_id);
124  else
125    d->vars->get(person_giving_damage)=new li_g1_ref(g1_global_id.invalid_id());
126
127  d->vars->get(smoke_type)=_smoke_type;
128  d->vars->get(ticks_to_think)=_ticks;
129  d->occupy_location();
130  d->request_think();
131  return d;
132}
133
134
135
136
137
138
139
140
141
Note: See TracBrowser for help on using the repository browser.