OAI_QUER.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 : OAI_QUER.CPP
  21. //Description: AI - query functions
  22. #include <ALL.h>
  23. #include <OTOWN.h>
  24. #include <OFIRM.h>
  25. #include <ONATION.h>
  26. //--------- Begin of function Nation::check_firm_ready --------//
  27. //
  28. // <short> xLoc, yLoc - locatino of the firm.
  29. // [int] firmId - id. of the firm. If not given, don't
  30. // verify the firm id. (default: 0)
  31. //
  32. // return 1 means firm exists and belongs to our nation
  33. // return 0 otherwise
  34. //
  35. int Nation::check_firm_ready(short xLoc, short yLoc, int firmId)
  36. {
  37. Location *locPtr = world.get_loc(xLoc, yLoc);
  38. if(!locPtr->is_firm())
  39. return 0; // no firm there
  40. short firmRecno = locPtr->firm_recno();
  41. if(firm_array.is_deleted(firmRecno))
  42. return 0; // firm deleted
  43. Firm *firmPtr = firm_array[firmRecno];
  44. if(firmPtr->nation_recno!=nation_recno)
  45. return 0; // firm changed nation
  46. if( firmId && firmPtr->firm_id!=firmId )
  47. return 0;
  48. return 1;
  49. }
  50. //---------- End of function Nation::check_firm_ready --------//
  51. //--------- Begin of function Nation::check_town_ready --------//
  52. //
  53. // return 1 means town exists and belongs to our nation
  54. // return 0 otherwise
  55. //
  56. int Nation::check_town_ready(short xLoc, short yLoc)
  57. {
  58. Location *locPtr = world.get_loc(xLoc, yLoc);
  59. if(!locPtr->is_town())
  60. return 0; // no town there
  61. short townRecno = locPtr->town_recno();
  62. if(town_array.is_deleted(townRecno))
  63. return 0; // town deleted
  64. Town *townPtr = town_array[townRecno];
  65. if(townPtr->nation_recno!=nation_recno)
  66. return 0; // town changed nation
  67. return 1;
  68. }
  69. //---------- End of function Nation::check_town_ready --------//
  70. //--------- Begin of function Nation::can_ai_build --------//
  71. //
  72. // Whether the AI can build the specific firm type next to
  73. // the current firm.
  74. //
  75. int Nation::can_ai_build(int firmId)
  76. {
  77. //------- check whether the AI has enough cash -----//
  78. if( cash < firm_res[firmId]->setup_cost )
  79. return 0;
  80. return 1;
  81. }
  82. //--------- End of function Nation::can_ai_build --------//