Guest User

KaM_Remake_r10240_production_amounts_change

a guest
Dec 29th, 2019
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var
  2. Trunk, Stone, Timber, Iron_ore, Gold_ore, Coal, Iron, Gold, Wine, Corn, Loaves, Flour, Leather, Sausages, Pig, Skin, Wooden_shield, Long_shield, Leather_armor, Iron_armament, Handaxe, Longsword, Lance, Pike, Longbow, Crossbow, Horse, Fish: Integer;
  3. CPWares: array [0..11] of array[0..300] of Record Skip: Boolean; Excess1, Excess2, Excess3, Ware1, Ware2, Ware3, HouseID: Integer; end; //how many items?
  4. ProductionCount: array[0..11] of Integer; //as of now, there are at most 12 players
  5. CPIterator: Integer;
  6.  
  7. procedure SetProductionAmounts();
  8. begin
  9. Trunk :=2;
  10. Stone :=4;
  11. Timber :=3;
  12. Iron_ore :=2;
  13. Gold_ore :=2;
  14. Coal :=2;
  15. Iron :=2;
  16. Gold :=3;
  17. Wine :=2;
  18. Corn :=2;
  19. Loaves :=3;
  20. Flour :=2;
  21. Leather :=3;
  22. Sausages :=4;
  23. Pig :=2;
  24. Skin :=2;
  25. Wooden_shield :=2;
  26. Long_shield :=2;
  27. Leather_armor :=2;
  28. Iron_armament :=2;
  29. Handaxe :=2;
  30. Longsword :=2;
  31. Lance :=2;
  32. Pike :=2;
  33. Longbow :=2;
  34. Crossbow :=2;
  35. Horse :=2;
  36. Fish :=3;
  37. end;
  38.  
  39.  
  40. procedure SetProduction (Player, Index: Integer; Ware: word; Count: word; NewCount: Integer);
  41. var Store: integer;
  42. begin
  43. Actions.HouseTakeWaresFrom(CPWares[Player][Index].HouseID, Ware, Count);
  44. Store := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
  45. CPWares[Player][Index].Skip := true;
  46. if Store + NewCount > 5 then
  47. begin
  48. CPWares[Player][Index].Excess1 := CPWares[Player][Index].Excess1 + Store + NewCount - 5;
  49. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
  50. end else
  51. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
  52. end;
  53.  
  54. procedure SetProduction2 (Player, Index: Integer; Ware: word; Count: word; NewCount: Integer);
  55. var Store: integer;
  56. begin
  57. Actions.HouseTakeWaresFrom(CPWares[Player][Index].HouseID, Ware, Count);
  58. Store := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
  59. CPWares[Player][Index].Skip := true;
  60. if Store + NewCount > 5 then
  61. begin
  62. CPWares[Player][Index].Excess2 := CPWares[Player][Index].Excess2 + Store + NewCount - 5;
  63. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
  64. end else
  65. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
  66. end;
  67.  
  68. procedure SetProduction3 (Player, Index: Integer; Ware: word; Count: word; NewCount: Integer);
  69. var Store: integer;
  70. begin
  71. Actions.HouseTakeWaresFrom(CPWares[Player][Index].HouseID, Ware, Count);
  72. Store := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
  73. CPWares[Player][Index].Skip := true;
  74. if Store + NewCount > 5 then
  75. begin
  76. CPWares[Player][Index].Excess3 := CPWares[Player][Index].Excess3 + Store + NewCount - 5;
  77. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
  78. end else
  79. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
  80. end;
  81.  
  82. procedure ChangeProduction (Player, Index: Integer; Ware: word; Count: word);
  83. begin
  84. case Ware of
  85. 0: SetProduction(Player, Index, Ware, Count, Trunk);
  86. 1: SetProduction(Player, Index, Ware, Count, Stone);
  87. 2: SetProduction(Player, Index, Ware, Count, Timber);
  88. 3: SetProduction(Player, Index, Ware, Count, Iron_ore);
  89. 4: SetProduction(Player, Index, Ware, Count, Gold_ore);
  90. 5: SetProduction(Player, Index, Ware, Count, Coal);
  91. 6: SetProduction(Player, Index, Ware, Count, Iron);
  92. 7: SetProduction(Player, Index, Ware, Count, Gold);
  93. 8: SetProduction(Player, Index, Ware, Count, Wine);
  94. 9: SetProduction(Player, Index, Ware, Count, Corn);
  95. 10: SetProduction(Player, Index, Ware, Count, Loaves);
  96. 11: SetProduction(Player, Index, Ware, Count, Flour);
  97. 12: SetProduction(Player, Index, Ware, Count, Leather);
  98. 13: SetProduction(Player, Index, Ware, Count, Sausages);
  99. 14: SetProduction(Player, Index, Ware, Count, Pig);
  100. 15: SetProduction2(Player, Index, Ware, Count, Skin);
  101. 16: SetProduction(Player, Index, Ware, Count, Wooden_shield);
  102. 17: SetProduction(Player, Index, Ware, Count, Long_shield);
  103. 18: SetProduction2(Player, Index, Ware, Count, Leather_armor);
  104. 19: SetProduction2(Player, Index, Ware, Count, Iron_armament);
  105. 20: SetProduction(Player, Index, Ware, Count, Handaxe);
  106. 21: SetProduction(Player, Index, Ware, Count, Longsword);
  107. 22: SetProduction2(Player, Index, Ware, Count, Lance);
  108. 23: SetProduction2(Player, Index, Ware, Count, Pike);
  109. 24: SetProduction3(Player, Index, Ware, Count, Longbow);
  110. 25: SetProduction3(Player, Index, Ware, Count, Crossbow);
  111. 26: SetProduction(Player, Index, Ware, Count, Horse);
  112. 27: SetProduction(Player, Index, Ware, Count, Fish);
  113.  
  114.  
  115. end;
  116. end;
  117.  
  118. procedure ClearExcess (Player,Index: Integer);
  119. begin
  120. CPWares[Player][Index].Excess1 := 0;
  121. CPWares[Player][Index].Excess2 := 0;
  122. CPWares[Player][Index].Excess3 := 0;
  123. end;
  124.  
  125. procedure CPGetNext (Player, Index: Integer);
  126. begin
  127. CPWares[Player][Index].Skip := CPWares[Player][Index+1].Skip;
  128. CPWares[Player][Index].HouseID := CPWares[Player][Index+1].HouseID;
  129.  
  130. CPWares[Player][Index].Excess1 := CPWares[Player][Index+1].Excess1;
  131. CPWares[Player][Index].Excess2 := CPWares[Player][Index+1].Excess2;
  132. CPWares[Player][Index].Excess3 := CPWares[Player][Index+1].Excess3;
  133. CPWares[Player][Index].Ware1 := CPWares[Player][Index+1].Ware1;
  134. CPWares[Player][Index].Ware2 := CPWares[Player][Index+1].Ware2;
  135. CPWares[Player][Index].Ware3 := CPWares[Player][Index+1].Ware3;
  136. end;
  137.  
  138. procedure HouseInitialization (Player, HouseID, Ware1, Ware2, Ware3: Integer);
  139. begin
  140. ProductionCount[Player] := ProductionCount[Player]+1;
  141. CPWares[Player][ProductionCount[Player]-1].Skip := false;
  142. CPWares[Player][ProductionCount[Player]-1].Ware1 := Ware1;
  143. CPWares[Player][ProductionCount[Player]-1].Ware2 := Ware2;
  144. CPWares[Player][ProductionCount[Player]-1].Ware3 := Ware3;
  145. CPWares[Player][ProductionCount[Player]-1].HouseID := HouseID;
  146. CPWares[Player][ProductionCount[Player]-1].Skip := false;
  147. ClearExcess(Player,ProductionCount[Player]-1);
  148. end;
  149.  
  150.  
  151.  
  152. procedure Initialize_buildings ();
  153. var HouseList: array of Integer;
  154. var CPi, CPi2, Index: Integer;
  155. begin
  156. for CPi:=0 to States.StatPlayerCount()-1 do
  157. begin
  158. HouseList := States.PlayerGetAllHouses(CPi);
  159. ProductionCount[CPi] := 0;
  160. for CPi2 := 0 to Length(HouseList)-1 do
  161. begin
  162. case States.HouseType(HouseList[CPi2]) of
  163. 0: HouseInitialization (CPi, HouseList[CPi2], 2, 0, 0); //Sawmill
  164. 1: HouseInitialization (CPi, HouseList[CPi2], 6, 0, 0); // Iron Smithy
  165. 3: HouseInitialization (CPi, HouseList[CPi2], 5, 0, 0); //Coal Mine
  166. 4: HouseInitialization (CPi, HouseList[CPi2], 3, 0, 0); //Iron Mine
  167. 5: HouseInitialization (CPi, HouseList[CPi2], 4, 0, 0); //Gold Mine
  168. 6: HouseInitialization (CPi, HouseList[CPi2], 27, 0, 0); //Fisherman's Hut
  169. 7: HouseInitialization (CPi, HouseList[CPi2], 10, 0, 0); //Bakery
  170. 8: HouseInitialization (CPi, HouseList[CPi2], 9, 0, 0); //Farm
  171. 9: HouseInitialization (CPi, HouseList[CPi2], 0, 0, 0); //Woodcutter
  172. 12: HouseInitialization (CPi, HouseList[CPi2], 26, 0, 0); //Stables
  173. 14: HouseInitialization (CPi, HouseList[CPi2], 1, 0, 0); //Quarry
  174. 15: HouseInitialization (CPi, HouseList[CPi2], 7, 0, 0); //Metallurgist's
  175. 16: HouseInitialization (CPi, HouseList[CPi2], 14, 15, 0); //Swine Farm
  176. 22: HouseInitialization (CPi, HouseList[CPi2], 11, 0, 0); //Mill
  177. 24: HouseInitialization (CPi, HouseList[CPi2], 13, 0, 0); //Butcher's
  178. 25: HouseInitialization (CPi, HouseList[CPi2], 12, 0, 0); //Tannery
  179. 28: HouseInitialization (CPi, HouseList[CPi2], 8, 0, 0); //Vineyard
  180. 2: HouseInitialization (CPi, HouseList[CPi2], 21, 23, 25); // Weapon Smithy
  181. 10: HouseInitialization (CPi, HouseList[CPi2], 17, 19, 0); //Armor Smithy
  182. 19: HouseInitialization (CPi, HouseList[CPi2], 20, 22, 24); //Weapons Workshop
  183. 20: HouseInitialization (CPi, HouseList[CPi2], 16, 18, 0); //Armor Workshop
  184. end;
  185. end;
  186. end;
  187. end;
  188.  
  189. procedure PrepareNewHouse (aHouse: Integer);
  190. var CPtmp: Integer;
  191. begin
  192. CPtmp := States.HouseOwner(aHouse);
  193. case States.HouseType(aHouse) of
  194. 0: HouseInitialization (CPtmp, aHouse, 2, 0, 0); //Sawmill
  195. 1: HouseInitialization (CPtmp, aHouse, 6, 0, 0); // Iron Smithy
  196. 3: HouseInitialization (CPtmp, aHouse, 5, 0, 0); //Coal Mine
  197. 4: HouseInitialization (CPtmp, aHouse, 3, 0, 0); //Iron Mine
  198. 5: HouseInitialization (CPtmp, aHouse, 4, 0, 0); //Gold Mine
  199. 6: HouseInitialization (CPtmp, aHouse, 27, 0, 0); //Fisherman's Hut
  200. 7: HouseInitialization (CPtmp, aHouse, 10, 0, 0); //Bakery
  201. 8: HouseInitialization (CPtmp, aHouse, 9, 0, 0); //Farm
  202. 9: HouseInitialization (CPtmp, aHouse, 0, 0, 0); //Woodcutter
  203. 12: HouseInitialization (CPtmp, aHouse, 26, 0, 0); //Stables
  204. 14: HouseInitialization (CPtmp, aHouse, 1, 0, 0); //Quarry
  205. 15: HouseInitialization (CPtmp, aHouse, 7, 0, 0); //Metallurgist's
  206. 16: HouseInitialization (CPtmp, aHouse, 14, 15, 0); //Swine Farm
  207. 22: HouseInitialization (CPtmp, aHouse, 11, 0, 0); //Mill
  208. 24: HouseInitialization (CPtmp, aHouse, 13, 0, 0); //Butcher's
  209. 25: HouseInitialization (CPtmp, aHouse, 12, 0, 0); //Tannery
  210. 28: HouseInitialization (CPtmp, aHouse, 8, 0, 0); //Vineyard
  211. 2: HouseInitialization (CPtmp, aHouse, 21, 23, 25); // Weapon Smithy
  212. 10: HouseInitialization (CPtmp, aHouse, 17, 19, 0); //Armor Smithy
  213. 19: HouseInitialization (CPtmp, aHouse, 20, 22, 24); //Weapons Workshop
  214. 20: HouseInitialization (CPtmp, aHouse, 16, 18, 0); //Armor Workshop
  215. end;
  216. end;
  217.  
  218. procedure RemoveHouse(aHouse: Integer);
  219. var CPtmp: Integer;
  220. var CPi, CPi2: Integer;
  221. begin
  222. CPtmp := States.HouseOwner(aHouse);
  223. for CPi := 0 to ProductionCount[CPtmp] do
  224. begin
  225. if CPi = ProductionCount[CPtmp] then exit;
  226. if aHouse = CPWares[CPtmp][CPi].HouseID then break;
  227. end;
  228. begin
  229. for CPi2 := CPi to ProductionCount[CPtmp]-1 do
  230. CPGetNext(CPtmp, CPi2);
  231. ProductionCount[CPtmp] := ProductionCount[CPtmp]-1;
  232. end;
  233. end;
  234.  
  235. procedure CheckProduction(aHouse: Integer; aType: word; aCount: word);
  236. var CPtmp: Integer;
  237. var CPi: Integer;
  238. begin
  239. CPtmp := States.HouseOwner(aHouse);
  240. for CPi := 0 to ProductionCount[CPtmp] do
  241. begin
  242. if CPi = ProductionCount[CPtmp] then exit;
  243. if CPWares[CPtmp][CPi].HouseId = aHouse then break;
  244. end;
  245. if CPWares[CPtmp][CPi].Skip = false then
  246. begin
  247. ChangeProduction(CPtmp, CPi, aType, aCount);
  248. end
  249. else CPWares[CPtmp][CPi].Skip := false;
  250. end;
  251.  
  252. procedure CPFill1(Player, Index, Ware: Integer);
  253. var Count, Addition: Integer;
  254. begin
  255. Count := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
  256. if Count < 5 then if CPWares[Player][Index].Excess1 > 0 then
  257. begin
  258. CPWares[Player][Index].Skip := true;
  259. if CPWares[Player][Index].Excess1 + Count > 5 then
  260. begin
  261. Addition := 5 - Count;
  262. CPWares[Player][Index].Excess1 := CPWares[Player][Index].Excess1 - Addition;
  263. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, Addition);
  264. end else
  265. begin
  266. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, CPWares[Player][Index].Excess1);
  267. CPWares[Player][Index].Excess1 := 0;
  268. end;
  269. end;
  270. end;
  271.  
  272. procedure CPFill2(Player, Index, Ware: Integer);
  273. var Count, Addition: Integer;
  274. begin
  275. Count := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
  276. if Count < 5 then if CPWares[Player][Index].Excess2 > 0 then
  277. begin
  278. CPWares[Player][Index].Skip := true;
  279. if CPWares[Player][Index].Excess2 + Count > 5 then
  280. begin
  281. Addition := 5 - Count;
  282. CPWares[Player][Index].Excess2 := CPWares[Player][Index].Excess2 - Addition;
  283. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, Addition);
  284. end else
  285. begin
  286. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, CPWares[Player][Index].Excess2);
  287. CPWares[Player][Index].Excess2 := 0;
  288. end;
  289. end;
  290. end;
  291.  
  292. procedure CPFill3(Player, Index, Ware: Integer);
  293. var Count, Addition: Integer;
  294. begin
  295. Count := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
  296. if Count < 5 then if CPWares[Player][Index].Excess3 > 0 then
  297. begin
  298. CPWares[Player][Index].Skip := true;
  299. if CPWares[Player][Index].Excess3 + Count > 5 then
  300. begin
  301. Addition := 5 - Count;
  302. CPWares[Player][Index].Excess3 := CPWares[Player][Index].Excess3 - Addition;
  303. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, Addition);
  304. end else
  305. begin
  306. Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, CPWares[Player][Index].Excess3);
  307. CPWares[Player][Index].Excess3 := 0;
  308. end;
  309. end;
  310. end;
  311.  
  312. procedure FillWaresOverLimit (Player: Integer);
  313. var CPi, Count, Addition: Integer;
  314. Begin
  315. for CPi := 0 to ProductionCount[Player]-1 do
  316. begin
  317. case States.HouseType(CPWares[Player][CPi].HouseID) of
  318. 0: CPFill1(Player, CPi, 2); //Sawmill
  319. 1: CPFill1(Player, CPi, 6); // Iron Smithy
  320. 3: CPFill1(Player, CPi, 5); //Coal Mine
  321. 4: CPFill1(Player, CPi, 3); //Iron Mine
  322. 5: CPFill1(Player, CPi, 4); //Gold Mine
  323. 6: CPFill1(Player, CPi, 27); //Fisherman's Hut
  324. 7: CPFill1(Player, CPi, 10); //Bakery
  325. 8: CPFill1(Player, CPi, 9); //Farm
  326. 9: CPFill1(Player, CPi, 0); //Woodcutter
  327. 12: CPFill1(Player, CPi, 26); //Stables
  328. 14: CPFill1(Player, CPi, 1); //Quarry
  329. 15: CPFill1(Player, CPi, 7); //Metallurgist's
  330. 16: begin //Swine Farm
  331. CPFill1(Player, CPi, 14);
  332. CPFill2(Player, CPi, 15);
  333. end;
  334. 22: CPFill1(Player, CPi, 11); //Mill
  335. 24: CPFill1(Player, CPi, 13); //Butcher's
  336. 25: CPFill1(Player, CPi, 12); //Tannery
  337. 28: CPFill1(Player, CPi, 8); //Vineyard
  338. 2: begin // Weapon Smithy
  339. CPFill1(Player, CPi, 21);
  340. CPFill2(Player, CPi, 23);
  341. CPFill3(Player, CPi, 25);
  342. end;
  343. 10: begin //Armor Smithy
  344. CPFill1(Player, CPi, 17);
  345. CPFill2(Player, CPi, 19);
  346. end;
  347. 19: begin //Weapons Workshop
  348. CPFill1(Player, CPi, 20);
  349. CPFill2(Player, CPi, 22);
  350. CPFill3(Player, CPi, 24);
  351. end;
  352. 20: begin //Armor Workshop
  353. CPFill1(Player, CPi, 16);
  354. CPFill2(Player, CPi, 18);
  355. end;
  356.  
  357. end;
  358. end;
  359. end;
  360.  
  361.  
  362. procedure OnMissionStart;
  363. begin
  364. SetProductionAmounts();
  365. end;
  366.  
  367. procedure OnHouseBuilt(aHouse: Integer);
  368. begin
  369. PrepareNewHouse(aHouse);
  370. end;
  371.  
  372. procedure OnHouseDestroyed (aHouse: Integer);
  373. begin
  374. RemoveHouse(aHouse);
  375. end;
  376.  
  377.  
  378. procedure OnWareProduced(aHouse: Integer; aType: word; aCount: word);
  379. begin
  380. CheckProduction(aHouse,aType,aCount);
  381. end;
  382.  
  383. procedure OnTick;
  384. begin
  385. if States.GameTime() = 1 then
  386. Initialize_buildings ();
  387.  
  388. for CPIterator := 0 to 11 do
  389. if States.GameTime() mod 20 = CPIterator then FillWaresOverLimit(CPIterator);
  390. end;
RAW Paste Data