mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-08 16:05:48 -07:00
Key changes are: Support for Persians Revamped defence system supoprting groups of attackers Dynamic priorities based on enemy strength and number of workers Better placement of towers and fortresses Randomised raiding in early game This was SVN commit r10755.
51 lines
932 B
JavaScript
51 lines
932 B
JavaScript
function VectorDistance(a, b)
|
|
{
|
|
var dx = a[0] - b[0];
|
|
var dz = a[1] - b[1];
|
|
return Math.sqrt(dx*dx + dz*dz);
|
|
}
|
|
|
|
function SquareVectorDistance(a, b)//A sqrtless vector calculator, to see if that improves speed at all.
|
|
{
|
|
var dx = a[0] - b[0];
|
|
var dz = a[1] - b[1];
|
|
return (dx*dx + dz*dz);
|
|
}
|
|
|
|
function MemoizeInit(obj)
|
|
{
|
|
obj._memoizeCache = {};
|
|
}
|
|
|
|
function Memoize(funcname, func)
|
|
{
|
|
return function() {
|
|
var args = funcname + '|' + Array.prototype.join.call(arguments, '|');
|
|
if (args in this._memoizeCache)
|
|
return this._memoizeCache[args];
|
|
|
|
var ret = func.apply(this, arguments);
|
|
this._memoizeCache[args] = ret;
|
|
return ret;
|
|
};
|
|
}
|
|
|
|
function ShallowClone(obj)
|
|
{
|
|
var ret = {};
|
|
for (var k in obj)
|
|
ret[k] = obj[k];
|
|
return ret;
|
|
}
|
|
|
|
// Picks a random element from an array
|
|
function PickRandom(list){
|
|
if (list.length === 0)
|
|
{
|
|
return undefined;
|
|
}
|
|
else
|
|
{
|
|
return list[Math.floor(Math.random()*list.length)];
|
|
}
|
|
}
|