Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Add trees to map
- --
- function AddTrees(cell)
- print("Adding trees.");
- for x=0, cell:getWidth()-1 do
- for y=0, cell:getHeight()-1 do
- local square = cell:getGridSquare(x, y, 0);
- n = cell:getGridSquare(x, y-1, 0);
- s = cell:getGridSquare(x, y+1, 0);
- e = cell:getGridSquare(x+1, y, 0);
- w = cell:getGridSquare(x-1, y, 0);
- if(ZombRand(5)==0) then
- local rand = ZombRand(6);
- if(rand==0 or rand==1 or rand==2 or rand==3) then
- rand = -1;
- end
- if(rand==4) then
- rand = 0;
- end
- if(rand==5) then
- rand = 16;
- end
- if(rand >= 0) then
- local vegitation = IsoTree.new(square, "TileTrees_"..rand);
- square:AddTileObject(vegitation);
- end
- end
- end
- end
- end
- --
- -- Add vegitation to map
- --
- function AddVegitation(cell)
- print("Adding grass.");
- for x=0, cell:getWidth()-1 do
- for y=0, cell:getHeight()-1 do
- local square = cell:getGridSquare(x, y, 0);
- for z=0, cell:getMaxFloors()-1 do
- local square2 = cell:getGridSquare(x, y, z);
- if square2 ~= nil then
- square2:ClearTileObjects();
- end
- end
- local floor = IsoObject.new(square, "TileFloorExt_3", false);
- square:AddTileObject(floor);
- local rand = ZombRand(2, 7);
- if(rand>3) then
- local vegitation = IsoObject.new(square, "TileTrees_"..rand, false);
- square:AddTileObject(vegitation);
- end
- end
- end
- end
- southFacingLots = {}
- northFacingLots = {}
- function LoadLots()
- southFacingLots[0] = IsoLot.new("media/lots/Lot_Diner_17x29.lot");
- southFacingLots[1] = IsoLot.new("media/lots/Lot_HouseS_1_22x22.lot");
- southFacingLots[2] = IsoLot.new("media/lots/Lot_Bar12x15.lot");
- southFacingLots[3] = IsoLot.new("media/lots/Lot_HouseGarage_30x36.lot");
- southFacingLots[4] = IsoLot.new("media/lots/Lot_Spiffos_64x34.lot");
- northFacingLots[0] = IsoLot.new("media/lots/Lot_Diner_17x29.lot");
- end
- function AddRoads(cell)
- print("Adding road.");
- local roadWE = IsoLot.new("media/lots/Lot_RoadEW_14x14.lot");
- local roadNS = IsoLot.new("media/lots/Lot_RoadNS_14x14.lot");
- local y = ZombRand(20, cell:getHeight()-40);
- for x=0, cell:getWidth()-1, 14 do
- cell:PlaceLot(roadWE, x, y, 0, true);
- end
- local canDoNorth = false;
- local canDoSouth = false;
- if y > 30 then
- canDoNorth = true;
- end
- if y < cell:getHeight()-30 then
- canDoSouth = true;
- end
- x = 20;
- if canDoNorth then
- while x < cell:getWidth() do
- if(ZombRand(3)==0) then
- x = x + ZombRand(30);
- else
- local lot = southFacingLots[ZombRand(3)];
- local ly = y - (lot:getHeight()-1);
- cell:PlaceLot(lot, x, ly, 0, true);
- x = x + lot:getWidth();
- end
- end
- end
- end
- function DoWERoad(cell, y)
- local roadWE = IsoLot.new("media/lots/Lot_RoadEW_14x14.lot");
- for x=0, cell:getWidth()-1, 14 do
- cell:PlaceLot(roadWE, x, y, 0, true);
- end
- end
- function DoNSRoadPart(cell, x, y1, y2)
- local roadWE = IsoLot.new("media/lots/Lot_RoadEW_14x14.lot");
- local roadNS = IsoLot.new("media/lots/Lot_RoadNS_14x14.lot");
- local roadNSB = IsoLot.new("media/lots/Lot_RoadTN_14x14.lot");
- local roadNST = IsoLot.new("media/lots/Lot_RoadTS_14x14.lot");
- for y=y1, y2, 14 do
- if y2 - y > 4 then -- don't put down road unless it will meet up with the other road
- cell:PlaceLot(roadNS, x, y, 0, true);
- end
- end
- cell:PlaceLot(roadWE, x, y2, 0, true);
- cell:PlaceLot(roadNSB, x-3, y2-3, 0, true);
- cell:PlaceLot(roadNST, x-3, y1-3, 0, true);
- end
- function DoSquare(cell, x1, x2, y1, y2)
- local wid = x2 - x1;
- local hei = y2 - y1;
- local x = x1;
- local y = y1;
- while x < x2 do
- x = x + ZombRand(10);
- local lot = northFacingLots[0];
- local ly = y1;--y - (lot:getHeight()-1);
- if(lot:getWidth() + x <= x2 and lot:getHeight() <= hei) then
- --cell:PlaceLot(lot, x, ly, 0, true);
- x = x + lot:getWidth();
- end
- end
- if hei > 40 then
- x = x1;
- while x < x2 do
- x = x + ZombRand(10);
- local lot = southFacingLots[ZombRand(5)];
- local ly = y2 - (lot:getHeight()-2);
- if(lot:getWidth() + x <= x2 and lot:getHeight() <= hei) then
- cell:PlaceLot(lot, x, ly, 0, true);
- x = x + lot:getWidth();
- end
- end
- end
- for x=x1, x2 do
- for y=y1, y2 do
- local square = cell:getGridSquare(x, y, 0);
- if(square ~= nil) then
- --square:ClearTileObjects();
- --local fl = IsoObject.new(square, "TileFloorExt_2", false);
- --square:AddTileObject(fl);
- end
- end
- end
- end
- function DoYSection(cell, y1, y2)
- local roadsX = {};
- local x = 0;
- local n = 1;
- while(x < cell:getWidth()) do
- x = x + ZombRand(90) + 30;
- DoNSRoadPart(cell, x, y1, y2);
- roadsX[n] = x;
- n = n + 1;
- end
- local last = -1;
- for k, x in ipairs(roadsX) do
- if last ~= -1 and k ~= n - 1 then
- DoSquare(cell, last + 8, x-1, y1+1, y2-1);
- end
- last = x;
- end
- end
- function DoRoadNetwork(cell)
- local roadsY = {};
- local y1 = 0;
- local n = 1;
- while(y1 < cell:getHeight()) do
- y1 = y1 + ZombRand(90) + 30;
- DoWERoad(cell, y1);
- roadsY[n] = y1;
- n = n + 1;
- end
- local last = -1;
- for k, y in ipairs(roadsY) do
- if last ~= -1 and k ~= n - 1 then
- DoYSection(cell, last + 7, y);
- end
- last = y;
- end
- end
- function GenerateMap(cell)
- cell:DeleteAllMovingObjects();
- print("Generating map.");
- LoadLots();
- AddVegitation(cell);
- AddTrees(cell);
- --AddRoads(cell);
- DoRoadNetwork(cell);
- end
- Events.OnPostMapLoad.Add(GenerateMap);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement