chunk_explosion.cc 3.2 KB

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