khaibar Advanced
Joined: 14 Dec 2007 Posts: 1145
|
Posted: Sat Sep 14, 2013 3:42 am Post subject: One click mod building {frizz plz read} |
|
|
Frizz is currently working on a one button click for units that involves a new class or something.
I remember him saying someone has to do it for mods. I am trying a simpler approach which is a one time generation of a new xml file that includes
- Mod id
- Mod ore
- Mod command
- Mod reqs
- Mod clicks
The required resources are calculated at maximum efficiency. Thus when someone attempts to build, he must have maximum efficiency on all prereqs and sub-prereqs to use this option. This is for coding simplicity and well I don't think anyone is going to build 100 gyros if one of it's prereqs isn't at 100%.
The faction mod ore discount was not calculated, it can be deducted from total ore, error margin is maximum of number of clicks ore which is acceptable. Or a new field can be added, mod ore discounted.
The code is not needed since it's a one time generation but I will give it for frizz or anyone to check
Code: | <?php
function xmltomods($source)
{
$oneclick = array();
$tmpids = array();
$tmpmod = array();
$expansions = array("","BT","B","XP","SW","F","CD");
$data = simplexml_load_file($source);
foreach($expansions as $expansion)
{
foreach($data->mod as $mod)
{
if( ($mod->needtobuild->Mod =="") AND ($mod->Expansion == $expansion ) )
{
$mod->clicks = 1;
$mod->needtobuild->Ore = ceil(0.5*$mod->needtobuild->Ore);
$mod->needtobuild->Command = ceil(0.5*$mod->needtobuild->Command);
$oneclick[intval($mod->Id)] = $mod;
$tmpids[] = $mod->Id;
}
}
do {
$alladded = true;
foreach($data->mod as $mod)
{
if(in_array($mod->Id,$tmpids))
continue;
if( ($mod->Expansion == $expansion ) AND ($mod->needtobuild->Mod !="") )
{
$canadd = true;
$mods = explode(",",$mod->needtobuild->Mod);
$tmpore = 0;
$tmpcommand = 0;
$tmpreq = "";
$tmpclicks = 1;
foreach($mods as $req)
{
if(strstr($req,"x"))
continue;
if(!in_array($req,$tmpids))
{
$alladded = false;
$canadd = false;
break;
}
$tmpore += $oneclick[$req]->needtobuild->Ore;
$tmpcommand += $oneclick[$req]->needtobuild->Command;
$tmpclicks += $oneclick[$req]->clicks;
if($oneclick[$req]->needtobuild->Mod)
{
if($tmpreq == "")
$tmpreq = $oneclick[$req]->needtobuild->Mod;
else
$tmpreq .=",".$oneclick[$req]->needtobuild->Mod;
}
}
if($canadd)
{
$tmpids[] = $mod->Id;
$mod->needtobuild->Ore = ceil(0.5*$mod->needtobuild->Ore) + $tmpore;
$mod->needtobuild->Command = ceil(0.5*$mod->needtobuild->Command) + $tmpcommand;
$mod->clicks = $tmpclicks;
$oneclick[intval($mod->Id)] = $mod;
if($tmpreq)
$tmpmod[intval($mod->Id)] = $mod->needtobuild->Mod.",".$tmpreq;
else
$tmpmod[intval($mod->Id)] = $mod->needtobuild->Mod;
}
}
}
} while(!$alladded);
}
foreach($oneclick as $mod)
{
if(isset($tmpmod[intval($mod->Id)]))
$mod->needtobuild->Mod = $tmpmod[intval($mod->Id)];
$tmpunique = explode(",",$mod->needtobuild->Mod);
$tmpunique = array_filter(array_unique($tmpunique));
$mod->needtobuild->Mod = implode(",",$tmpunique);
echo "Name: ".$mod->Name."<br>";
echo "ID: ".$mod->Id."<br>";
echo "Ore: ".$mod->needtobuild->Ore."<br>";
echo "Command: ".$mod->needtobuild->Command."<br>";
if($mod->needtobuild->Mod != "")
echo "Req: ".$mod->needtobuild->Mod."<br>";
echo "Clicks: ".$mod->clicks."<br><br>";
}
}
?> |
Samples of the output
Code: | Name: Compressed Cobalt Plating
ID: 170
Ore: 200
Command: 2
Req: 133
Clicks: 2
Name: Proton Mass Generator
ID: 171
Ore: 200
Command: 2
Req: 130
Clicks: 2
Name: EMP Missiles
ID: 172
Ore: 1483
Command: 19
Req: 116,171,108,53,59,130
Clicks: 12
Name: EMP Ammunition
ID: 173
Ore: 1368
Command: 21
Req: 139,108,55,57,61,63
Clicks: 13
Name: Cluster Missiles
ID: 174
Ore: 815
Command: 14
Req: 58,127,54,59
Clicks: 8
Name: Gyrojet Rounds
ID: 175
Ore: 835
Command: 13
Req: 55,132,37,15,129
Clicks: 7
Name: Cluster Missile Pod
ID: 177
Ore: 1315
Command: 20
Req: 174,127,170,58,133
Clicks: 12
Name: Chimera Power Converter
ID: 168
Ore: 675
Command: 8
Req: 171,137,130,136
Clicks: 5
Name: Argus Energy Adaptor
ID: 169
Ore: 725
Command: 9
Req: 170,122,133,121
Clicks: 5
Name: Gyrojet Long-gun
ID: 176
Ore: 1685
Command: 23
Req: 175,168,55,132,171,137
Clicks: 13
Name: Tremor Sensors
ID: 178
Ore: 2275
Command: 27
Req: 168,169,138,137,171,170,122,82,64,136
Clicks: 16
Name: Obliteration Cannon
ID: 167
Ore: 3416
Command: 44
Req: 114,109,169,110,111,108,85,63,170,122
Clicks: 31 |
Someone please double check some of these if you can build them at full efficiency. If you have the ore discount faction bonus, reduce the ore price above by 25%.
Frizz please tell me if this approach is acceptable and needed so that I can generate the xml file and modify the construct files to handle the new format as well as the old one. |
|