OF_RESE2.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 : OF_RESE2.CPP
  21. //Description : Firm Research Center - AI functions
  22. #include <ONATION.h>
  23. #include <OINFO.h>
  24. #include <OTOWN.h>
  25. #include <OUNIT.h>
  26. #include <OTECHRES.h>
  27. #include <OF_RESE.h>
  28. //--------- Begin of function FirmResearch::process_ai ---------//
  29. void FirmResearch::process_ai()
  30. {
  31. //---- think about which technology to research ----//
  32. if( !tech_id )
  33. think_new_research();
  34. //------- recruit workers ---------//
  35. if( info.game_date%15==firm_recno%15 )
  36. {
  37. if( worker_count < MAX_WORKER )
  38. ai_recruit_worker();
  39. }
  40. //----- think about closing down this firm -----//
  41. if( info.game_date%30==firm_recno%30 )
  42. {
  43. if( think_del() )
  44. return;
  45. }
  46. }
  47. //----------- End of function FirmResearch::process_ai -----------//
  48. //------- Begin of function FirmResearch::think_del -----------//
  49. //
  50. // Think about deleting this firm.
  51. //
  52. int FirmResearch::think_del()
  53. {
  54. //----- if all technologies have been researched -----//
  55. if( nation_array[nation_recno]->total_tech_level() == tech_res.total_tech_level ) // all technology have been researched
  56. {
  57. ai_del_firm();
  58. return 1;
  59. }
  60. //----------------------------------------------//
  61. if( worker_count > 0 )
  62. return 0;
  63. //-- check whether the firm is linked to any towns or not --//
  64. for( int i=0 ; i<linked_town_count ; i++ )
  65. {
  66. if( linked_town_enable_array[i] == LINK_EE )
  67. return 0;
  68. }
  69. //------------------------------------------------//
  70. ai_del_firm();
  71. return 1;
  72. }
  73. //--------- End of function FirmResearch::think_del -----------//
  74. //----- Begin of function FirmResearch::think_new_research ------//
  75. //
  76. // Think about which technology to research.
  77. //
  78. void FirmResearch::think_new_research()
  79. {
  80. TechInfo* techInfo;
  81. int bestTechId=0, curRating, bestRating=0;
  82. for( int techId=tech_res.tech_count ; techId>0 ; techId-- )
  83. {
  84. techInfo = tech_res[techId];
  85. if( techInfo->can_research(nation_recno) )
  86. {
  87. curRating = 100 + techInfo->is_nation_researching(nation_recno)*20;
  88. if( curRating > bestRating ||
  89. ( curRating==bestRating && m.random(2)==0 ) )
  90. {
  91. bestTechId = techId;
  92. bestRating = curRating;
  93. }
  94. }
  95. }
  96. //------------------------------------//
  97. if( bestTechId )
  98. start_research( bestTechId, COMMAND_AI );
  99. }
  100. //------ End of function FirmResearch::think_new_research -------//