css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              h1 creep calculator for 
	a(href="https://screeps.com") screeps.com
div.content.top(ng-app='calc' ng-controller="parts")
	p
		//a(href="{{$location.href}}##{{creepHash}}", ng-init="updateLink()") {{creepUrl}}
	.controls
		table
			tr
				th part/struct
				th price
				th
				th count 
				th 
				th boost
				th sum
			tr(ng-repeat='i in parts' ng-class="{have: i.count && i.mul<0, source: i.count && i.mul>0, error: i.count<i.min}")
				td {{ i.type }}
				td.right {{ i.price }}
				td
					button(tabindex="-1" ng-click="i.count = i.min") min
					button(tabindex="-1" ng-click="subtract(i.type)") -
				td: input.count(type="number" ng-model="i.count" size="5")
				td
					button(tabindex="-1" ng-click="add(i.type)") +
					button(tabindex="-1" ng-if="i.type!=='spawn'" ng-click="add(i.type, 10)") +10
				td
					select(ng-if="boosts[i.type]" ng-model="i.boost" ng-init="boost[i.type]='-'" ng-options="b.text as b.text for b in boosts[i.type]")
				td.right {{ i.count * i.price * i.mul }}
			tr
				th.left
					label(for="unitsId") units
				th
					input.count(id="unitsId" type="number" size="1" ng-model="units" ng-init="units=1" ng-change="updateLink()")
				th parts
				th(ng-class="{error: getPartsCount()>50}") {{ getPartsCount() | num:0 }}
					span(title="all parts") ({{ getPartsCount()*units | num:0 }})
				th
				th sum
				th {{ units*getSum(false) | num }}
			tr
				th.left
					label(for="controllerLevelId") controller: 
				th
					select.count(id="controllerLevelId" ng-model="controllerLevel" ng-options="l as l.text for l in controllerLevels" ng-change="updateLink()")
				th
				th
				th
				th(title="number of units keeps builded from one source") per source
				th {{ (1500/300*3000 / getSum(false) / units) | num }}
			tr
				th.left
					label(for="tickId") tick duration (sec)
				th
					input.count(id="tickId" type="number" size="1" step="0.1" ng-model="tick" ng-init="tick=3")
				th
				th
				th
				th balance
				th(ng-class="{error: getBalance()<0}") {{ getBalance() | num }}
		div
			.fr
				button(ng-click="parseInput()") parse
				button(ng-click="reset()") reset
			div
				label(for="inputTextId") field to parse body array
				textarea(id="inputTextId" ng-model="inputText" rows="2")
						
	.stats(ng-if="getPartsCount()>0")
		table.stats(border="1")
			tr
				td.label Health:
				td.center(colspan="4") 
					span {{ getHits(false)*units | num }} 
					span(ng-if="assoc['TOUGH'].count>0") (by TOUGH {{getHits(true)*units  | num }})
			tr(ng-repeat="stat in [\
				{id: 'dismantle', name: 'Dismantle structures', part: 'WORK', mul: 50},\
				{id: 'harvest', name: 'Harvest energy', part: 'WORK', mul: 2},\
				{id: 'upgrade', name: 'Upgrade controller', part: 'WORK', mul: 1},\
				{id: 'build', name: 'Build', part: 'WORK', mul: 5},\
				{id: 'build', name: 'Fortify', part: 'WORK', mul: 100},\
				{id: 'attack', name: 'Attack', part: 'ATTACK', mul: 30},\
				{id: 'rangedAttack', name: 'Ranged attack', part: 'RANGED_ATTACK', mul: 10},\
				{id: 'rangedAttack', name: 'Mass attack 1', part: 'RANGED_ATTACK', mul: 10},\
				{id: 'rangedAttack', name: 'Mass attack 2', part: 'RANGED_ATTACK', mul: 4},\
				{id: 'rangedAttack', name: 'Mass attack 3', part: 'RANGED_ATTACK', mul: 1},\
				{id: 'heal', name: 'Heal', part: 'HEAL', mul: 12},\
				{id: 'heal', name: 'Ranged heal', part: 'HEAL', mul: 4},\
				]" ng-if="assoc[stat.part].count > 0")
				td {{ ::stat.name }}
				td {{ assoc[stat.part].count*stat.mul*(bmul[stat.id][assoc[stat.part].boost]||1)*units | num }}
					span.tip /T
				td {{ assoc[stat.part].count*stat.mul*(bmul[stat.id][assoc[stat.part].boost]||1)*1500*units | num }}
					span.tip /life
				td {{ assoc[stat.part].count*stat.mul*(bmul[stat.id][assoc[stat.part].boost]||1)*60*60*units/tick | num }}
					span.tip /H
				td {{ assoc[stat.part].count*stat.mul*(bmul[stat.id][assoc[stat.part].boost]||1)*60*60*24*units/tick | num }}
					span.tip /D
			tr(ng-if="assoc['CARRY'].count>0")
				td Carry
				td {{ assoc['CARRY'].count*(bmul['carry'][assoc['CARRY'].boost]||1)*50 | num }}
					span.tip /1
				td
					span(ng-if="units > 1") {{ assoc['CARRY'].count*(bmul['carry'][assoc['CARRY'].boost]||1)*50*units | num }}
						span.tip /{{ units }}
				td
				td
			tr(ng-if="assoc['MOVE'].count>0")
				td
					span Walk&nbsp;time
					//br(ng-if="assoc['CARRY'].count>0")
					span(ng-if="assoc['CARRY'].count>0") (empty,&nbsp;full)
				td.center(colspan="4")
					span(ng-repeat="place in [\
						{name: 'plain', k:1},\
						{name: 'road', k:0.5},\
						{name: 'swamp', k:5},\
					]") {{ place.name }}=
						span {{ getWait(place.k, false) }}
						span(ng-if="assoc['CARRY'].count>0") ,{{ getWait(place.k, true) }}
						span &nbsp;&nbsp;
			tr
				td Energy
				td {{ getSum(true) | num }}
					span.tip /1
				td 
					span(ng-if="units > 1") {{ units*getSum(true) |num }}
						span.tip /{{ units }}
				td {{ units*getSum(true)*60*60/(1500*tick) | num }}
					span.tip /H
				td {{ units*getSum(true)*60*60*24/(1500*tick) | num }}
					span.tip /D
			tr(ng-repeat='i in parts' ng-if="i.boost != undefined && i.boost != '-' && i.count > 0")
				td {{ assoc[i.type].boost }}
				td {{ 30*i.count | num}}
					span.tip /1
				td
					span(ng-if="units > 1") {{ 30*i.count*units | num }}
						span.tip /{{units}}
				td {{ 30*i.count*units*60*60/(1500*tick) | num}}
					span.tip /H
				td {{ 30*i.count*units*60*60*24/(1500*tick) | num}}
					span.tip /D
		div
			textarea(rows="2" onmouseup="this.select()" ng-model="getParts()")
			br
			div
				textarea(rows="1" onmouseup="this.select()" ng-model="getParts(true)")

div links
	ul
		li: a(href="http://jsonviewer.stack.hu/") good online JSON viewer

div changes
	ul
		li 2018-05-08 made it less noisy
		li 2018-05-08 added boosts support
		li 2018-05-08 added ability to specify tick rate for correct by-hour and by-day calculations
		li 2017-04-28 fixed extensions capacity for rcl7/8
		li 2015-08-26 fixed harvest amount
		li 2015-10-08 max parts warning set to 50
		li 2015-10-14 fixed attack,heal values; added units multiplier; captions shinked;
            
          
!
            
              tr:nth-child(odd) {
	background-color: #f8f8f8;
}

tr.have {
	background-color: #ff0;
}

tr.source {
	background-color: #afa;
}

tr.error, td.error, th.error {
	background-color: #f88 !important;
}

textarea {
	width: calc(100% - 4px);
	border: 1px solid #888;
	padding: 1px;
	margin: 1px;
}

div.controls, div.stats { display: inline-block; padding: 10px; 
vertical-align: top;
}

table.stats {
	border-collapse: collapse;
	width: 34em;
	border: 1px solid #888;
	padding: 1px;
	margin: 1px;
}

table.stats td {
	padding: 4px;
}

table.stats tr td:first-child {
	min-width: 10em;
	text-align: left;
}

.left {
	text-align: left;
}

.right {
	text-align: right;
}

.center {
	text-align: center !important;
}

table.stats tr td:nth-child(1n+2) {
	min-width: 6em;
	text-align: right;
}

span.tip {
	color: grey;
}

.fr {
	float: right;
}

.top {
	display: table-cell;
	vertical-align: top;
}

h1 {
	font-size: 28px;
	margin: 2px;
	padding: 1px;
}

button, select, input {
	border: 1px solid #ccc;
	border-radius: 4px;
	padding: 4px;
	margin: 1px;
	background-color: #e8e8a0;
}

button:focus, select:focus, input:focus {
	border: 1px solid #000;
}

