Post 03 Jan 2015, 11:56 by Esthlos
1. makes troops/minions walk in from outside the map
Not really "walk in", but this code does something pretty close to that (it spawns groups one row at a time from an edge... not necessarily the map's edge):
- Code:
const aEdgeSpawnRate = 20; //How many ticks need to pass before the next row spawns.
var aEdgeSpawnQueue: array of Record aGroupID, aPlayer, aType, aX, aY, aDir, aColumns, aStage: Integer; end;
type tEdge = (South, SouthEast, East, NorthEast, North, NorthWest, West, SouthWest); //From where is the troop arriving
//To be placed OnTick
procedure aManageSpawnFromEdge;
var i: Integer;
var i2: Integer;
var iCount: Integer;
var aNewGroup: Integer;
begin
if Length(aEdgeSpawnQueue) > 0 then begin
iCount := 0;
for i := 0 to Length(aEdgeSpawnQueue)-1 do begin
aEdgeSpawnQueue[i-iCount].aStage := aEdgeSpawnQueue[i-iCount].aStage-1;
if aEdgeSpawnQueue[i-iCount].aStage <= 0 then if States.UnitAt(aEdgeSpawnQueue[i-iCount].aX, aEdgeSpawnQueue[i-iCount].aY) > 0 then aEdgeSpawnQueue[i-iCount].aStage := 1;
if aEdgeSpawnQueue[i-iCount].aStage <= 0 then begin
aNewGroup := Actions.GiveGroup(aEdgeSpawnQueue[i-iCount].aPlayer, aEdgeSpawnQueue[i-iCount].aType, aEdgeSpawnQueue[i-iCount].aX, aEdgeSpawnQueue[i-iCount].aY, aEdgeSpawnQueue[i-iCount].aDir, 1, 1);
if States.GroupDead(aEdgeSpawnQueue[i-iCount].aGroupID) = False then Actions.GroupOrderLink(aNewGroup, aEdgeSpawnQueue[i-iCount].aGroupID);
if States.GroupDead(aEdgeSpawnQueue[i-iCount].aGroupID) = True then for i2 := i-iCount+1 to Length(aEdgeSpawnQueue)-1 do if aEdgeSpawnQueue[i2].aGroupID = aEdgeSpawnQueue[i-iCount].aGroupID then aEdgeSpawnQueue[i2].aGroupID := aNewGroup;
for i2 := i-iCount to Length(aEdgeSpawnQueue)-2 do aEdgeSpawnQueue[i2] := aEdgeSpawnQueue[i2+1];
iCount := iCount+1;
end;
end;
if iCount > 0 then SetLength(aEdgeSpawnQueue, Length(aEdgeSpawnQueue)-iCount);
end;
end;
//To be used instead of Actions.GiveGroup
function aSpawnFromEdge(aPlayer, aType, aX, aY, aCount, aColumns: Integer; aEdge: tEdge): Integer;
var i: Integer;
var iX: Integer;
var iY: Integer;
var iDir: Integer;
var iVar: Integer;
var iStage: Integer;
var iCount: Integer;
begin
case aEdge of
South: iDir := 0;
//SouthEast: iDir := 7;
East: iDir := 6;
//NorthEast: iDir := 5;
North: iDir := 4;
//NorthWest: iDir := 3;
West: iDir := 2;
//SouthWest: iDir := 1;
else Exit; //Other directions not supported yet
end;
i := 1;
if iDir mod 2 = 0 then i := aColumns;
result := Actions.GiveGroup(aPlayer, aType, aX, aY, iDir, i, aColumns);
iCount := aCount-i;
if iCount > 0 then begin
SetLength(aEdgeSpawnQueue, Length(aEdgeSpawnQueue)+iCount);
for i := 0 to iCount-1 do begin
iVar := (i mod aColumns)-((aColumns-(aColumns mod 2))/2);
case aEdge of
South: begin
iX := aX+iVar;
iY := aY;
end;
//SouthEast: begin
//end;
East: begin
iX := aX;
iY := aY+iVar+((aColumns+1) mod 2);
end;
//NorthEast: begin
//end;
North: begin
iX := aX+iVar+((aColumns+1) mod 2);
iY := aY;
end;
//NorthWest: begin
//end;
West: begin
iX := aX;
iY := aY+iVar;
end;
//SouthWest: begin
//end;
end;
iStage := (((i-(i mod aColumns))/aColumns)+1)*aEdgeSpawnRate;
if iX <= 0 then iX := 1;
if iY <= 0 then iY := 1;
if iX >= States.MapWidth then iX := States.MapWidth-1;
if iY >= States.MapHeight then iY := States.MapHeight-1;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aGroupID := result;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aPlayer := aPlayer;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aType := aType;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aX := iX;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aY := iY;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aDir := iDir;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aColumns := aColumns;
aEdgeSpawnQueue[Length(aEdgeSpawnQueue)-i-1].aStage := iStage;
end;
end;
end;
Here's AED09's script with a bugfix and with this code being used:
2. makes troops/minions walk out of a building
Already asked
Lewin to add this... I've even already written, tested and PMed him the code needed, it only needs him to come back from vacation and check it up
You do not have the required permissions to view the files attached to this post.
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"