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

Last change on this file 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.2 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 "objs/chunk_explosion.hh"
10#include "object_definer.hh"
11#include "objs/explode_model.hh"
12#include "map.hh"
13#include "map_man.hh"
14#include "lisp/lisp.hh"
15#include "g1_rand.hh"
16#include "objs/explosion1.hh"
17#include "time/profile.hh"
18
19static i4_profile_class pf_chunk_explosion("chunk_explosion");
20
21g1_chunk_explosion_class::g1_chunk_explosion_class(g1_object_type id, g1_loader_class *fp)
22  : g1_object_class(id, fp) {}
23
24void g1_chunk_explosion_class::setup(const i4_3d_vector &pos,
25                                     const i4_3d_vector &rotations,
26                                     g1_quad_object_class *model,
27                                     const i4_3d_vector &_dir,
28                                     int ticks_till_explode)
29
30{
31  dir=_dir;
32  dir.x=dir.x*0.1 + g1_float_rand(5)*0.04-0.08;
33  dir.y=dir.y*0.1 + g1_float_rand(7)*0.04-0.08;
34  dir.z=g1_float_rand(6)*0.1+0.1;
35
36  avel.x=g1_float_rand(8)*0.2;
37  avel.y=g1_float_rand(1)*0.2;
38  avel.z=g1_float_rand(0)*0.4-0.2;
39 
40  ticks_left=ticks_till_explode;
41     
42  draw_params.setup(model);
43  x=lx=pos.x;
44  y=ly=pos.y;
45  h=lh=pos.z;
46  theta = rotations.z;
47  pitch = rotations.y;
48  roll = rotations.x;
49  occupy_location();
50  request_think();
51}             
52             
53void g1_chunk_explosion_class::draw(g1_draw_context_class *context)
54{
55  g1_model_draw(this, draw_params, context);
56}
57
58static li_symbol_ref explode_model("explode_model");
59
60float jc_f=0.0008;
61float jc_l=0.2;
62
63static li_symbol_ref explosion1("explosion1");
64
65void g1_chunk_explosion_class::think()
66{
67  pf_chunk_explosion.start();
68
69  if (!ticks_left)
70  {
71    g1_explode_model_class *e;
72    e=(g1_explode_model_class *)g1_create_object(g1_get_object_type(explode_model.get()));
73    g1_explode_params params;
74    params.stages[0].setup(1, jc_f, G1_APPLY_SING);
75    params.stages[1].setup(20, 0, G1_APPLY_SING);
76    params.t_stages=2;
77    e->setup(this, i4_3d_vector(0,0,0), params);
78
79    g1_explosion1_class *explosion;
80    explosion=(g1_explosion1_class *)g1_create_object(g1_get_object_type(explosion1.get()));
81    explosion->setup(x,y,h);
82         
83    unoccupy_location();
84    request_remove();
85  }
86  else
87  {
88    i4_3d_vector ray=dir;
89
90    g1_object_class *hit;
91    if (g1_get_map()->check_non_player_collision(0xff, i4_3d_vector(x,y,h), ray, hit))
92      dir.z=-dir.z*0.75;
93
94    unoccupy_location();
95    grab_old();
96    x+=ray.x;
97    y+=ray.y;
98    h+=ray.z;
99
100    pitch+=avel.x;
101    roll+=avel.y;
102    theta+=avel.z;
103
104    if (occupy_location())
105      request_think();
106    ticks_left--;
107  }
108
109  pf_chunk_explosion.stop();
110}
111
112
113g1_object_definer<g1_chunk_explosion_class> g1_chunk_explosion_def("chunk_explosion");
114
115
116
Note: See TracBrowser for help on using the repository browser.