Skip to content

Commit

Permalink
Add tech handler for campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
perim committed May 25, 2013
1 parent a212e90 commit d4ebc6a
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions data/base/script/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,70 @@ function eventDestroyed(victim)
setDesign(false);
}
}

function eventResearched(research, structure, player)
{
//debug("RESEARCH : " + research.fullname + "(" + research.name + ") for " + player + " results=" + research.results);
for (var v = 0; v < research.results.length; v++)
{
var s = research.results[v].split(":");
if (['Droids', 'Cyborgs'].indexOf(s[0]) >= 0) // research result applies to droids and cyborgs
{
for (var i in Upgrades[player].Body) // loop over all bodies
{
if (Stats.Body[i].BodyClass === s[0]) // if match against hint in ini file, change it
{
// eg Upgrades[0].Body['Tiger']['Armour']
Upgrades[player].Body[i][s[1]] += Math.ceil(Stats.Body[i][s[1]] * s[2] / 100);
//debug(" upgraded " + i + " :: " + s[1] + " to " + Upgrades[player].Body[i][s[1]] + " by " + Math.ceil(Stats.Body[i][s[1]] * s[2] / 100));
}
}
}
else if (['ResearchPoints', 'ProductionPoints', 'PowerPoints', 'RepairPoints', 'RearmPoints'].indexOf(s[0]) >= 0)
{
for (var i in Upgrades[player].Building)
{
if (Stats.Building[i][s[0]] > 0) // only applies if building has this stat already
{
Upgrades[player].Building[i][s[0]] += Math.ceil(Stats.Building[i][s[0]] * s[1] / 100);
//debug(" upgraded " + i + " to " + Upgrades[player].Building[i][s[0]] + " by " + Math.ceil(Stats.Building[i][s[0]] * s[1] / 100));
}
}
}
else if (['Wall', 'Structure'].indexOf(s[0]) >= 0)
{
for (var i in Upgrades[player].Building)
{
if (Stats.Building[i].Type === s[0]) // applies to specific building type
{
Upgrades[player].Building[i][s[1]] += Math.ceil(Stats.Building[i][s[1]] * s[2] / 100);
//debug(" upgraded " + i + " to " + Upgrades[player].Building[i][s[1]] + " by " + Math.ceil(Stats.Building[i][s[1]] * s[2] / 100));
}
}
}
else if (['ECM', 'Sensor', 'Repair', 'Construct'].indexOf(s[0]) >= 0)
{
for (var i in Upgrades[player][s[0]])
{
// Upgrades.player.type.buildingName.parameter ... hard to read but short and flexible
Upgrades[player][s[0]][i][s[1]] += Math.ceil(Stats[s[0]][i][s[1]] * s[2] / 100);
//debug(" upgraded " + i + " to " + Upgrades[player][s[0]][i][s[1]] + " by " + Math.ceil(Stats[s[0]][i][s[1]] * s[2] / 100));
}
}
else if (Stats.WeaponClass.indexOf(s[0]) >= 0) // if first field is a weapon class
{
for (var i in Upgrades[player].Weapon)
{
if (Stats.Weapon[i][s[1]] > 0 && Stats.Weapon[i].ImpactClass === s[0])
{
Upgrades[player].Weapon[i][s[1]] += Math.ceil(Stats.Weapon[i][s[1]] * s[2] / 100);
//debug(" upgraded " + i + " to " + Upgrades[player].Weapon[i][s[1]] + " by " + Math.ceil(Stats.Weapon[i][s[1]] * s[2] / 100));
}
}
}
else
{
debug("(error) Unrecognized research hint=" + s[0]);
}
}
}

0 comments on commit d4ebc6a

Please sign in to comment.