gun_port.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/def_object.hh"
  9. #include "lisp/li_init.hh"
  10. #include "lisp/li_class.hh"
  11. #include "li_objref.hh"
  12. #include "map_man.hh"
  13. #include "map.hh"
  14. #include "math/pi.hh"
  15. static li_int_class_member health("health"), explode_health("explode_health"),
  16. fire_delay("fire_delay"), total_burst("total_burst"), burst_delay("burst_delay"),
  17. cost("cost"), range("range");
  18. static li_symbol_class_member fire_type("bullet");
  19. li_object *g1_gunport_damage(li_object *o, li_environment *env)
  20. {
  21. g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
  22. int hp=li_int::get(li_car(li_cdr(li_cdr(o))))->value();
  23. health()-=hp;
  24. me->request_think();
  25. return 0;
  26. }
  27. li_object *g1_gunport_enter_range(li_object *o, li_environment *env)
  28. {
  29. return 0;
  30. }
  31. li_object *g1_gunport_think(li_object *o, li_environment *env)
  32. {
  33. g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
  34. li_class *v=me->vars;
  35. if (health() < 0)
  36. {
  37. if (health() < explode_health())
  38. {
  39. me->unoccupy_location();
  40. me->request_remove();
  41. }
  42. else
  43. {
  44. me->set_flag(g1_object_class::DANGEROUS,0);
  45. health()--;
  46. me->request_think();
  47. }
  48. }
  49. return 0;
  50. }
  51. static li_float_class_member turn_speed("turn_speed"), speed("speed"),
  52. max_speed("max_speed"), hill_scale("hill_scale"), damage_speedup("damage_speedup");
  53. li_object *g1_speed_damage(li_object *o, li_environment *env)
  54. {
  55. g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
  56. int hp=li_int::get(li_car(li_cdr(li_cdr(o))))->value();
  57. speed()+=hp * damage_speedup();
  58. me->request_think();
  59. return 0;
  60. }
  61. li_object *g1_circle_think(li_object *o, li_environment *env)
  62. {
  63. g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
  64. me->grab_old();
  65. me->unoccupy_location();
  66. float s=speed();
  67. me->x += cos(me->theta)*s;
  68. me->y += sin(me->theta)*s;
  69. float h=g1_get_map()->terrain_height(me->x, me->y);
  70. if (h<me->h) // going down hill speed up
  71. {
  72. s += (me->h-h) * hill_scale();
  73. if (s>max_speed())
  74. s=max_speed();
  75. speed()=s;
  76. me->h=h;
  77. }
  78. else if (h>me->h) // going up hill, slow down
  79. {
  80. s += (me->h-h) * hill_scale();
  81. if (s<0)
  82. {
  83. me->theta+=i4_pi(); // turn around
  84. s=0.001;
  85. }
  86. speed()=s;
  87. me->h=h;
  88. }
  89. me->theta += turn_speed();
  90. if (me->occupy_location())
  91. me->request_think();
  92. return 0;
  93. }
  94. li_automatic_add_function(g1_speed_damage, "speed_damage");
  95. li_automatic_add_function(g1_circle_think, "circle_think");
  96. li_automatic_add_function(g1_gunport_damage, "gunport_damage");
  97. li_automatic_add_function(g1_gunport_think, "gunport_think");
  98. li_automatic_add_function(g1_gunport_enter_range, "gunport_enter_range");