input.count {
	width: 4em;
}
            
          
!
            
              angular.module('calc', [])
.controller('parts',['$scope','$rootScope','$location', '$window', '$timeout', function($scope,$rootScope, $location,  $window, $timeout){
	var assoc = $scope.assoc = {};
	$scope.add = function(type, n){
		var t = assoc[type];
		if(!n)
			n = 1;
		t.count = +t.count + +n;
		$scope.updateLink()
	};
	$scope.subtract = function(type){
		var t = assoc[type];
		if(t.count===t.min)
			return;
		t.count -= 1;
		$scope.updateLink()
	};
	$scope.parts = [
		{type: 'TOUGH', price: 10, count: 0, mul: -1, boost: '-'},
		{type: 'MOVE', price: 50, count: 1, mul: -1,  boost: '-'},
		{type: 'WORK', price: 100, count: 0, mul: -1, boost: '-'},
		{type: 'CARRY', price: 50, count: 0, mul: -1, boost: '-'},
		{type: 'ATTACK', price: 80, count: 0, mul: -1, boost: '-'},
		{type: 'RANGED_ATTACK', price: 150, count: 0, mul: -1, boost: '-'},
		{type: 'HEAL', price: 250, count: 0, mul: -1, boost: '-'},
		{type: 'CLAIM', price: 600, count: 0, mul: -1, boost: '-'},
		{type: 'spawn', price: 300, count: 1, mul: 1, min: 1},
		{type: 'extension', price: 50, count: 0, mul: 1},
	];
	for(var t of $scope.parts){
		assoc[t.type] = t;
		t.min = t.min || 0;
	}
	$scope.getBalance = function(){
		var s = 0;
		for(var t of $scope.parts){
			s += t.count * t.price * t.mul;
		}
		return s;
	}
	$scope.getSum = function(includeBoostingCost){
		var s = 0;
		for(var t of $scope.parts){
			if(t.mul<0) {
				s += t.count * t.price;
				if(includeBoostingCost && (t.boost != undefined) && (t.boost != '-')) {
					s += 20*t.count;
				}
			}
		}
		return s;
	}
	$scope.getPartsCount = function(){
		var c = 0;
		for(var t of $scope.parts)
			if(t.mul<0)
				c += +t.count;
		return c;
	}
	$scope.getParts = function(hm){
		if(hm){
			return $scope.parts
				.filter(function(part){ return part.count>0 && part.mul<0;})
				.map(function(part){ return part.type+'*'+part.count;})
				.join(',');
		}
		var out = [];
		for(var t of $scope.parts){
			if(t.mul>0)
				continue;
			var a = [];
			for(var j=0; j<t.count; ++j)
					out.push(t.type);
		}
		return '['+out.join(',')+']';
	}
	$scope.reset = function(){
			for(var i in $scope.parts)
				if($scope.parts[i].mul<0)
					$scope.parts[i].count = $scope.parts[i].min;
	}
	$scope.parseInput = function(){
		for(var p of $scope.parts) {
			p.boostPower = 0;
			if(p.mul<0){
				var match = $scope.inputText.match(new RegExp("\\b"+p.type+"\\b", 'g'));
				p.count = match ? Math.max(match.length, p.min) : p.min;
			}
			$scope.updateLink()
		}
	}
	$scope.updateLink = function(){
		$scope.creepHash = $scope.getCreepHash()
		
		$scope.creepUrl = window.location.href + $scope.creepHash
		$scope.inputText = $scope.getParts()
	}
	$scope.getCreepHash = function(){
		return btoa($scope.getParts());
	}
	$scope.getBodyFromHash = function(){
		return atob(window.location.hash.substring(2))
	}
	$scope.inputText = $scope.getBodyFromHash()
	$scope.parseInput()
	$scope.boosts = {
		'MOVE': [
			{ text: '-' },
			{ text: 'ZO' },
			{ text: 'ZHO2' },
			{ text: 'XZHO2' },
		],
		'TOUGH': [
			{ text: '-' },
			{ text: 'GO' },
			{ text: 'GHO2' },
			{ text: 'XGHO2' },
		],
		'WORK': [
			{ text: '-' },
			{ text: 'ZH' },
			{ text: 'ZH2O' },
			{ text: 'XZH2O' },
			{ text: 'LH' },
			{ text: 'LH2O' },
			{ text: 'XLH2O' },
			{ text: 'GH' },
			{ text: 'GH2O' },
			{ text: 'XGH2O' },
			{ text: 'UO' },
			{ text: 'UHO2' },
			{ text: 'XUHO2' },
		],
		'CARRY' : [
			{ text: '-' },
			{ text: 'KH' },
			{ text: 'KH2O' },
			{ text: 'XKH2O' },
		],
		'ATTACK' : [
			{ text: '-' },
			{ text: 'UH' },
			{ text: 'UH2O' },
			{ text: 'XUH2O' },
		],
		'RANGED_ATTACK' : [
			{ text: '-' },
			{ text: 'KO' },
			{ text: 'KHO2' },
			{ text: 'XKHO2' },
		],
		'HEAL' : [
			{ text: '-' },
			{ text: 'LO' },
			{ text: 'LHO2' },
			{ text: 'XLHO2' },
		],
	}
	$scope.bmul = {
		'harvest': {
			'UO': 3,
			'UHO2': 5,
			'XUHO2': 7
		},
		'upgrade': {
			'GH': 1.5,
			'GH2O': 1.8,
			'XGH2O': 2
		},
		'build': {
			'LH': 1.5,
			'LH2O': 1.8,
			'XLH2O': 2
		},
		'dismantle': {
			'ZH': 2,
			'ZH2O': 3,
			'XZH2O': 4
		},
		'attack': {
			'UH': 2,
			'UH2O': 3,
			'XUH2O': 4
		},
		'rangedAttack': {
			'KO': 2,
			'KHO2': 3,
			'XKHO2': 4
		},
		'heal': {
			'LO': 2,
			'LHO2': 3,
			'XLHO2': 4
		},
		'carry': {
			'KH': 2,
			'KH2O': 3,
			'XKH2O': 4
		},
		'move': {
			'ZO': 2,
			'ZHO2': 3,
			'XZHO2': 4
		},
		'armor': {
			'GO': 30,
			'GHO2': 50,
			'XGHO2': 70
		}
	}
	$scope.controllerLevels = [
		{spawns: 0, extensions: 0, extensionCapacity: 0, text: 'no (='},
		{spawns: 1, extensions: 0, extensionCapacity: 50, text: '1'},
		{spawns: 1, extensions: 5, extensionCapacity: 50, text: '2'},
		{spawns: 1, extensions: 10, extensionCapacity: 50, text: '3'},
		{spawns: 1, extensions: 20, extensionCapacity: 50, text: '4'},
		{spawns: 1, extensions: 30, extensionCapacity: 50, text: '5'},
		{spawns: 1, extensions: 40, extensionCapacity: 50, text: '6'},
		{spawns: 2, extensions: 50, extensionCapacity: 100, text: '7'},
		{spawns: 3, extensions: 60, extensionCapacity: 200, text: '8'},
	];
	$scope.controllerLevel = $scope.controllerLevels['8'];
	$scope.$watch('controllerLevel', function(val){
			if(!val)
				return;
			assoc['spawn'].count = val.spawns;
			assoc['extension'].count = val.extensions;
		  assoc['extension'].price = val.extensionCapacity;
	});
	$scope.maxHarvest = function(mul){
		return Math.min(60*60/300*1500*mul, assoc['WORK'].count*5*60*60*mul);
	};
/*
t = ceil(k * W / M)

Where:
    t = time (game ticks)
    k = terrain factor (1x for plain, 0.5x for road, 5x for swamp)
    W = creep weight (Number of body parts, excluding MOVE and empty CARRY parts)
    M = number of MOVE parts
*/
	$scope.getWait = function(k, full){
		var W = $scope.getPartsCount() - +assoc['MOVE'].count - (full ? 0 : +assoc['CARRY'].count);
		var M = +assoc['MOVE'].count*($scope.bmul['move'][assoc['MOVE'].boost]||1);
		var speed = Math.ceil(k * W / M);
		return Math.max(1,speed);
	};
	$scope.getHits = function(toughOnly){
	  var armor = assoc['TOUGH'];
		var armorHits = armor.count*100*100/(100-($scope.bmul['armor'][armor.boost]||0));
		if(toughOnly) {
			return armorHits;
		} else {
			var unarmoredHp = 100*($scope.getPartsCount()-assoc['TOUGH'].count);
			return unarmoredHp + armorHits;
		}
	}
}])

.filter('num', function(){
	return function(n, w){
		if(n==0) {
			return '';
		}
		if(w === undefined)
				w = 3;
		if(w == 0) {
			return n;
		}
		if(n<1000)
			return n.toPrecision(w);
		else if(n<1000000)
			return (n/1000).toPrecision(w)+'K';
		else
			return (n/1000000).toPrecision(w)+'M';
	};
})

;
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console