Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- My idea is for a polymorphic function to create new creeps,
- without an excess of repetitive code. To begin, it will take
- the single parameter which determines the role. In the future
- further parameters might determine body size/type.
- */
- // Store the body types here
- var harvester_body = '[MOVE, MOVE, MOVE, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE]';
- var upgrader_body = '[MOVE, CARRY, MOVE, WORK, WORK, MOVE, CARRY, MOVE]';
- var builder_body = '[MOVE, MOVE, WORK, CARRY, CARRY, WORK, MOVE, MOVE]';
- var repairer_body = '[MOVE, CARRY, MOVE, WORK, WORK, MOVE, CARRY, MOVE]';
- var miner_body = '[MOVE, WORK, WORK, WORK, MOVE]';
- var newCreep = {
- run: function (creepRole) {
- // My thought here is to generate the name via the role
- var newName = (creepRole + Game.time);
- // And then using the role spawn the creep
- switch (creepRole) {
- case 'harvester':
- Game.spawns.Spawn1.spawnCreep(harvester_body, newName,
- { memory: { role: creepRole } });
- case 'upgrader':
- Game.spawns.Spawn1.spawnCreep(upgrader_body, newName,
- { memory: { role: creepRole } });
- case 'builder':
- Game.spawns.Spawn1.spawnCreep(builder_body, newName,
- { memory: { role: creepRole } });
- case 'repairer':
- Game.spawns.Spawn1.spawnCreep(repairer_body, newName,
- { memory: { role: creepRole } });
- case 'miner':
- Game.spawns.Spawn1.spawnCreep(miner_body, newName,
- { memory: { role: creepRole } });
- }
- // I would prefer to be able to call the body type using the role
- // as well, as this would reduce the amount of code required even further.
- }
- };
- module.exports = newCreep;
Add Comment
Please, Sign In to add comment