System Populator editable by Javascript?
Posted: Sat Dec 08, 2012 10:00 pm
An interesting concept was mentioned in this thread about the system populator being editable by Javascript. I tried playing around with the code a bit and managed to get it so that the system populator could be editable via the planetinfo.plist file.
The code could be modified to make these functions editable in the planetinfo.plist file. Using the source code from version 1.76.1, the original code in the Universe.m file from line 9079 reads like this: But if the previous code is changed with the following code: Now the game will check whether there is an entry in the planetinfo.list file that can overide the number of ships in each category that are generated in that system. So if an entry was added to the planetinfo.plist file that reads: Now every time the player enters the Lave system in Galaxy 1 there will be 100 Thargoid Warships in that system. This could also be used to always ensure that there are no police in a system, as the code will currently always make sure there is at least 1 police/bounty hunter in a system (see code above under the //debug comment).
So using the above as a template, would it be much more work to make this editable by Javascript? You can already use commands in Javascript to change system properties like the tech level, name, productivity, etc... so could this be expanded upon in the same way?
The code could be modified to make these functions editable in the planetinfo.plist file. Using the source code from version 1.76.1, the original code in the Universe.m file from line 9079 reads like this:
Code: Select all
// traders
// TODO: consider using floating point for this stuff, giving a greater variety of possible results while maintaining the same range.
unsigned trading_parties = (9 - economy); // 2 .. 9
if (government == 0) trading_parties *= 1.25; // 25% more trade where there are no laws!
if (trading_parties > 0)
trading_parties = 1 + trading_parties * (randf()+randf()); // randomize 0..2
while (trading_parties > 15)
trading_parties = 1 + (Ranrot() % trading_parties); // reduce
OOLog(kOOLogUniversePopulate, @"... adding %d %@trading vessels", trading_parties, @"");
unsigned skim_trading_parties = (Ranrot() & 3) + trading_parties * (Ranrot() & 31) / 120; // about 12%
OOLog(kOOLogUniversePopulate, @"... adding %d %@trading vessels", skim_trading_parties, @"sun skim ");
// pirates
int anarchy = (8 - government);
unsigned raiding_parties = (Ranrot() % anarchy) + (Ranrot() % anarchy) + anarchy * trading_parties / 3; // boosted
raiding_parties *= randf() + randf(); // randomize
while (raiding_parties > 25)
raiding_parties = 12 + (Ranrot() % raiding_parties); // reduce
OOLog(kOOLogUniversePopulate, @"... adding %d %@pirate vessels", raiding_parties, @"");
unsigned skim_raiding_parties = ((randf() < 0.14 * economy)? 1:0) + raiding_parties * (Ranrot() & 31) / 120; // about 12%
OOLog(kOOLogUniversePopulate, @"... adding %d %@pirate vessels", skim_raiding_parties, @"sun skim ");
// bounty-hunters and the law
unsigned hunting_parties = (1 + government) * trading_parties / 8;
if (government == 0) hunting_parties *= 1.25; // 25% more bounty hunters in an anarchy
hunting_parties *= (randf()+randf()); // randomize
while (hunting_parties > 15)
hunting_parties = 5 + (Ranrot() % hunting_parties); // reduce
//debug
if (hunting_parties < 1)
hunting_parties = 1;
OOLog(kOOLogUniversePopulate, @"... adding %d %@law/bounty-hunter vessels", hunting_parties, @"");
unsigned skim_hunting_parties = ((randf() < 0.14 * government)? 1:0) + hunting_parties * (Ranrot() & 31) / 160; // about 10%
OOLog(kOOLogUniversePopulate, @"... adding %d %@law/bounty-hunter vessels", skim_hunting_parties, @"sun skim ");
unsigned thargoid_parties = 0;
while ((Ranrot() % 100) < thargoidChance && thargoid_parties < 16)
thargoid_parties++;
OOLog(kOOLogUniversePopulate, @"... adding %d Thargoid warships", thargoid_parties);
unsigned rockClusters = Ranrot() % 3;
if (trading_parties + raiding_parties + hunting_parties < 10)
rockClusters += 1 + (Ranrot() % 3);
rockClusters *= 2;
Code: Select all
// traders
// TODO: consider using floating point for this stuff, giving a greater variety of possible results while maintaining the same range.
unsigned trading_parties = (9 - economy); // 2 .. 9
if (government == 0) trading_parties *= 1.25; // 25% more trade where there are no laws!
if (trading_parties > 0)
trading_parties = 1 + trading_parties * (randf()+randf()); // randomize 0..2
while (trading_parties > 15)
trading_parties = 1 + (Ranrot() % trading_parties); // reduce
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_trading_parties = trading_parties;
trading_parties = [systeminfo oo_unsignedIntForKey:@"trading_parties" defaultValue:backup_trading_parties];
OOLog(kOOLogUniversePopulate, @"... adding %d %@trading vessels", trading_parties, @"");
unsigned skim_trading_parties = (Ranrot() & 3) + trading_parties * (Ranrot() & 31) / 120; // about 12%
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_skim_trading_parties = skim_trading_parties;
skim_trading_parties = [systeminfo oo_unsignedIntForKey:@"skim_trading_parties" defaultValue:backup_skim_trading_parties];
OOLog(kOOLogUniversePopulate, @"... adding %d %@trading vessels", skim_trading_parties, @"sun skim ");
// pirates
int anarchy = (8 - government);
unsigned raiding_parties = (Ranrot() % anarchy) + (Ranrot() % anarchy) + anarchy * trading_parties / 3; // boosted
raiding_parties *= randf() + randf(); // randomize
while (raiding_parties > 25)
raiding_parties = 12 + (Ranrot() % raiding_parties); // reduce
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_raiding_parties = raiding_parties;
raiding_parties = [systeminfo oo_unsignedIntForKey:@"raiding_parties" defaultValue:backup_raiding_parties];
OOLog(kOOLogUniversePopulate, @"... adding %d %@pirate vessels", raiding_parties, @"");
unsigned skim_raiding_parties = ((randf() < 0.14 * economy)? 1:0) + raiding_parties * (Ranrot() & 31) / 120; // about 12%
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_skim_raiding_parties = skim_raiding_parties;
skim_raiding_parties = [systeminfo oo_unsignedIntForKey:@"skim_raiding_parties" defaultValue:backup_skim_raiding_parties];
OOLog(kOOLogUniversePopulate, @"... adding %d %@pirate vessels", skim_raiding_parties, @"sun skim ");
// bounty-hunters and the law
unsigned hunting_parties = (1 + government) * trading_parties / 8;
if (government == 0) hunting_parties *= 1.25; // 25% more bounty hunters in an anarchy
hunting_parties *= (randf()+randf()); // randomize
while (hunting_parties > 15)
hunting_parties = 5 + (Ranrot() % hunting_parties); // reduce
//debug
if (hunting_parties < 1)
hunting_parties = 1;
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_hunting_parties = hunting_parties;
hunting_parties = [systeminfo oo_unsignedIntForKey:@"hunting_parties" defaultValue:backup_hunting_parties];
OOLog(kOOLogUniversePopulate, @"... adding %d %@law/bounty-hunter vessels", hunting_parties, @"");
unsigned skim_hunting_parties = ((randf() < 0.14 * government)? 1:0) + hunting_parties * (Ranrot() & 31) / 160; // about 10%
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_skim_hunting_parties = skim_hunting_parties;
skim_hunting_parties = [systeminfo oo_unsignedIntForKey:@"skim_hunting_parties" defaultValue:backup_skim_hunting_parties];
OOLog(kOOLogUniversePopulate, @"... adding %d %@law/bounty-hunter vessels", skim_hunting_parties, @"sun skim ");
unsigned thargoid_parties = 0;
while ((Ranrot() % 100) < thargoidChance && thargoid_parties < 16)
thargoid_parties++;
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_thargoid_parties = thargoid_parties;
thargoid_parties = [systeminfo oo_unsignedIntForKey:@"thargoid_parties" defaultValue:backup_thargoid_parties];
OOLog(kOOLogUniversePopulate, @"... adding %d Thargoid warships", thargoid_parties);
unsigned rockClusters = Ranrot() % 3;
if (trading_parties + raiding_parties + hunting_parties < 10)
rockClusters += 1 + (Ranrot() % 3);
// Check whether there is an entry in planetinfo.plist for party:
unsigned backup_rockClusters = rockClusters;
rockClusters = [systeminfo oo_unsignedIntForKey:@"rockClusters" defaultValue:backup_rockClusters];
rockClusters *= 2;
OOLog(kOOLogUniversePopulate, @"... adding %d asteroid clusters", rockClusters);
Code: Select all
"0 7" =
{
thargoid_parties = 100;
};
So using the above as a template, would it be much more work to make this editable by Javascript? You can already use commands in Javascript to change system properties like the tech level, name, productivity, etc... so could this be expanded upon in the same way?