verybiggun.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 "sound_man.hh"
  9. #include "objs/model_id.hh"
  10. #include "objs/model_draw.hh"
  11. #include "objs/rocktank.hh"
  12. #include "objs/verybiggun.hh"
  13. #include "input.hh"
  14. #include "math/pi.hh"
  15. #include "math/trig.hh"
  16. #include "math/angle.hh"
  17. #include "objs/bullet.hh"
  18. #include "resources.hh"
  19. #include "saver.hh"
  20. #include "map_cell.hh"
  21. #include "map.hh"
  22. #include "cell_id.hh"
  23. #include "sfx_id.hh"
  24. #include "object_definer.hh"
  25. static g1_object_type bullet;
  26. void g1_very_big_gun_init()
  27. {
  28. bullet = g1_get_object_type("bullet");
  29. }
  30. g1_object_definer<g1_very_big_gun_class>
  31. g1_very_big_gun_def("verybiggun", SELECTABLE, g1_very_big_gun_init);
  32. g1_fire_range_type g1_very_big_gun_class::range()
  33. {
  34. return (g1_fire_range_type)g1_very_big_gun_def.defaults->fire_range;
  35. }
  36. g1_very_big_gun_class::g1_very_big_gun_class(g1_object_type id,
  37. g1_loader_class *fp)
  38. : g1_map_piece_class(id,fp)
  39. {
  40. draw_params.setup("turret");
  41. defaults = g1_very_big_gun_def.defaults;
  42. w16 ver,data_size;
  43. if (fp)
  44. {
  45. fp->get_version(ver,data_size);
  46. if (ver==DATA_VERSION)
  47. {
  48. }
  49. else
  50. {
  51. fp->seek(fp->tell() + data_size);
  52. fire_delay = 15;
  53. health = 20;
  54. }
  55. fp->end_version(I4_LF);
  56. }
  57. else
  58. {
  59. fire_delay = 15;
  60. health = 20;
  61. }
  62. health = 200;
  63. //no sound for now
  64. //init_rumble_sound(g1_moving_engineering_vehicle_wav);
  65. maxspeed = 0; //doesnt move
  66. turn_speed = defaults->turn_speed;
  67. radar_type=G1_RADAR_BUILDING;
  68. set_flag(BLOCKING |
  69. SELECTABLE |
  70. TARGETABLE |
  71. GROUND |
  72. HIT_GROUND |
  73. SHADOWED, 1);
  74. }
  75. void g1_very_big_gun_class::save(g1_saver_class *fp)
  76. {
  77. g1_map_piece_class::save(fp);
  78. fp->start_version(DATA_VERSION);
  79. fp->end_version();
  80. }
  81. void g1_very_big_gun_class::fire()
  82. {
  83. if (attack_target.valid())
  84. {
  85. i4_float tmp_x,tmp_y,tmp_z;
  86. fire_delay = defaults->fire_delay;
  87. tmp_x = 0.4;
  88. tmp_y = 0;
  89. tmp_z = 0.2;
  90. i4_transform_class btrans,tmp1;
  91. i4_angle ang = theta;
  92. btrans.translate(0,0,0);
  93. tmp1.rotate_z(ang);
  94. btrans.multiply(tmp1);
  95. tmp1.rotate_y(pitch);
  96. btrans.multiply(tmp1);
  97. tmp1.rotate_x(roll);
  98. btrans.multiply(tmp1);
  99. i4_3d_point_class tpoint;
  100. btrans.transform(i4_3d_point_class(tmp_x,tmp_y,tmp_z),tpoint);
  101. i4_float bx,by,bz;
  102. bx = tpoint.x + x;
  103. by = tpoint.y + y;
  104. bz = tpoint.z + h;
  105. i4_float b_dx,b_dy,b_dz;
  106. btrans.transform(i4_3d_point_class(g1_resources.bullet_speed,0,0),tpoint);
  107. b_dx = tpoint.x;
  108. b_dy = tpoint.y;
  109. b_dz = tpoint.z;
  110. g1_bullet_class *b = (g1_bullet_class *)g1_create_object(bullet);
  111. if (b)
  112. {
  113. b->setup(bx, by, bz, b_dx, b_dy, b_dz, ang,pitch,roll,player_num,
  114. i4_F,
  115. defaults->damage,
  116. defaults->fire_range
  117. );
  118. b->set_owner(this);
  119. }
  120. }
  121. }
  122. void g1_very_big_gun_class::think()
  123. {
  124. check_life();
  125. if (find_new_target)
  126. find_target();
  127. if (health < 200)
  128. health++;
  129. pitch = groundpitch*cos(theta) - groundroll *sin(theta);
  130. roll = groundroll *cos(theta) + groundpitch*sin(theta);
  131. if (fire_delay>0)
  132. fire_delay--;
  133. //aim the turet
  134. if (attack_target.valid())
  135. {
  136. request_think();
  137. i4_float dx,dy,angle;
  138. //this will obviously only be true if attack_target.ref != NULL
  139. dx = (attack_target->x - x);
  140. dy = (attack_target->y - y);
  141. //aim the turet
  142. angle = i4_atan2(dy,dx);
  143. //snap it
  144. i4_normalize_angle(angle);
  145. if (!i4_rotate_to(theta,angle,turn_speed))
  146. if (!fire_delay)
  147. fire();
  148. }
  149. }