source: golgotha/src/golg/objs/structure_death.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.0 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 "g1_object.hh"
10#include "map.hh"
11#include "map_man.hh"
12#include "lisp/li_class.hh"
13#include "objs/structure_death.hh"
14#include "objs/particle_emitter.hh"
15#include "objs/explode_model.hh"
16#include "objs/carcass.hh"
17#include "math/random.hh"
18#include "math/pi.hh"
19
20// circular distribution precomputation
21#include "objs/circle_distrib.cc"
22
23static li_symbol_ref particles("particle_emitter");
24static r1_texture_ref explosion2("smoke_particle");
25static li_symbol_ref explode_model("explode_model");
26static g1_model_ref carcass("garage_charred");
27
28g1_particle_emitter_params t_params;
29i4_float t_rad = 0.6;
30i4_float t_fac_grav = 0.002;
31i4_float t_roll = 0.01;
32i4_float t_rspeed = 0.05;
33
34int death_time = 50;
35
36class global_setter_class
37{
38public:
39  global_setter_class()
40  {
41    t_params.defaults();
42    t_params.start_size=0.4;
43    t_params.particle_lifetime=20;
44    t_params.grow_speed=-t_params.start_size/t_params.particle_lifetime;
45    t_params.max_speed=0.05;
46    t_params.air_friction=0.90;
47    t_params.num_create_attempts_per_tick=1;
48    t_params.creation_probability=0.50;
49    t_params.speed.set(0, 0, 0.05);
50    t_params.emitter_lifetime=death_time;
51  };
52} global_setter;
53
54i4_bool g1_structure_death_class::think()
55{
56  if (me->health<=0)
57  {
58    me->request_think();
59    me->health--;
60    me->h += i4_float(me->health)*t_fac_grav;
61    me->roll += t_roll;
62     
63    if (me->health<-death_time)
64    {
65      me->unoccupy_location();
66      me->request_remove();
67    }
68    return i4_F;
69  }
70  return i4_T;
71}
72
73void g1_structure_death_class::damage(g1_object_class *obj, int hp, i4_3d_vector damage_dir)
74{
75  if (me->health<=0)
76    return;
77
78  me->health-=hp;
79
80  if (me->health<=0)
81  {
82    me->health=0;
83
84    g1_explode_model_class *e;
85    e=(g1_explode_model_class *)g1_create_object(g1_get_object_type(explode_model.get()));
86    g1_explode_params params;
87    params.stages[0].setup(0,  0.0008, G1_APPLY_SING);
88    params.stages[1].setup(10, 0,      G1_APPLY_SING);
89    params.t_stages=2;
90    params.gravity=0.05;
91    e->setup(me, i4_3d_vector(0,0,0), params);
92
93    i4_float limit = me->occupancy_radius();
94    limit *= limit;
95
96    for (int n=0; n<sizeof(distrib)/sizeof(distrib[0]) && distrib[n][2]<limit; n++)
97    {
98      g1_particle_emitter_params params;
99      params.defaults();
100      params.start_size=0.4;
101      params.grow_speed=-params.start_size/20;
102      params.max_speed=0.1;
103      params.air_friction=0.90;
104      params.num_create_attempts_per_tick=1;
105      params.creation_probability=0.50;
106      params.particle_lifetime=20;
107      params.speed.set(0, 0, 0.05);
108
109      params = t_params;
110
111      params.emitter_lifetime += i4_rand()&0x15;
112
113      params.texture=explosion2.get();
114      g1_particle_emitter_class *emitter =
115        (g1_particle_emitter_class *)g1_create_object(g1_get_object_type(particles.get()));
116
117      i4_float
118        th = i4_float_rand()*i4_2pi(),
119        px = distrib[n][0] + me->x,
120        py = distrib[n][1] + me->y;
121
122      params.speed.x = t_rspeed*distrib[n][0];
123      params.speed.y = t_rspeed*distrib[n][1];
124
125      if (emitter)
126        emitter->setup(px,py, g1_get_map()->terrain_height(px,py), params);
127    }
128
129    g1_create_carcass(me, carcass.get(), -1, -1, 0);
130
131//     g1_object_class *o=g1_create_object(g1_get_object_type("garage_charred"));
132//     o->x = me->x;
133//     o->y = me->y;
134//     o->h = me->h;
135//     o->theta = me->theta;
136//     o->pitch = me->pitch;
137//     o->roll = me->roll;
138//     o->grab_old();
139//     o->occupy_location();
140
141    me->request_think();
142  }
143}
Note: See TracBrowser for help on using the repository browser.