Radical change to how custom buildings can be made - Uses Drone.extend so that new player-submitted blueprints can be part of a chain.

This commit is contained in:
walterhiggins 2013-01-01 22:38:16 +00:00
parent dfc5ba1b8f
commit 3d3dccaf70
4 changed files with 56 additions and 54 deletions

View file

@ -368,6 +368,18 @@ var Drone = {
// for blocks 68 (wall signs) 65 (ladders) 61,62 (furnaces) 23 (dispenser) and 54 (chest) // for blocks 68 (wall signs) 65 (ladders) 61,62 (furnaces) 23 (dispenser) and 54 (chest)
Drone.PLAYER_SIGN_FACING = [4,2,5,3]; Drone.PLAYER_SIGN_FACING = [4,2,5,3];
Drone.PLAYER_TORCH_FACING = [2,4,1,3]; Drone.PLAYER_TORCH_FACING = [2,4,1,3];
//
// add custom methods to the Drone object using this function
//
Drone.extend = function(name, func)
{
Drone.prototype[name] = func;
global[name] = function(){
var result = new Drone();
result[name].apply(result,arguments);
return result;
};
};
Drone.prototype.prism0 = function(block,w,d){ Drone.prototype.prism0 = function(block,w,d){
this.prism(block,w,d).fwd().right().prism(0,w-2,d-2).left().back(); this.prism(block,w,d).fwd().right().prism(0,w-2,d-2).left().back();
@ -847,8 +859,6 @@ var Drone = {
for (var i = 0;i < ops.length; i++){ for (var i = 0;i < ops.length; i++){
global[ops[i]] = function(op){ global[ops[i]] = function(op){
return function(){ return function(){
for (var i = 0;i < arguments.length;i++)
print ("DEBUG:" + arguments[i]);
var result = new Drone(); var result = new Drone();
result[op].apply(result,arguments); result[op].apply(result,arguments);
return result; return result;

View file

@ -2,14 +2,12 @@ load($SCRIPT_DIR + "/fort.js");
// //
// a castle is just a big wide fort with 4 taller forts at each corner // a castle is just a big wide fort with 4 taller forts at each corner
// //
function castle (side, height, drone) Drone.extend('castle', function(side, height)
{ {
// //
// use sensible default parameter values // use sensible default parameter values
// if no parameters are supplied // if no parameters are supplied
// //
if (typeof drone == "undefined")
drone = new Drone();
if (typeof side == "undefined") if (typeof side == "undefined")
side = 24; side = 24;
if (typeof height == "undefined") if (typeof height == "undefined")
@ -19,7 +17,7 @@ function castle (side, height, drone)
// //
// remember where the drone is so it can return 'home' // remember where the drone is so it can return 'home'
// //
drone.chkpt('castle'); this.chkpt('castle');
// //
// how big the towers at each corner will be... // how big the towers at each corner will be...
// //
@ -29,24 +27,24 @@ function castle (side, height, drone)
// //
// the main castle building will be front and right of the first tower // the main castle building will be front and right of the first tower
// //
drone.fwd(towerSide/2).right(towerSide/2); this.fwd(towerSide/2).right(towerSide/2);
// //
// the castle is really just a big fort with 4 smaller 'tower' forts at each corner // the castle is really just a big fort with 4 smaller 'tower' forts at each corner
// //
drone = fort(side,height,drone); this.fort(side,height);
// //
// move back to start position // move back to start position
// //
drone.move('castle'); this.move('castle');
// //
// now place 4 towers at each corner (each tower is another fort) // now place 4 towers at each corner (each tower is another fort)
// //
for (var corner = 0; corner < 4; corner++) for (var corner = 0; corner < 4; corner++)
{ {
// construct a 'tower' fort // construct a 'tower' fort
fort(towerSide,towerHeight,drone); this.fort(towerSide,towerHeight);
// move forward the length of the castle then turn right // move forward the length of the castle then turn right
drone.fwd(side+towerSide-1).turn(); this.fwd(side+towerSide-1).turn();
}
return drone.move('castle');
} }
return this.move('castle');
});

View file

@ -16,15 +16,12 @@ load(scriptDir + "/../drone.js"); // assumes cottage.js and drone.js are in same
// //
// [2] to build a cottage using an existing drone... // [2] to build a cottage using an existing drone...
// //
// /js cottage(drone); // /js drone.cottage();
// //
function cottage(/* optional */ drone) Drone.extend('cottage',function ()
{ {
if (typeof drone == "undefined"){ this.chkpt('cottage')
drone = new Drone();
}
drone.chkpt('cottage')
.box0(48,7,2,6) // 4 walls .box0(48,7,2,6) // 4 walls
.right(3).door() // door front and center .right(3).door() // door front and center
.up(1).left(2).box(102) // windows to left and right .up(1).left(2).box(102) // windows to left and right
@ -33,28 +30,25 @@ function cottage(/* optional */ drone)
// //
// put up a sign near door. // put up a sign near door.
// //
drone.down().right(4).sign(["Home","Sweet","Home"],68); this.down().right(4).sign(["Home","Sweet","Home"],68);
return drone.move('cottage'); return this.move('cottage');
}; });
// //
// a more complex script that builds an tree-lined avenue with // a more complex script that builds an tree-lined avenue with
// cottages on both sides. // cottages on both sides.
// //
function cottage_road(numberCottages,/* optional */ drone) Drone.extend('cottage_road', function(numberCottages)
{ {
if (typeof numberCottages == "undefined"){ if (typeof numberCottages == "undefined"){
numberCottages = 6; numberCottages = 6;
} }
if (typeof drone == "undefined"){
drone = new Drone();
}
var i=0, distanceBetweenTrees = 11; var i=0, distanceBetweenTrees = 11;
// //
// step 1 build the road. // step 1 build the road.
// //
var cottagesPerSide = Math.floor(numberCottages/2); var cottagesPerSide = Math.floor(numberCottages/2);
drone this
.chkpt("cottage_road") // make sure the drone's state is saved. .chkpt("cottage_road") // make sure the drone's state is saved.
.box(43,3,1,cottagesPerSide*(distanceBetweenTrees+1)) // build the road .box(43,3,1,cottagesPerSide*(distanceBetweenTrees+1)) // build the road
.up().right() // now centered in middle of road .up().right() // now centered in middle of road
@ -64,30 +58,30 @@ function cottage_road(numberCottages,/* optional */ drone)
// step 2 line the road with trees // step 2 line the road with trees
// //
for (; i < cottagesPerSide+1;i++){ for (; i < cottagesPerSide+1;i++){
drone this
.left(5).oak() .left(5).oak()
.right(10).oak() .right(10).oak()
.left(5) // return to middle of road .left(5) // return to middle of road
.fwd(distanceBetweenTrees+1); // move forward. .fwd(distanceBetweenTrees+1); // move forward.
} }
drone.move("cr").back(6); // move back 1/2 the distance between trees this.move("cr").back(6); // move back 1/2 the distance between trees
// this function builds a path leading to a cottage. // this function builds a path leading to a cottage.
function pathAndCottage(d){ function pathAndCottage(d){
return cottage(d.down().box(43,1,1,5).fwd(5).left(3).up()); return d.down().box(43,1,1,5).fwd(5).left(3).up().cottage();
}; };
// //
// step 3 build cottages on each side // step 3 build cottages on each side
// //
for (i = 0;i < cottagesPerSide; i++) for (i = 0;i < cottagesPerSide; i++)
{ {
drone.fwd(distanceBetweenTrees+1).chkpt("r"+i); this.fwd(distanceBetweenTrees+1).chkpt("r"+i);
// build cottage on left // build cottage on left
pathAndCottage(drone.turn(3)).move("r"+i); pathAndCottage(this.turn(3)).move("r"+i);
// build cottage on right // build cottage on right
pathAndCottage(drone.turn()).move("r"+i); pathAndCottage(this.turn()).move("r"+i);
} }
// return drone to where it was at start of function // return drone to where it was at start of function
return drone.move("cottage_road"); return this.move("cottage_road");
} });

View file

@ -2,10 +2,8 @@ load($SCRIPT_DIR + "/../drone.js");
// //
// constructs a medieval fort // constructs a medieval fort
// //
function fort(side, height, drone) Drone.extend('fort', function(side, height)
{ {
if (typeof drone == "undefined")
drone = new Drone();
if (typeof side == "undefined") if (typeof side == "undefined")
side = 18; side = 18;
if (typeof height == "undefined") if (typeof height == "undefined")
@ -19,43 +17,45 @@ function fort(side, height, drone)
// //
// build walls. // build walls.
// //
drone.chkpt('fort').box0(brick,side,height-1,side); this.chkpt('fort').box0(brick,side,height-1,side);
// //
// build turrets // build turrets
// //
drone.up(height-1); this.up(height-1);
for (i = 0;i <= 3;i++){ for (i = 0;i <= 3;i++){
var turret = []; var turret = [];
drone.box(brick) // solid brick corners this.box(brick) // solid brick corners
.up().box('50:5').down() // light a torch on each corner .up().box('50:5').down() // light a torch on each corner
.fwd(); .fwd();
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[drone.dir]); turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[this.dir]);
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[(drone.dir+2)%4]); turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[(this.dir+2)%4]);
drone.box(turret,1,1,side-2).fwd(side-2).turn(); this.box(turret,1,1,side-2).fwd(side-2).turn();
} }
// //
// build battlements // build battlements
// //
drone.move('fort'); this.move('fort');
drone.up(height-2).fwd().right().box('44:5',side-2,1,side-2); this.up(height-2).fwd().right().box('44:5',side-2,1,side-2);
var battlementWidth = 3; var battlementWidth = 3;
if (side <= 12) if (side <= 12)
battlementWidth = 2; battlementWidth = 2;
drone.fwd(battlementWidth).right(battlementWidth) this.fwd(battlementWidth).right(battlementWidth)
.box(0,side-((1+battlementWidth)*2),1,side-((1+battlementWidth)*2)); .box(0,side-((1+battlementWidth)*2),1,side-((1+battlementWidth)*2));
// //
// add door // add door
// //
var torch = '50:' + Drone.PLAYER_TORCH_FACING[drone.dir]; var torch = '50:' + Drone.PLAYER_TORCH_FACING[this.dir];
drone.move('fort').right((side/2)-1).door2() // double doors this.move('fort').right((side/2)-1).door2() // double doors
.back().left().up().box(torch) // left torch .back().left().up().box(torch) // left torch
.right(3).box(torch); // right torch .right(3).box(torch); // right torch
// //
// add ladder up to battlements // add ladder up to battlements
// //
var ladder = '65:' + Drone.PLAYER_SIGN_FACING[(drone.dir+2)%4]; var ladder = '65:' + Drone.PLAYER_SIGN_FACING[(this.dir+2)%4];
drone.move('fort').right((side/2)-3).fwd(1) // move inside fort this.move('fort').right((side/2)-3).fwd(1) // move inside fort
.box(ladder, 1,height-1,1); .box(ladder, 1,height-1,1);
return drone.move('fort'); return this.move('fort');
};
});