2015-01-03 10:50:37 +01:00
|
|
|
'use strict';
|
2015-01-16 22:20:34 +01:00
|
|
|
/*global require */
|
|
|
|
var Drone = require('drone'),
|
|
|
|
blocks = require('blocks');
|
|
|
|
/************************************************************************
|
|
|
|
### Drone.fort() method
|
|
|
|
|
|
|
|
Constructs a medieval fort.
|
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
|
|
|
|
* side - How many blocks whide and long the fort will be (default: 18 . Must be greater than 9)
|
|
|
|
* height - How tall the fort will be (default: 6 . Must be greater than 3)
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
|
|
|
|
At the in-game prompt you can create a fort by looking at a block and typing:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
/js fort()
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively you can create a new Drone object from a Player or Location object and call the fort() method.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
var d = new Drone(player);
|
|
|
|
d.fort();
|
|
|
|
```
|
|
|
|
![fort example](img/fortex1.png)
|
|
|
|
|
|
|
|
***/
|
2014-08-23 17:45:16 +02:00
|
|
|
function fort( side, height ) {
|
2014-12-30 15:54:38 +01:00
|
|
|
var turret,
|
2014-02-19 01:15:44 +01:00
|
|
|
i,
|
2015-01-03 10:50:37 +01:00
|
|
|
torch;
|
2014-02-19 01:15:44 +01:00
|
|
|
|
2014-01-29 20:49:15 +01:00
|
|
|
if ( typeof side == 'undefined' ) {
|
|
|
|
side = 18;
|
|
|
|
}
|
|
|
|
if ( typeof height == 'undefined' ) {
|
|
|
|
height = 6;
|
|
|
|
}
|
|
|
|
// make sure side is even
|
|
|
|
if ( side % 2 ) {
|
|
|
|
side++;
|
|
|
|
}
|
2014-02-16 19:29:36 +01:00
|
|
|
var battlementWidth = 3;
|
|
|
|
if ( side <= 12 ) {
|
|
|
|
battlementWidth = 2;
|
|
|
|
}
|
2014-01-29 20:49:15 +01:00
|
|
|
if ( height < 4 || side < 10 ) {
|
|
|
|
throw new java.lang.RuntimeException('Forts must be at least 10 wide X 4 tall');
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// build walls.
|
|
|
|
//
|
2014-12-30 15:54:38 +01:00
|
|
|
this
|
|
|
|
.chkpt('fort')
|
|
|
|
.down()
|
|
|
|
.chessboard( blocks.wool.black, blocks.wool.white, side)
|
|
|
|
.up()
|
|
|
|
.box0( blocks.brick.stone, side, height - 1, side)
|
2014-02-19 01:15:44 +01:00
|
|
|
.up(height-1);
|
2014-01-29 20:49:15 +01:00
|
|
|
//
|
|
|
|
// build battlements
|
|
|
|
//
|
|
|
|
for ( i = 0; i <= 3; i++ ) {
|
2014-02-19 01:15:44 +01:00
|
|
|
|
|
|
|
turret = [
|
2014-12-30 15:54:38 +01:00
|
|
|
blocks.stairs.stone ,
|
|
|
|
blocks.stairs.stone + ':'+ Drone.PLAYER_STAIRS_FACING[ (this.dir + 2) % 4 ]
|
2014-02-19 01:15:44 +01:00
|
|
|
];
|
2014-12-30 15:54:38 +01:00
|
|
|
this
|
|
|
|
.box( blocks.brick.stone ) // solid brick corners
|
2014-02-19 01:15:44 +01:00
|
|
|
.up()
|
2014-12-30 19:12:10 +01:00
|
|
|
.box(blocks.torch)
|
2014-02-19 01:15:44 +01:00
|
|
|
.down() // light a torch on each corner
|
|
|
|
.fwd()
|
2014-12-30 15:54:38 +01:00
|
|
|
.boxa( turret, 1, 1, side-2)
|
|
|
|
.fwd( side-2 )
|
2014-02-19 01:15:44 +01:00
|
|
|
.turn();
|
2014-01-29 20:49:15 +01:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// build battlement's floor
|
|
|
|
//
|
2014-12-30 15:54:38 +01:00
|
|
|
this
|
|
|
|
.move('fort')
|
2014-02-19 01:15:44 +01:00
|
|
|
.up(height-2)
|
|
|
|
.fwd()
|
|
|
|
.right();
|
|
|
|
|
|
|
|
for ( i = 0; i < battlementWidth; i++ ) {
|
2015-01-16 22:20:34 +01:00
|
|
|
var bside = side - ( 2 + (i * 2) );
|
2014-12-30 15:54:38 +01:00
|
|
|
this
|
2015-01-16 22:20:34 +01:00
|
|
|
.box0( blocks.slab.oak, bside, 1, bside)
|
2014-02-19 01:15:44 +01:00
|
|
|
.fwd()
|
|
|
|
.right();
|
2014-01-29 20:49:15 +01:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// add door
|
|
|
|
//
|
2014-12-30 15:54:38 +01:00
|
|
|
torch = blocks.torch + ':' + Drone.PLAYER_TORCH_FACING[this.dir];
|
|
|
|
this
|
|
|
|
.move('fort')
|
2015-01-16 22:20:34 +01:00
|
|
|
.right( ( side / 2 ) - 1 )
|
2014-02-19 01:15:44 +01:00
|
|
|
.door2() // double doors
|
|
|
|
.back()
|
|
|
|
.left()
|
|
|
|
.up()
|
2015-01-16 22:20:34 +01:00
|
|
|
.box( torch ) // left torch
|
|
|
|
.right( 3 )
|
|
|
|
.box( torch ); // right torch
|
2014-01-29 20:49:15 +01:00
|
|
|
//
|
|
|
|
// add ladder up to battlements
|
|
|
|
//
|
2014-12-30 15:54:38 +01:00
|
|
|
this
|
|
|
|
.move('fort')
|
2015-01-16 22:20:34 +01:00
|
|
|
.right( ( side / 2 ) - 3 )
|
|
|
|
.fwd() // move inside fort
|
|
|
|
.turn( 2 )
|
|
|
|
.box( blocks.air, 1, height - 1, 1)
|
|
|
|
.ladder( height - 1 )
|
|
|
|
.move( 'fort' );
|
2014-08-23 17:45:16 +02:00
|
|
|
}
|
|
|
|
Drone.extend(fort);
|
2013-12-24 01:09:49 +01:00
|
|
|
|