bases.cc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 "lisp/li_class.hh"
  9. #include "g1_object.hh"
  10. #include "li_objref.hh"
  11. #include "math/random.hh"
  12. #include "math/pi.hh"
  13. #include "object_definer.hh"
  14. #include "player.hh"
  15. #include "controller.hh"
  16. #include "objs/path_object.hh"
  17. #include "objs/bases.hh"
  18. #include "sound/sfx_id.hh"
  19. #include "player.hh"
  20. #include "image_man.hh"
  21. #include "map.hh"
  22. #include "map_man.hh"
  23. i4_isl_list<g1_factory_class> g1_factory_list;
  24. static li_symbol_ref build("build");
  25. S1_SFX(sfx_built, "assembled/vehicle_ready_22khz.wav", S1_STREAMED, 100);
  26. static li_int_class_member ticks_till_next_deploy("ticks_till_next_deploy"),
  27. reset_time_in_ticks("reset_time_in_ticks"),
  28. path_color("path_color"),
  29. selected_path_color("selected_path_color");
  30. static li_g1_ref_class_member start("start");
  31. static li_object_class_member can_build("can_build");
  32. static g1_team_icon_ref airbase_radar_im("bitmaps/radar/airbase.tga");
  33. static g1_team_icon_ref garage_radar_im("bitmaps/radar/garage.tga");
  34. static g1_team_icon_ref mainbasepad_radar_im("bitmaps/radar/base_golg.tga");
  35. void g1_factory_class::set_start(g1_path_object_class *_start)
  36. {
  37. li_class_context context(vars);
  38. start();
  39. vars->set_value(start.offset, new li_g1_ref(_start));
  40. }
  41. g1_path_object_class *g1_factory_class::get_start()
  42. {
  43. g1_object_class *o=li_g1_ref::get(vars->get(start),0)->value();
  44. if (!o) return 0;
  45. return g1_path_object_class::cast(o);
  46. }
  47. w32 g1_factory_class::get_path_color()
  48. {
  49. return vars->get(path_color);
  50. }
  51. w32 g1_factory_class::get_selected_path_color()
  52. {
  53. return vars->get(selected_path_color);
  54. }
  55. g1_factory_class::g1_factory_class(g1_object_type id, g1_loader_class *fp)
  56. : g1_object_class(id,fp), death(this)
  57. {
  58. const char *n=name();
  59. char lod_n[256];
  60. sprintf(lod_n, "%s_lod", n);
  61. draw_params.setup(n,0,lod_n);
  62. if (!strcmp(n, "garage"))
  63. radar_image=&garage_radar_im;
  64. else if (!strcmp(n, "airbase"))
  65. radar_image=&airbase_radar_im;
  66. else if (!strcmp(n, "mainbasepad"))
  67. radar_image=&mainbasepad_radar_im;
  68. radar_type=G1_RADAR_BUILDING;
  69. set_flag(BLOCKING |
  70. CAN_DRIVE_ON |
  71. GROUND
  72. ,1);
  73. }
  74. i4_bool g1_factory_class::occupy_location()
  75. {
  76. if (g1_object_class::occupy_location())
  77. {
  78. g1_factory_list.insert(*this);
  79. return i4_T;
  80. }
  81. else
  82. return i4_F;
  83. }
  84. void g1_factory_class::unoccupy_location()
  85. {
  86. g1_object_class::unoccupy_location();
  87. g1_factory_list.find_and_unlink(this);
  88. }
  89. g1_map_piece_class *g1_factory_class::create_object(int type)
  90. {
  91. if (start()->value())
  92. {
  93. g1_object_class *o=g1_object_type_array[type]->create_object(type,0);
  94. if (o)
  95. {
  96. g1_map_piece_class *mp=g1_map_piece_class::cast(o);
  97. if (!mp)
  98. mp->request_remove();
  99. else
  100. {
  101. mp->player_num=player_num;
  102. mp->x=x; mp->y=y; mp->h=h;
  103. mp->theta=theta;
  104. mp->add_team_flag();
  105. mp->grab_old();
  106. mp->occupy_location();
  107. g1_player_man.get(mp->player_num)->add_object(mp->global_id);
  108. return mp;
  109. }
  110. }
  111. }
  112. return 0;
  113. }
  114. i4_bool g1_factory_class::build(int type)
  115. {
  116. li_class_context context(vars);
  117. g1_path_object_class *startp=get_start();
  118. if (startp)
  119. {
  120. // is this a object type we can build?
  121. int found=0;
  122. for (li_object *blist=can_build(); !found && blist; blist=li_cdr(blist,0))
  123. if (li_int::get(li_get_value(li_symbol::get(li_car(blist,0),0)),0)->value()==type)
  124. found=1;
  125. if (!found)
  126. return 0;
  127. int cost=g1_object_type_array[type]->defaults->cost;
  128. if (cost<=g1_player_man.get(player_num)->money() && !deploy_que.full())
  129. {
  130. if (player_num==g1_player_man.local_player)
  131. sfx_built.play();
  132. g1_player_man.get(player_num)->money()-=cost;
  133. g1_build_item item;
  134. item.type=type;
  135. g1_path_object_class *list[400];
  136. if (startp)
  137. {
  138. int t=startp->find_path(g1_player_man.get(player_num)->get_team(), list, 400);
  139. item.path=(g1_id_ref *)i4_malloc(sizeof(g1_id_ref) *(t+1), "");
  140. for (int i=0; i<t; i++)
  141. item.path[i]=list[i];
  142. item.path[t].id=0;
  143. }
  144. else
  145. item.path=0;
  146. deploy_que.que(item);
  147. request_think();
  148. return i4_T;
  149. }
  150. }
  151. return i4_F;
  152. }
  153. void g1_factory_class::think()
  154. {
  155. if (!death.think())
  156. return;
  157. if (ticks_till_next_deploy())
  158. {
  159. ticks_till_next_deploy()--;
  160. request_think();
  161. }
  162. else if (!deploy_que.empty())
  163. {
  164. ticks_till_next_deploy()=reset_time_in_ticks();
  165. g1_build_item item;
  166. deploy_que.deque(item);
  167. g1_map_piece_class *o=create_object(item.type);
  168. if (o)
  169. {
  170. o->set_path(item.path);
  171. char msg[100];
  172. sprintf(msg, "Vehicle advancing : %s", o->name());
  173. g1_player_man.show_message(msg, 0x00ff00, player_num);
  174. }
  175. else
  176. i4_free(item.path);
  177. request_think();
  178. }
  179. }
  180. void g1_factory_class::damage(g1_object_class *obj, int hp, i4_3d_vector damage_dir)
  181. {
  182. death.damage(obj, hp, damage_dir);
  183. }
  184. static g1_object_definer<g1_factory_class>
  185. garage_def("garage", g1_object_definition_class::EDITOR_SELECTABLE);
  186. static g1_object_definer<g1_factory_class>
  187. airbase_def("airbase", g1_object_definition_class::EDITOR_SELECTABLE);