OF_MARK.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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_MARK.H
  21. //Description : Header of FirmMarket
  22. #ifndef __OF_MARK_H
  23. #define __OF_MARK_H
  24. #ifndef __OFIRM_H
  25. #include <OFIRM.h>
  26. #endif
  27. #ifndef __OINFO_H
  28. #include <OINFO.h>
  29. #endif
  30. #ifndef __ORAWRES_H
  31. #include <ORAWRES.h>
  32. #endif
  33. #ifndef __TOWN_H
  34. #include <OTOWN.h>
  35. #endif
  36. //---------- Define constant -----------//
  37. #define PEASANT_GOODS_MONTH_DEMAND 0.5 // No. of unit of goods a peasant buys in a month
  38. #define WORKER_GOODS_MONTH_DEMAND 1 // No. of unit of goods a worker buys in a month
  39. #define MAX_MARKET_GOODS 3 // Maximum no. of types of goods the market trades for
  40. #define MAX_MARKET_STOCK 500
  41. //------- Define class MarketInfo --------//
  42. #pragma pack(1)
  43. struct MarketGoods
  44. {
  45. char raw_id;
  46. char product_raw_id;
  47. short input_firm_recno;
  48. float stock_qty;
  49. float cur_month_supply; // supply from direct linked firms only. One of its uses is determining whether we have enough supply to export
  50. float last_month_supply;
  51. float supply_30days() { return last_month_supply*(30-info.game_day)/30 +
  52. cur_month_supply; }
  53. float month_demand;
  54. float cur_month_sale_qty;
  55. float last_month_sale_qty;
  56. float sale_qty_30days() { return last_month_sale_qty*(30-info.game_day)/30 +
  57. cur_month_sale_qty; }
  58. float cur_year_sales;
  59. float last_year_sales;
  60. float sales_365days() { return last_year_sales*(365-info.year_day)/365 +
  61. cur_year_sales; }
  62. };
  63. #pragma pack()
  64. //------- Define class FirmMarket --------//
  65. #pragma pack(1)
  66. class FirmMarket : public Firm
  67. {
  68. public:
  69. float max_stock_qty; // maximum stock qty of each market goods
  70. MarketGoods market_goods_array[MAX_MARKET_GOODS];
  71. MarketGoods* market_raw_array[MAX_RAW];
  72. MarketGoods* market_product_array[MAX_PRODUCT]; // pointers to market_goods_array
  73. int free_slot_count();
  74. int stock_value_index(); // for AI, a 0-100 index number telling the total value of the market's stock
  75. short next_output_link_id;
  76. short next_output_firm_recno;
  77. //------------ ai vars -----------//
  78. int no_linked_town_since_date;
  79. int last_import_new_goods_date;
  80. char is_retail_market; // if 1, then it sells consumer products only, if 0, it sells raw materials only
  81. public:
  82. FirmMarket();
  83. ~FirmMarket();
  84. void init_derived();
  85. void draw(int displayLayer=1);
  86. void put_info(int refreshFlag);
  87. void detect_info();
  88. void next_day();
  89. void next_month();
  90. void next_year();
  91. void sell_goods();
  92. short hire_caravan(char remoteAction);
  93. int can_hire_caravan();
  94. void set_goods(int isRaw, int goodsId, int position);
  95. void clear_market_goods(int position);
  96. int is_market_linked_to_town(int ownBaseTownOnly=0);
  97. virtual FirmMarket* cast_to_FirmMarket() { return this; };
  98. void process_ai(); // ai process entry point
  99. int read_derived_file(File* filePtr);
  100. //-------------- multiplayer checking codes ---------------//
  101. virtual UCHAR crc8();
  102. virtual void clear_ptr();
  103. private:
  104. void put_market_info(int dispY1, int refreshFlag);
  105. void disp_income(int dispY1, int refreshFlag);
  106. void input_goods(int maxInputQty);
  107. void set_next_output_firm();
  108. void update_trade_link();
  109. void free_unused_slot();
  110. //------------------ AI actions --------------------//
  111. int think_del();
  112. void ai_update_link_status();
  113. int think_import_new_product();
  114. int think_increase_existing_product_supply();
  115. int think_import_specific_product(int productId);
  116. int think_mft_specific_product(int rawId);
  117. int think_export_product();
  118. int think_build_export_market(int townRecno);
  119. void think_demand_trade_treaty();
  120. void think_market_build_factory();
  121. int ai_create_new_trade(Firm* firmPtr, int stop1PickUpType, int stop2PickUpType);
  122. };
  123. #pragma pack()
  124. //--------------------------------------//
  125. #endif