Dynamic Script - Scripts
HEX COLORS: http://docwiki.embarcadero.com/RADStudi ... ors_in_VCL
TABLES: https://code.google.com/p/castlesand/wi ... ptsLookups
NATIVE SCRIPTS: https://code.google.com/p/castlesand/wi ... ptsDynamic
Test(a: integer) - use for every test if your script run, type any variables or just: 1, 2, 3... etc. HouseTypeToWorkerType(aType: integer): integer - return worker type for specific house type.
- Code:
function HouseTypeToWorkerType(aType: integer): integer; begin case aType of 9: RESULT := 1; //woodcutters 14: RESULT := 10; //quarry 0: RESULT :=5; //sawmill 20:RESULT :=5; //armour workshop 19:RESULT :=5; //weapons workshop 8: RESULT := 4; //farm 16: RESULT := 3; //pig farm 22: RESULT := 6; // mill 12:RESULT :=3; //stables 25: RESULT := 7; // tannery 7: RESULT := 6; // bakery 24: RESULT := 7; // butchers 28: RESULT := 4; //vineyard 6: RESULT := 8; //fishers 3: RESULT := 2; // coal mine 4: RESULT := 2; // iron mine 5: RESULT := 2; // gold mine 15:RESULT :=12; //metallurgists 1:RESULT :=12; //iron smithy 10:RESULT := 11; //armour smithy 2:RESULT := 11; //weapon smithy 17:RESULT := 13; //watch tower 21: RESULT := 13; //barracks else RESULT := -1; end end;
- Code:
function WareTypeToSellPrice(aWareType: integer): integer; begin case aWareType of 0: RESULT:= 10; //tree trunk 1: RESULT:= 6; //stone 2: RESULT:= 15; // timber 3: RESULT:= 25; //iron ore 4: RESULT:= 25; //gold ore 5: RESULT:= 20; //coal 6: RESULT:= 50; //iron 7: RESULT:= 50; //gold 8: RESULT:= 30; //vine 9: RESULT:= 30; //corn 10: RESULT:= 30; //loaves 11: RESULT:= 30; //flour 12: RESULT:= 30; //leather 13: RESULT:= 30; //sausages 14: RESULT:= 50; //pig 15: RESULT:= 40; //skin 16: RESULT:= 40; //wooden shield 17: RESULT:= 40; //long shield 18: RESULT:= 40; //leather armour 19: RESULT:= 40; //iron armament 20: RESULT:= 40; //handaxe 21: RESULT:= 40; //long sword 22: RESULT:= 40; //lance 23: RESULT:= 40; //pike 24: RESULT:= 40; //longbow 25: RESULT:= 40; //crossbow 26: RESULT:= 40; //horse 27: RESULT:= 40; //fish else RESULT:= 0; end end;
- Code:
function HouseChangeOwner(aHouse, toPlayer: integer): integer; var t, x, y: integer; begin if (aHouse > 0) and InRange(toPlayer, 0, MAX_PLAYERS-1) then begin t:= States.HouseType(aHouse); x:= States.HousePositionX(aHouse); y:= States.HousePositionY(aHouse); Actions.HouseDestroy(aHouse, true); result:= Actions.GiveHouse(toPlayer, t, x, y); end else result:= -1; end;
- Code:
function ChangeUnitType(aUnit, aType: integer): integer; var owner, x, y: integer; begin if (aUnit > 0 ) and (aType >= 0 ) and (aType < 37) then begin owner:= States.UnitOwner(aUnit); x:= States.UnitPositionX(aUnit); y:= States.UnitPositionY(aUnit); Actions.UnitKill(aUnit, true); result:= States.GroupMember(Actions.GiveGroup(owner, aType, x, y, 4, 1, 1), 0); end else begin result:= -1; end; end;
ClosestEnemyGroup(aPlayer, X, Y, radius:Integer): Integer - returns id of cloest enemy group. const MAX_PLAYERS = 0..8
- Code:
function ClosestEnemyGroup(aPlayer, X, Y, radius:Integer): Integer; var Groups: array of Integer; i, j, BestDistanceSqr, ThisDistanceSqr, DX, DY, fUnit: Integer; begin Result := -1; for j := 0 to MAX_PLAYERS-1 do begin if (States.PlayerEnabled(j) = true) and (States.PlayerDefeated(j) = false) and (j <> aPlayer) then begin if( States.PlayerAllianceCheck(aPlayer, j) <> true ) then begin Groups := States.PlayerGetAllGroups(j); for i := 0 to Length(Groups) -1 do begin fUnit:=States.GroupMember(Groups[i], 0); DX := X - States.UnitPositionX(fUnit); DY := Y - States.UnitPositionY(fUnit); ThisDistanceSqr := (DX*DX) + (DY*DY); if ((Abs(DX)<radius) and (Abs(DY)<radius)) and ((Result = -1) or (ThisDistanceSqr < BestDistanceSqr)) then begin BestDistanceSqr := ThisDistanceSqr; Result := Groups[i]; end; //end; end; end; end; end; end;
ClosestEnemyHouse(aPlayer, X, Y:Integer): Integer - returns ID of closest enemy house. const MAX_PLAYERS = 0..8
- Code:
function ClosestEnemyHouse(aPlayer, X, Y:Integer): Integer; var Houses: array of Integer; i, j, BestDistanceSqr, ThisDistanceSqr, DX, DY: Integer; begin Result := -1; for j := 0 to MAX_PLAYERS-1 do begin if (States.PlayerEnabled(j) = true) and (States.PlayerDefeated(j) = false) and (j <> aPlayer) then begin if( States.PlayerAllianceCheck(aPlayer, j) <> true ) then begin Houses := States.PlayerGetAllHouses(j); for i := 0 to Length(Houses) -1 do begin DX := X - States.HousePositionX(Houses[i]); DY := Y - States.HousePositionY(Houses[i]); ThisDistanceSqr := (DX*DX) + (DY*DY); if ((Result = -1) or (ThisDistanceSqr < BestDistanceSqr) ) and CheckObjectIDTable(Houses[i], PLAYERS_MAIN_TOWER) then begin BestDistanceSqr := ThisDistanceSqr; Result := Houses[i]; end; //end; end; end; end; end; end;