OFIRM2.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OFIRM2.CPP
  21. //Description : Class Firm - part 2
  22. #include <OFIRM.h>
  23. #include <OTOWN.h>
  24. #include <OSPY.h>
  25. #include <ONATION.h>
  26. #include <ORACERES.h>
  27. #include <OUNIT.h>
  28. //--------- Begin of function Firm::kill_overseer ---------//
  29. //
  30. // Kill the overeseer of the firm
  31. //
  32. void Firm::kill_overseer()
  33. {
  34. if( !overseer_recno )
  35. return;
  36. //-------- if the overseer is a spy -------//
  37. Unit* unitPtr = unit_array[overseer_recno];
  38. if( unitPtr->spy_recno )
  39. spy_array[unitPtr->spy_recno]->set_place(SPY_UNDEFINED, 0);
  40. //-- no need to del the spy here, unit_array.del() will del the spy --//
  41. //-----------------------------------------//
  42. if( overseer_town_recno )
  43. town_array[overseer_town_recno]->dec_pop(unit_array[overseer_recno]->race_id, 1);
  44. unit_array.del(overseer_recno);
  45. overseer_recno = 0;
  46. }
  47. //----------- End of function Firm::kill_overseer -----------//
  48. //--------- Begin of function Firm::kill_all_worker ---------//
  49. //
  50. // All the workers in the firm are deleted
  51. //
  52. void Firm::kill_all_worker()
  53. {
  54. for(int i=worker_count; i>0; i--)
  55. kill_worker(i);
  56. }
  57. //----------- End of function Firm::kill_all_worker -----------//
  58. //--------- Begin of function Firm::kill_worker ---------//
  59. //
  60. // Kill a specific worker.
  61. //
  62. void Firm::kill_worker(int workerId)
  63. {
  64. err_when( !worker_array ); // this function shouldn't be called if this firm does not need worker
  65. err_when( workerId<1 || workerId>worker_count );
  66. //------- decrease worker no. and create an unit -----//
  67. Worker* workerPtr = worker_array+workerId-1;
  68. int unitRecno = 0;
  69. if( workerPtr->race_id && workerPtr->name_id )
  70. race_res[workerPtr->race_id]->free_name_id(workerPtr->name_id);
  71. if( workerPtr->town_recno ) // town_recno is 0 if the workers in the firm do not live in towns
  72. town_array[workerPtr->town_recno]->dec_pop(workerPtr->race_id, 1); // 1-has job
  73. //-------- if this worker is a spy ---------//
  74. if( workerPtr->spy_recno )
  75. {
  76. spy_array[workerPtr->spy_recno]->set_place(SPY_UNDEFINED, 0);
  77. spy_array.del_spy( workerPtr->spy_recno );
  78. }
  79. //--- decrease the nation unit count as the Unit has already increased it ----//
  80. if( !firm_res[firm_id]->live_in_town ) // if the unit does not live in town, increase the unit count now
  81. unit_res[workerPtr->unit_id]->dec_nation_unit_count(nation_recno);
  82. //------- delete the record from the worker_array ------//
  83. err_when( worker_count > MAX_WORKER );
  84. err_when( selected_worker_id > worker_count );
  85. m.del_array_rec(worker_array, worker_count, sizeof(Worker), workerId);
  86. if( selected_worker_id > workerId || selected_worker_id == worker_count )
  87. selected_worker_id--;
  88. worker_count--;
  89. if( worker_count==0 )
  90. selected_worker_id = 0;
  91. err_when( selected_worker_id > worker_count );
  92. }
  93. //----------- End of function Firm::kill_worker -----------//
  94. //--------- Begin of function Firm::kill_builder ---------//
  95. void Firm::kill_builder(short builderRecno)
  96. {
  97. unit_array.del(builderRecno);
  98. }
  99. //----------- End of function Firm::kill_builder -----------//
  100. //--------- Begin of function Firm::locate_space ---------//
  101. int Firm::locate_space(int removeFirm, int &xLoc, int &yLoc, int xLoc2, int yLoc2, int width, int height, int mobileType, int regionId)
  102. {
  103. int checkXLoc, checkYLoc;
  104. if(removeFirm)
  105. {
  106. //*** note only for land unit with size 1x1 ***//
  107. char mType = UNIT_LAND;
  108. for(checkYLoc=loc_y1; checkYLoc<=loc_y2; checkYLoc++)
  109. {
  110. for(checkXLoc=loc_x1; checkXLoc<=loc_x2; checkXLoc++)
  111. {
  112. if(world.get_loc(checkXLoc, checkYLoc)->can_move(mType))
  113. {
  114. xLoc = checkXLoc;
  115. yLoc = checkYLoc;
  116. return 1;
  117. }
  118. }
  119. }
  120. }
  121. else
  122. {
  123. checkXLoc = loc_x1;
  124. checkYLoc = loc_y1;
  125. if(!world.locate_space(checkXLoc, checkYLoc, xLoc2, yLoc2, width, height, mobileType, regionId))
  126. return 0;
  127. else
  128. {
  129. xLoc = checkXLoc;
  130. yLoc = checkYLoc;
  131. return 1;
  132. }
  133. }
  134. return 0;
  135. }
  136. //----------- End of function Firm::locate_space -----------//