Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- 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;
- CPWares: array [0..11] of array[0..300] of Record Skip: Boolean; Excess1, Excess2, Excess3, Ware1, Ware2, Ware3, HouseID: Integer; end; //how many items?
- ProductionCount: array[0..11] of Integer; //as of now, there are at most 12 players
- CPIterator: Integer;
- procedure SetProductionAmounts();
- begin
- Trunk :=2;
- Stone :=4;
- Timber :=3;
- Iron_ore :=2;
- Gold_ore :=2;
- Coal :=2;
- Iron :=2;
- Gold :=3;
- Wine :=2;
- Corn :=2;
- Loaves :=3;
- Flour :=2;
- Leather :=3;
- Sausages :=4;
- Pig :=2;
- Skin :=2;
- Wooden_shield :=2;
- Long_shield :=2;
- Leather_armor :=2;
- Iron_armament :=2;
- Handaxe :=2;
- Longsword :=2;
- Lance :=2;
- Pike :=2;
- Longbow :=2;
- Crossbow :=2;
- Horse :=2;
- Fish :=3;
- end;
- procedure SetProduction (Player, Index: Integer; Ware: word; Count: word; NewCount: Integer);
- var Store: integer;
- begin
- Actions.HouseTakeWaresFrom(CPWares[Player][Index].HouseID, Ware, Count);
- Store := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
- CPWares[Player][Index].Skip := true;
- if Store + NewCount > 5 then
- begin
- CPWares[Player][Index].Excess1 := CPWares[Player][Index].Excess1 + Store + NewCount - 5;
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
- end else
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
- end;
- procedure SetProduction2 (Player, Index: Integer; Ware: word; Count: word; NewCount: Integer);
- var Store: integer;
- begin
- Actions.HouseTakeWaresFrom(CPWares[Player][Index].HouseID, Ware, Count);
- Store := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
- CPWares[Player][Index].Skip := true;
- if Store + NewCount > 5 then
- begin
- CPWares[Player][Index].Excess2 := CPWares[Player][Index].Excess2 + Store + NewCount - 5;
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
- end else
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
- end;
- procedure SetProduction3 (Player, Index: Integer; Ware: word; Count: word; NewCount: Integer);
- var Store: integer;
- begin
- Actions.HouseTakeWaresFrom(CPWares[Player][Index].HouseID, Ware, Count);
- Store := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
- CPWares[Player][Index].Skip := true;
- if Store + NewCount > 5 then
- begin
- CPWares[Player][Index].Excess3 := CPWares[Player][Index].Excess3 + Store + NewCount - 5;
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
- end else
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, NewCount);
- end;
- procedure ChangeProduction (Player, Index: Integer; Ware: word; Count: word);
- begin
- case Ware of
- 0: SetProduction(Player, Index, Ware, Count, Trunk);
- 1: SetProduction(Player, Index, Ware, Count, Stone);
- 2: SetProduction(Player, Index, Ware, Count, Timber);
- 3: SetProduction(Player, Index, Ware, Count, Iron_ore);
- 4: SetProduction(Player, Index, Ware, Count, Gold_ore);
- 5: SetProduction(Player, Index, Ware, Count, Coal);
- 6: SetProduction(Player, Index, Ware, Count, Iron);
- 7: SetProduction(Player, Index, Ware, Count, Gold);
- 8: SetProduction(Player, Index, Ware, Count, Wine);
- 9: SetProduction(Player, Index, Ware, Count, Corn);
- 10: SetProduction(Player, Index, Ware, Count, Loaves);
- 11: SetProduction(Player, Index, Ware, Count, Flour);
- 12: SetProduction(Player, Index, Ware, Count, Leather);
- 13: SetProduction(Player, Index, Ware, Count, Sausages);
- 14: SetProduction(Player, Index, Ware, Count, Pig);
- 15: SetProduction2(Player, Index, Ware, Count, Skin);
- 16: SetProduction(Player, Index, Ware, Count, Wooden_shield);
- 17: SetProduction(Player, Index, Ware, Count, Long_shield);
- 18: SetProduction2(Player, Index, Ware, Count, Leather_armor);
- 19: SetProduction2(Player, Index, Ware, Count, Iron_armament);
- 20: SetProduction(Player, Index, Ware, Count, Handaxe);
- 21: SetProduction(Player, Index, Ware, Count, Longsword);
- 22: SetProduction2(Player, Index, Ware, Count, Lance);
- 23: SetProduction2(Player, Index, Ware, Count, Pike);
- 24: SetProduction3(Player, Index, Ware, Count, Longbow);
- 25: SetProduction3(Player, Index, Ware, Count, Crossbow);
- 26: SetProduction(Player, Index, Ware, Count, Horse);
- 27: SetProduction(Player, Index, Ware, Count, Fish);
- end;
- end;
- procedure ClearExcess (Player,Index: Integer);
- begin
- CPWares[Player][Index].Excess1 := 0;
- CPWares[Player][Index].Excess2 := 0;
- CPWares[Player][Index].Excess3 := 0;
- end;
- procedure CPGetNext (Player, Index: Integer);
- begin
- CPWares[Player][Index].Skip := CPWares[Player][Index+1].Skip;
- CPWares[Player][Index].HouseID := CPWares[Player][Index+1].HouseID;
- CPWares[Player][Index].Excess1 := CPWares[Player][Index+1].Excess1;
- CPWares[Player][Index].Excess2 := CPWares[Player][Index+1].Excess2;
- CPWares[Player][Index].Excess3 := CPWares[Player][Index+1].Excess3;
- CPWares[Player][Index].Ware1 := CPWares[Player][Index+1].Ware1;
- CPWares[Player][Index].Ware2 := CPWares[Player][Index+1].Ware2;
- CPWares[Player][Index].Ware3 := CPWares[Player][Index+1].Ware3;
- end;
- procedure HouseInitialization (Player, HouseID, Ware1, Ware2, Ware3: Integer);
- begin
- ProductionCount[Player] := ProductionCount[Player]+1;
- CPWares[Player][ProductionCount[Player]-1].Skip := false;
- CPWares[Player][ProductionCount[Player]-1].Ware1 := Ware1;
- CPWares[Player][ProductionCount[Player]-1].Ware2 := Ware2;
- CPWares[Player][ProductionCount[Player]-1].Ware3 := Ware3;
- CPWares[Player][ProductionCount[Player]-1].HouseID := HouseID;
- CPWares[Player][ProductionCount[Player]-1].Skip := false;
- ClearExcess(Player,ProductionCount[Player]-1);
- end;
- procedure Initialize_buildings ();
- var HouseList: array of Integer;
- var CPi, CPi2, Index: Integer;
- begin
- for CPi:=0 to States.StatPlayerCount()-1 do
- begin
- HouseList := States.PlayerGetAllHouses(CPi);
- ProductionCount[CPi] := 0;
- for CPi2 := 0 to Length(HouseList)-1 do
- begin
- case States.HouseType(HouseList[CPi2]) of
- 0: HouseInitialization (CPi, HouseList[CPi2], 2, 0, 0); //Sawmill
- 1: HouseInitialization (CPi, HouseList[CPi2], 6, 0, 0); // Iron Smithy
- 3: HouseInitialization (CPi, HouseList[CPi2], 5, 0, 0); //Coal Mine
- 4: HouseInitialization (CPi, HouseList[CPi2], 3, 0, 0); //Iron Mine
- 5: HouseInitialization (CPi, HouseList[CPi2], 4, 0, 0); //Gold Mine
- 6: HouseInitialization (CPi, HouseList[CPi2], 27, 0, 0); //Fisherman's Hut
- 7: HouseInitialization (CPi, HouseList[CPi2], 10, 0, 0); //Bakery
- 8: HouseInitialization (CPi, HouseList[CPi2], 9, 0, 0); //Farm
- 9: HouseInitialization (CPi, HouseList[CPi2], 0, 0, 0); //Woodcutter
- 12: HouseInitialization (CPi, HouseList[CPi2], 26, 0, 0); //Stables
- 14: HouseInitialization (CPi, HouseList[CPi2], 1, 0, 0); //Quarry
- 15: HouseInitialization (CPi, HouseList[CPi2], 7, 0, 0); //Metallurgist's
- 16: HouseInitialization (CPi, HouseList[CPi2], 14, 15, 0); //Swine Farm
- 22: HouseInitialization (CPi, HouseList[CPi2], 11, 0, 0); //Mill
- 24: HouseInitialization (CPi, HouseList[CPi2], 13, 0, 0); //Butcher's
- 25: HouseInitialization (CPi, HouseList[CPi2], 12, 0, 0); //Tannery
- 28: HouseInitialization (CPi, HouseList[CPi2], 8, 0, 0); //Vineyard
- 2: HouseInitialization (CPi, HouseList[CPi2], 21, 23, 25); // Weapon Smithy
- 10: HouseInitialization (CPi, HouseList[CPi2], 17, 19, 0); //Armor Smithy
- 19: HouseInitialization (CPi, HouseList[CPi2], 20, 22, 24); //Weapons Workshop
- 20: HouseInitialization (CPi, HouseList[CPi2], 16, 18, 0); //Armor Workshop
- end;
- end;
- end;
- end;
- procedure PrepareNewHouse (aHouse: Integer);
- var CPtmp: Integer;
- begin
- CPtmp := States.HouseOwner(aHouse);
- case States.HouseType(aHouse) of
- 0: HouseInitialization (CPtmp, aHouse, 2, 0, 0); //Sawmill
- 1: HouseInitialization (CPtmp, aHouse, 6, 0, 0); // Iron Smithy
- 3: HouseInitialization (CPtmp, aHouse, 5, 0, 0); //Coal Mine
- 4: HouseInitialization (CPtmp, aHouse, 3, 0, 0); //Iron Mine
- 5: HouseInitialization (CPtmp, aHouse, 4, 0, 0); //Gold Mine
- 6: HouseInitialization (CPtmp, aHouse, 27, 0, 0); //Fisherman's Hut
- 7: HouseInitialization (CPtmp, aHouse, 10, 0, 0); //Bakery
- 8: HouseInitialization (CPtmp, aHouse, 9, 0, 0); //Farm
- 9: HouseInitialization (CPtmp, aHouse, 0, 0, 0); //Woodcutter
- 12: HouseInitialization (CPtmp, aHouse, 26, 0, 0); //Stables
- 14: HouseInitialization (CPtmp, aHouse, 1, 0, 0); //Quarry
- 15: HouseInitialization (CPtmp, aHouse, 7, 0, 0); //Metallurgist's
- 16: HouseInitialization (CPtmp, aHouse, 14, 15, 0); //Swine Farm
- 22: HouseInitialization (CPtmp, aHouse, 11, 0, 0); //Mill
- 24: HouseInitialization (CPtmp, aHouse, 13, 0, 0); //Butcher's
- 25: HouseInitialization (CPtmp, aHouse, 12, 0, 0); //Tannery
- 28: HouseInitialization (CPtmp, aHouse, 8, 0, 0); //Vineyard
- 2: HouseInitialization (CPtmp, aHouse, 21, 23, 25); // Weapon Smithy
- 10: HouseInitialization (CPtmp, aHouse, 17, 19, 0); //Armor Smithy
- 19: HouseInitialization (CPtmp, aHouse, 20, 22, 24); //Weapons Workshop
- 20: HouseInitialization (CPtmp, aHouse, 16, 18, 0); //Armor Workshop
- end;
- end;
- procedure RemoveHouse(aHouse: Integer);
- var CPtmp: Integer;
- var CPi, CPi2: Integer;
- begin
- CPtmp := States.HouseOwner(aHouse);
- for CPi := 0 to ProductionCount[CPtmp] do
- begin
- if CPi = ProductionCount[CPtmp] then exit;
- if aHouse = CPWares[CPtmp][CPi].HouseID then break;
- end;
- begin
- for CPi2 := CPi to ProductionCount[CPtmp]-1 do
- CPGetNext(CPtmp, CPi2);
- ProductionCount[CPtmp] := ProductionCount[CPtmp]-1;
- end;
- end;
- procedure CheckProduction(aHouse: Integer; aType: word; aCount: word);
- var CPtmp: Integer;
- var CPi: Integer;
- begin
- CPtmp := States.HouseOwner(aHouse);
- for CPi := 0 to ProductionCount[CPtmp] do
- begin
- if CPi = ProductionCount[CPtmp] then exit;
- if CPWares[CPtmp][CPi].HouseId = aHouse then break;
- end;
- if CPWares[CPtmp][CPi].Skip = false then
- begin
- ChangeProduction(CPtmp, CPi, aType, aCount);
- end
- else CPWares[CPtmp][CPi].Skip := false;
- end;
- procedure CPFill1(Player, Index, Ware: Integer);
- var Count, Addition: Integer;
- begin
- Count := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
- if Count < 5 then if CPWares[Player][Index].Excess1 > 0 then
- begin
- CPWares[Player][Index].Skip := true;
- if CPWares[Player][Index].Excess1 + Count > 5 then
- begin
- Addition := 5 - Count;
- CPWares[Player][Index].Excess1 := CPWares[Player][Index].Excess1 - Addition;
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, Addition);
- end else
- begin
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, CPWares[Player][Index].Excess1);
- CPWares[Player][Index].Excess1 := 0;
- end;
- end;
- end;
- procedure CPFill2(Player, Index, Ware: Integer);
- var Count, Addition: Integer;
- begin
- Count := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
- if Count < 5 then if CPWares[Player][Index].Excess2 > 0 then
- begin
- CPWares[Player][Index].Skip := true;
- if CPWares[Player][Index].Excess2 + Count > 5 then
- begin
- Addition := 5 - Count;
- CPWares[Player][Index].Excess2 := CPWares[Player][Index].Excess2 - Addition;
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, Addition);
- end else
- begin
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, CPWares[Player][Index].Excess2);
- CPWares[Player][Index].Excess2 := 0;
- end;
- end;
- end;
- procedure CPFill3(Player, Index, Ware: Integer);
- var Count, Addition: Integer;
- begin
- Count := States.HouseResourceAmount(CPWares[Player][Index].HouseID, Ware);
- if Count < 5 then if CPWares[Player][Index].Excess3 > 0 then
- begin
- CPWares[Player][Index].Skip := true;
- if CPWares[Player][Index].Excess3 + Count > 5 then
- begin
- Addition := 5 - Count;
- CPWares[Player][Index].Excess3 := CPWares[Player][Index].Excess3 - Addition;
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, Addition);
- end else
- begin
- Actions.HouseAddWaresTo(CPWares[Player][Index].HouseID, Ware, CPWares[Player][Index].Excess3);
- CPWares[Player][Index].Excess3 := 0;
- end;
- end;
- end;
- procedure FillWaresOverLimit (Player: Integer);
- var CPi, Count, Addition: Integer;
- Begin
- for CPi := 0 to ProductionCount[Player]-1 do
- begin
- case States.HouseType(CPWares[Player][CPi].HouseID) of
- 0: CPFill1(Player, CPi, 2); //Sawmill
- 1: CPFill1(Player, CPi, 6); // Iron Smithy
- 3: CPFill1(Player, CPi, 5); //Coal Mine
- 4: CPFill1(Player, CPi, 3); //Iron Mine
- 5: CPFill1(Player, CPi, 4); //Gold Mine
- 6: CPFill1(Player, CPi, 27); //Fisherman's Hut
- 7: CPFill1(Player, CPi, 10); //Bakery
- 8: CPFill1(Player, CPi, 9); //Farm
- 9: CPFill1(Player, CPi, 0); //Woodcutter
- 12: CPFill1(Player, CPi, 26); //Stables
- 14: CPFill1(Player, CPi, 1); //Quarry
- 15: CPFill1(Player, CPi, 7); //Metallurgist's
- 16: begin //Swine Farm
- CPFill1(Player, CPi, 14);
- CPFill2(Player, CPi, 15);
- end;
- 22: CPFill1(Player, CPi, 11); //Mill
- 24: CPFill1(Player, CPi, 13); //Butcher's
- 25: CPFill1(Player, CPi, 12); //Tannery
- 28: CPFill1(Player, CPi, 8); //Vineyard
- 2: begin // Weapon Smithy
- CPFill1(Player, CPi, 21);
- CPFill2(Player, CPi, 23);
- CPFill3(Player, CPi, 25);
- end;
- 10: begin //Armor Smithy
- CPFill1(Player, CPi, 17);
- CPFill2(Player, CPi, 19);
- end;
- 19: begin //Weapons Workshop
- CPFill1(Player, CPi, 20);
- CPFill2(Player, CPi, 22);
- CPFill3(Player, CPi, 24);
- end;
- 20: begin //Armor Workshop
- CPFill1(Player, CPi, 16);
- CPFill2(Player, CPi, 18);
- end;
- end;
- end;
- end;
- procedure OnMissionStart;
- begin
- SetProductionAmounts();
- end;
- procedure OnHouseBuilt(aHouse: Integer);
- begin
- PrepareNewHouse(aHouse);
- end;
- procedure OnHouseDestroyed (aHouse: Integer);
- begin
- RemoveHouse(aHouse);
- end;
- procedure OnWareProduced(aHouse: Integer; aType: word; aCount: word);
- begin
- CheckProduction(aHouse,aType,aCount);
- end;
- procedure OnTick;
- begin
- if States.GameTime() = 1 then
- Initialize_buildings ();
- for CPIterator := 0 to 11 do
- if States.GameTime() mod 20 = CPIterator then FillWaresOverLimit(CPIterator);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement