Skip to content

Commit

Permalink
Fix bugs in production and build.
Browse files Browse the repository at this point in the history
Weapon based units would not be produced in a factory due to bad logic with system units. Now checks that the most basic component of a system can be produced.
Increase power restrictions for building which leads to overall better success.
Slight research path alterations.
and general tweaks in other areas.
  • Loading branch information
KJeff01 authored Aug 11, 2017
1 parent aa304c1 commit 4ba7046
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 75 deletions.
6 changes: 3 additions & 3 deletions multiplay/skirmish/cobra_includes/adaption.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function switchOffMG() {
}

var len = subpersonalities[personality].primaryWeapon.weapons.length;
if(isDesignable(subpersonalities[personality].primaryWeapon.weapons[len - 1].stat)) {
if(isDesignable(subpersonalities[personality].primaryWeapon.weapons[len - 1].stat) || (playerAlliance(true).length > 0)) {
turnOffMG = true;
removeThisTimer("switchOffMG");
}
Expand Down Expand Up @@ -42,10 +42,10 @@ function adaptToMap() {
const T3_MATCH = isDesignable("Howitzer03-Rot");
const ADAPT_PERSONALITIES = ["AM", "AR", "AB", "AC", "AL"];

if(!T3_MATCH && (((maxPlayers - 1) === 1) || (MAP_OIL_LEVEL === "LOW") || (baseType === CAMP_CLEAN))) {
if(!T3_MATCH && (((maxPlayers - 1) === 1) || ((MAP_OIL_LEVEL === "LOW") && !ALLY_COUNT))) {
choice = ADAPT_PERSONALITIES[random(3)]; // AM, AR, AB.
}
else if ((MAP_OIL_LEVEL === "MEDIUM") || ((ALLY_COUNT !== 0) && (ALLY_COUNT < ENEMY_COUNT))) {
else if ((MAP_OIL_LEVEL === "MEDIUM") || ALLY_COUNT) {
var offset = (T3_MATCH && (baseType !== CAMP_CLEAN)) ? 4 : 3;
choice = ADAPT_PERSONALITIES[random(offset) + 1]; // AR, AB, AC, AL.
}
Expand Down
55 changes: 25 additions & 30 deletions multiplay/skirmish/cobra_includes/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function checkUnfinishedStructures() {

//Look for oil.
function lookForOil() {
var droids = (gameTime < 10000) ? enumGroup(constructGroup) : enumGroup(oilGrabberGroup);
var droids = (gameTime < 15000) ? enumDroid(me, DROID_CONSTRUCT) : enumGroup(oilGrabberGroup);
var oils = enumFeature(-1, oilResources).sort(distanceToBase); // grab closer oils first
var s = 0;
var success = false;
Expand Down Expand Up @@ -319,7 +319,7 @@ function buildAAForPersonality() {

//Build defense systems.
function buildDefenses() {
const MIN_POWER = 30;
const MIN_POWER = 90;

if((gameTime > 120000) && (getRealPower() > MIN_POWER)) {
if(buildSensors()) {
Expand All @@ -338,12 +338,11 @@ function buildDefenses() {
function buildPhase1() {
//if a hover map without land enemies, then build research labs first to get to hover propulsion even faster
if(!forceHover || seaMapWithLandEnemy) {
if(countAndBuild(FACTORY, 1)) {
if(countAndBuild(FACTORY, 2)) {
return true;
}

var res = (baseType !== CAMP_CLEAN) ? 2 : 1;
if(!researchComplete && countAndBuild(structures.labs, res)) {
if(!researchComplete && countAndBuild(structures.labs, 1)) {
return true;
}

Expand All @@ -365,16 +364,12 @@ function buildPhase1() {
return true;
}

if(countAndBuild(FACTORY, 2)) {
return true;
}

return false;
}

//Build at least one of each factory and then pursue the favorite factory.
function factoryBuildOrder() {
const MIN_POWER = 80;
const MIN_POWER = 200;
if(getRealPower() < MIN_POWER) {
return false;
}
Expand All @@ -399,28 +394,28 @@ function factoryBuildOrder() {
//Build all research labs and one of each factory and pursue the decided factory order.
//Build repair bays when possible.
function buildPhase2() {
const MIN_POWER = 30;
const MIN_TIME = 150000;
const MIN_POWER = 250;
const MIN_TIME = 180000;
if(!countStruct(structures.gens) || (getRealPower() < MIN_POWER)) {
return true;
}

if(!researchComplete && countAndBuild(structures.labs, 2)) {
return true;
}

if(gameTime > MIN_TIME) {
if(!researchComplete && countAndBuild(structures.labs, 5)) {
if(random(3) && countAndBuild(structures.extras[0], 5)) {
return true;
}

if(countAndBuild(FACTORY, 2)) {
if(!researchComplete && countAndBuild(structures.labs, 5)) {
return true;
}

if (factoryBuildOrder()) {
return true;
}

if(countAndBuild(structures.extras[0], 5)) {
return true;
}
}

return false;
Expand All @@ -443,7 +438,7 @@ function buildSpecialStructures() {

//Build the minimum repairs and any vtol pads.
function buildExtras() {
const MIN_POWER = 30;
const MIN_POWER = 70;
if(!isStructureAvailable("A0PowMod1") || (gameTime < 80000) || (getRealPower() < MIN_POWER)) {
return false;
}
Expand All @@ -467,39 +462,39 @@ function buildOrder() {
if(enemyUnitsInBase()) { return; }
if(buildSpecialStructures()) { return; }
if(buildExtras()) { return; }
if(!lookForOil()) { buildDefenses(); }
lookForOil();
if(buildPhase2()) { return; }
buildDefenses();
}

//Check if a building has modules to be built
function maintenance() {
const list = ["A0PowMod1", "A0ResearchModule1", "A0FacMod1", "A0FacMod1"];
const mods = [1, 1, 2, 2]; //Number of modules paired with list above
var cacheList = list.length;
const LIST = ["A0PowMod1", "A0FacMod1", "A0ResearchModule1", "A0FacMod1"];
const MODS = [1, 2, 1, 2]; //Number of modules paired with list above
var struct = null, module = "", structList = [];

if(countStruct(structures.derricks) < 4) {
return false;
}

for (var i = 0; i < cacheList; ++i) {
if (isStructureAvailable(list[i])) {
for (var i = 0, l = LIST.length; i < l; ++i) {
if (isStructureAvailable(LIST[i])) {
if(struct !== null) {
break;
}
switch(i) {
case 0: { structList = enumStruct(me, structures.gens).sort(distanceToBase); break; }
case 1: { structList = enumStruct(me, structures.labs).sort(distanceToBase); break; }
case 2: { structList = enumStruct(me, FACTORY).sort(distanceToBase); break; }
case 1: { structList = enumStruct(me, FACTORY).sort(distanceToBase); break; }
case 2: { structList = enumStruct(me, structures.labs).sort(distanceToBase); break; }
case 3: { structList = enumStruct(me, VTOL_FACTORY).sort(distanceToBase); break; }
default: { break; }
}

for (var c = 0, s = structList.length; c < s; ++c) {
if (structList[c].modules < mods[i]) {
if (structList[c].modules < MODS[i]) {
//Only build the last factory module if we have a heavy body
if(structList[c].modules === 1) {
if((i === 2) && !componentAvailable("Body11ABT")) {
if((i === 1) && !componentAvailable("Body11ABT")) {
continue;
}
//Build last vtol factory module once Cobra gets retribution (or has good power levels)
Expand All @@ -508,7 +503,7 @@ function maintenance() {
}
}
struct = structList[c];
module = list[i];
module = LIST[i];
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions multiplay/skirmish/cobra_includes/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function eventDroidIdle(droid) {
function eventDroidBuilt(droid, struct) {
if (droid) {
if(isConstruct(droid)) {
if(!isDefined(enumGroup(constructGroup)[3])) {
if(enumGroup(constructGroup).length < 3) {
groupAdd(constructGroup, droid);
queue("checkUnfinishedStructures", 2500);
}
Expand Down Expand Up @@ -212,7 +212,6 @@ function eventBeacon(x, y, from, to, message) {
return;
}


if(allianceExistsBetween(from, to) || (to === from)) {
var cyborgs = enumGroup(cyborgGroup);
var tanks = enumGroup(attackGroup);
Expand Down
6 changes: 3 additions & 3 deletions multiplay/skirmish/cobra_includes/globalVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const subpersonalities = {
"artillery": weaponStats.howitzers,
"antiAir": weaponStats.AA, //cannons_AA is too weak.
"factoryOrder": [FACTORY, CYBORG_FACTORY, VTOL_FACTORY],
"peaceChance": 70,
"peaceChance": 100,
"defensePriority": 10,
"vtolPriority": 20,
"systemPriority": 30,
Expand Down Expand Up @@ -66,7 +66,7 @@ const subpersonalities = {
"artillery": weaponStats.mortars,
"antiAir": weaponStats.AA,
"factoryOrder": [FACTORY, CYBORG_FACTORY, VTOL_FACTORY],
"peaceChance": 40,
"peaceChance": 80,
"defensePriority": 30,
"vtolPriority": 80,
"systemPriority": 45,
Expand All @@ -81,7 +81,7 @@ const subpersonalities = {
"artillery": weaponStats.fireMortars,
"antiAir": weaponStats.AA,
"factoryOrder": [VTOL_FACTORY, FACTORY, CYBORG_FACTORY],
"peaceChance": 55,
"peaceChance": 75,
"defensePriority": 10,
"vtolPriority": 60,
"systemPriority": 40,
Expand Down
25 changes: 6 additions & 19 deletions multiplay/skirmish/cobra_includes/miscFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ function isDefined(data) {
return (typeof(data) !== "undefined");
}

//Determine if a game object is destroyed or not.
function isObjectAlive(object) {
return (isDefined(object) && object && (object.id !== 0));
}

//Sort an array from smallest to largest in value.
function sortArrayNumeric(a, b) {
return (a - b);
Expand Down Expand Up @@ -162,24 +167,6 @@ function diffPerks() {
}
}

//See if we can design this droid. Mostly used for checking for new weapons with the NIP.
function isDesignable(item, body, prop) {
if(!isDefined(item)) {
return false;
}

if(!isDefined(body)) {
body = "Body1REC";
}

if(!isDefined(prop)) {
prop = "wheeled01";
}

var virDroid = makeTemplate(me, "Virtual Droid", body, prop, "", "", item, item);
return (virDroid !== null);
}

//See if power levels are low. This takes account of only the power obtained from the generators.
function checkLowPower(pow) {
if(!isDefined(pow)) {
Expand Down Expand Up @@ -307,7 +294,7 @@ function countEnemyVTOL() {
var enemies = findLivingEnemies();
var enemyVtolCount = 0;

for (var x = 0, e = enemies.length; x < e; ++x) {
for(var x = 0, e = enemies.length; x < e; ++x) {
enemyVtolCount += enumDroid(enemies[x]).filter(function(obj) {
return isVTOL(obj);
}).length;
Expand Down
26 changes: 22 additions & 4 deletions multiplay/skirmish/cobra_includes/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ const repairTurrets = [
"LightRepair1",
];

//See if we can design this droid. Mostly used for checking for new weapons with the NIP.
function isDesignable(item, body, prop) {
if(!isDefined(item)) {
return false;
}

if(!isDefined(body)) {
body = "Body1REC";
}

if(!isDefined(prop)) {
prop = "wheeled01";
}

var virDroid = makeTemplate(me, "Virtual Droid", body, prop, "", "", item, item);
return (virDroid !== null);
}

//Pick a random weapon line. May return undefined for machineguns.
function chooseRandomWeapon() {
var weaps;
Expand All @@ -52,7 +70,7 @@ function chooseRandomWeapon() {
default: weaps = subpersonalities[personality].primaryWeapon; break;
}

if(!isDefined(weaps) || (returnPrimaryAlias() !== "las")) {
if(!isDefined(weaps)) {
weaps = subpersonalities[personality].primaryWeapon;
}

Expand Down Expand Up @@ -341,7 +359,7 @@ function produce() {
return;
}

const MIN_POWER = -20;
const MIN_POWER = 30;
const MIN_TRUCKS = 5;
const MIN_COM_ENG = 3;
const MIN_SENSORS = 2;
Expand Down Expand Up @@ -369,10 +387,10 @@ function produce() {
if(buildTrucks) {
buildSys(fac[x], "Spade1Mk1");
}
else if(buildSensors) {
else if(buildSensors && componentAvailable("SensorTurret1Mk1")) {
buildSys(fac[x]);
}
else if(allowSpecialSystems && buildRepairs) {
else if(allowSpecialSystems && buildRepairs && componentAvailable("LightRepair1")) {
buildSys(fac[x], repairTurrets);
}
else {
Expand Down
Loading

0 comments on commit 4ba7046

Please sign in to comment.