Here's what I've done so far.
Code: Select all
/*ShadowBot Goals:
- Attempt to adapt production towards whatever weapon-vehicle and weapon-structure combos the opponent is using.
- Attempt to fight the opponent on multiple fronts by building proxy factories.
- Be ready to rebuild elsewhere if main base is sacked (so that it's harder to kill off).
- Map-specific strategy support.
- Multiple personality support.
- Being able to work with human players in executing complex tasks, including building defenses where specified, and following waypoint paths to attack opponents from the side or rear.
*/
var unitID = []; //This is a list of all units' IDs currently owned by the AI.
var unitRole = []; //This is used by individual units to determine their behavior, both individually, and while working with other units as a team.
const UNIT_ROLE_TANK = 0; //This unit's role is to soak up damage for the other units in its group. Since it tends to be more expensive than others within its group, it'll try to retreat if at low health.
const UNIT_ROLE_DPS = 1; //This unit's role is to deal as much damage as possible. Typically, they're not very durable, so they must rely on tanks to protect them, though on the other hand, they tend to be inexpensive, and thus, expendable.
const UNIT_ROLE_HARASSER = 2; //This unit's role is to rush in, deal damage, and get out before trouble comes. While harassers can possess either short or long range weaponry, including Mortars, speed is of utmost priority.
const UNIT_ROLE_SIEGE = 3; //This unit's role is to accompany an assaulting force to lay down close-range fire support. Typically, they're armed with short-range artillery, such as Mortars.
const UNIT_ROLE_FIRESUPPORT = 4; //Same as the siege role, only they stay safely away from the battlefield, and use long-ranged artillery such as Howitzers or Ripple Rockets. While size or degree of protection doesn't matter for these units, speed is of little priority.
const UNIT_ROLE_COUNTERBATTERY = 5; //This unit's role is to stay within the safety of the base and provide counter-battery and counter-radar fire with their long-range artillery weapons. High rate-of-fire or durability is of little concern since they need to take out their targets ASAP, so they'll typically be armed with weapons such as Ripple Rockets or Ground Shakers. However, they'll typically prioritize higher rate-of-fire artillery, such as Mortars and Hellstorms, over lower rate-of-fire artillery, such as the enemy's own Ground Shakers or Ripple Rockets (which can be dealt with by those units assigned to the siege or fire support roles).
const UNIT_ROLE_PROBE = 6; //This unit's role is to attempt to see what the enemy's base is like. Often, this would be a cheap, fast, expendable unit such as a Cyborg Machinegunner, Bug Machinegun Hover, or Bug Machinegun VTOL, but sometimes, a heavy-bodied unit, a unit equipped with a high damage-per-shot weapon (such as a Lancer, MRA, or Bunker Buster), and/or a unit equipped with a Sensor Turret is used instead.
const UNIT_ROLE_INTERCEPTOR = 7; //This unit's role is to intercept and destroy enemy units, especially fast-moving ones like harassers and VTOLs. They tend to be fast-moving hovers or VTOLs themselves. May attempt to flank and attack enemies from behind. Will attempt to pursue fleeing enemies until they're low on health, or until they run into heavy opposition.
const UNIT_ROLE_DEFENDER = 8; //Same as the interceptor role, only that they won't pursue enemies outside their designated area. They tend to be slow-moving units such as Tracks or Super Cyborgs.
const UNIT_ROLE_CONSTBASE = 9; //This unit's role is to stay within their designated base and build new structures. Neither speed nor durability are a priority, so the AI would typically assign Combat Engineers this role.
const UNIT_ROLE_CONSTOIL = 10; //This unit's role is to capture oil resources as quickly as possible. As such, speed is important, so the AI would prefer to use hover trucks to accomplish this goal.
const UNIT_ROLE_CONSTOUTPOST = 11; //This unit's role is to build and maintain outposts close to the front lines, or sometimes, even behind enemy lines. As such, durability is a priority, so heavy bodies (along with heavy construction turrets if available) are preferred, though sometimes, Combat Engineers are used to drop behind enemy lines using Cyborg Transports.
const UNIT_ROLE_SPOTTER = 12; //This unit's role is to spot targets for artillery bombardment.
const UNIT_ROLE_CBSENSOR = 13; //This unit's role is to escort groups of units and help protect them from enemy artillery.
const UNIT_ROLE_RADARDETECTOR = 14; //Same as above, though it attempts to spot enemy sensors.
const UNIT_ROLE_REPAIR = 15; //This unit's role is to repair damaged units that arrive at its designated area. Oftentimes, they'll be Cyborg Mechanics.
const UNIT_ROLE_REPAIRCOMBAT = 16; //This unit's role is to repair damaged units as they're retreating from the battlefield. As such, high durability is a priority, since chances are that they'll be a high-priority target for enemy forces.
const UNIT_ROLE_TRANSPORT = 17; //This unit's role is to transport other units across the battlefield.
const UNIT_ROLE_COMMANDER = 18; //This unit's role is to provide a combat bonus to whatever troops are assigned to it. Often, new commanders tend to be built using cheaper, lighter bodies, while more experienced commanders are recycled and placed in more durable, more expensive bodies.
const UNIT_ROLE_EMP = 19; //This unit's role is to temporarily disable enemy units and structures so that its teammates can safely finish them off.
const UNIT_ROLE_NEXUS = 20; //This unit's role is to capture enemy units and structures. Often, it'll prioritize capturing more defenseless stuff, like isolated Oil Derricks and wandering trucks, though it can be used in rush attacks. Prioritizes speed over defense.
var unitBody = []; //The internal name of the body being used by the unit.
const BODY_CYBORG1 = 0;
const BODY_CYBORG2 = 1;
const BODY_CYBORG3 = 2;
const BODY_CYBORG4 = 3;
const BODY_SUPERCYBORG1 = 4;
const BODY_SUPERCYBORG2 = 5;
const BODY_SUPERCYBORG3 = 6;
const BODY_SUPERCYBORG4 = 7;
const BODY_VIPER = 8;
const BODY_COBRA = 9;
const BODY_PYTHON = 10;
const BODY_COUATL = 11;
const BODY_BUG = 12;
const BODY_SCORPION = 13;
const BODY_MANTIS = 14;
const BODY_ABADDON = 15;
const BODY_LEOPARD = 16;
const BODY_PANTHER = 17;
const BODY_TIGER = 18;
const BODY_SABRETOOTH = 19;
const BODY_FALCON = 20;
const BODY_WARHAWK = 21;
const BODY_EAGLE = 22;
const BODY_PHOENIX = 23;
const BODY_GLADIUS = 24;
const BODY_LONGSWORD = 25;
const BODY_CLAYMORE = 26;
const BODY_EXCALIBUR = 27;
const BODY_RETALIATION = 28;
const BODY_RETRIBUTION = 29;
const BODY_VENGEANCE = 30;
const BODY_NEMESIS = 31;
const BODY_WYRMLING = 32;
const BODY_SALAMANDER = 33;
const BODY_WYVERN = 34;
const BODY_DRAGON = 35;
const BODY_TRANSPORT = 36;
const BODY_SUPERTRANSPORT = 37;
var bodyEngine = []; //The engine power of the body after upgrades. Used by the AI to help keep itself from designing units that are either too heavy (especially) or too light for their engine power.
const bodyBaseEngine = [1080,1080,1080,1080,1000,1000,1000,1000,3000,6000,12000,24000,3000,6000,12000,24000,2381,4762,9524,19049,2381,4762,9524,19049,1890,3780,7560,15119,1890,3780,7560,15119,1500,3000,6000,12000,1000,24000]; //The base engine power of the body.
var engineMultiplier = 1;
const bodyWeight = [999,999,999,999,999,999,999,999,250,500,1000,2000,166,333,666,1333,250,500,1000,2000,166,333,666,1333,250,500,1000,2000,166,333,666,1333,250,500,1000,2000,0,0]; //The weight of the body. Used by the AI to help keep itself from designing units that are either too heavy or too light for their engine power.
var unitPropulsion = []; //The name of the propulsion system used by the unit.
const PROPULSION_WHEELS = 0;
const PROPULSION_HALFTRACKS = 1;
const PROPULSION_TRACKS = 2;
const PROPULSION_HOVER = 3;
const PROPULSION_VTOL = 4;
const PROPULSION_CYBORG = 5;
const PROPULSION_SUPERCYBORG = 6;
const propulsionWeightModifier = [8,6,4,12,1,1,1]; //The weight of the propulsion system. Used by the AI to help keep itself from designing units that are either too heavy or too light for their engine power.
const propulsionTerrainModifier = [
[1,1.5,0,.5],
[1,1.5,0,.5],
[1,1.5,0,.5],
[1,1,1.5,1],
[1,1,1,1],
[1,1.5,0,.5],
[1,1.5,0,.5]
]; //The multiplier to apply to the engine power of units that are using X propulsion and traveling over Y terrain. Useful if the AI finds itself playing on a map that it recognizes possesses an abundance of one or more of the following terrain types:
const TERRAIN_DEFAULT = 0;
const TERRAIN_ROAD = 1;
const TERRAIN_WATER = 2;
const TERRAIN_MUD = 3;
var unitTurret = []; //The internal name of the primary turret that the unit is equipped with.
var turretWeight = []; //The turret's weight.
var weaponDamagePerShot = []; //The weapon's base damage-per-shot, modified by weapon upgrades. This is used to determine what targets units armed with this weapon should prioritize over others.
const weaponBaseDamagePerShot = []; //The weapon's base damage-per-shot.
var weaponROF = []; //The weapon's rate-of-fire.
const weaponBaseROF = []; //The weapon's base rate-of-fire.
var weaponDamagePerSecond = [{{}}]; //3D array that determines X weapon's predicted damage-per-second against Y designated target body and Z propulsion type.
const weaponType = []; //The weapon's class, also used to determine what targets units armed with this weapon should prioritize over others.
const WEAPON_TYPE_ANTIPERSONNEL = 0;
const WEAPON_TYPE_ALLROUNDER = 1;
const WEAPON_TYPE_ANTITANK = 2;
const WEAPON_TYPE_BUNKERBUSTER = 3;
const WEAPON_TYPE_ANTISTRUCTURE = 4;
const WEAPON_TYPE_FLAMER = 5;
const weaponClass = []; //Whether the weapon deals kinetic or thermal damage. Used in tertiary target prioritizing.
const WEAPON_CLASS_KINETIC = 0;
const WEAPON_CLASS_THERMAL = 1;
const weaponSubclass = []; //The subclass that the weapon belongs to.
const WEAPON_SUBCLASS_MACHINEGUN = 0;
const WEAPON_SUBCLASS_CANNON = 1;
const WEAPON_SUBCLASS_ROCKET = 2;
const WEAPON_SUBCLASS_FLAMER = 3;
const WEAPON_SUBCLASS_MORTAR = 4;
const WEAPON_SUBCLASS_HOWITZER = 5;
const WEAPON_SUBCLASS_ANTIAIR = 6;
const WEAPON_SUBCLASS_BOMB = 7;
const WEAPON_SUBCLASS_LASER = 8;
const WEAPON_SUBCLASS_RAILGUN = 9;
const WEAPON_SUBCLASS_MISSILE = 10;
const WEAPON_SUBCLASS_SPECIAL = 11; //Reserved for special weapons such as NEXUS Link Turrets, EMPs, and the LasSat.
var subclassDamageModifier = []; //The multiplier to apply to the damage-per-shot of a weapon belonging to a certain weapon line.
var subclassROFModifier = []; //Used to help determine which weapons the AI should prioritize production/construction over others.
var groupList = []; //This determines which droids belong to a certain group.
var groupPrice = []; //This is the cost (in power) that was used to create the entire group. Used to determine when the group should retreat for repairs.
var groupStrength = []; //This is a measure of the group's remaining health. It is calculated as this: groupStrength = the sum of each individual unit's cost times the unit's remaining health percentage.
var groupObjective = []; //This determines the group's objective, whether it's to build a base, look for oil, perform raids on enemy oil, lay siege upon the enemy's base, etc.
//Create lists of components that will be useful for target prioritizing purposes.
include("multiplay/skirmish/component-definitions.inc");
function eventStartLevel()
{
}Since I'll probably want to create and use arrays that keep track of what each of the AI player's units' and structures' stats are in-game, I'll probably be using the array.splice function liberally whenever one of the AIs own units or structures is destroyed.
By the way, has anyone ever tried to create a 3D array? For example:
Code: Select all
myArray = [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]]Would such an array work on JavaScript?
Edit: Nevermind. I tested it, and 3D arrays seem to work just fine.



