Files
EscapistsReintroduced/docs/evidence/recovery-launcher-2026-10-02/launcher/supplement.py
T
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

46 lines
4.1 KiB
Python

from pathlib import Path
P=Path('/tmp/erri-launcher-resupply-1140');d=P/'addons/core/Scripts/Game/ERR/10_AI'
p=d/'ERR_InfantryAmmoTransfer.c';s=p.read_text().replace('if (!StoredUnder(loaded.GetOwner(), rifle)) continue;', '''InventoryItemComponent loadedItem = InventoryItemComponent.Cast(loaded.GetOwner().FindComponent(InventoryItemComponent));
if (!loadedItem || !loadedItem.GetParentSlot()) continue;
InventoryStorageSlot loadedSlot = loadedItem.GetParentSlot();
if (loadedSlot.GetParentContainer() != muzzle || loadedSlot.GetAttachedEntity() != loaded.GetOwner()) continue;''');p.write_text(s)
p=d/'ERR_InfantryResupply.c';s=p.read_text().replace(' else foreach (IEntity magazine : m_Stock)', ' else if (launcherTrip) available = LauncherStock(recipient);\n else foreach (IEntity magazine : m_Stock)')
s=s.replace(' bool TryPlanLauncher(',''' // Compatibility-only preflight of original own carriers; HQ still uses the
// delivered report for demand and positions. No item is reserved or moved here.
protected bool LauncherStock(ERR_HQUnit recipient)
{
if (!recipient || !recipient.StatusSampler || m_Stock.Count() > 96) return false;
int strength = recipient.StatusSampler.InitialStrength();
if (strength < 1 || strength > 32) return false;
int checks;
foreach (IEntity magazine : m_Stock)
{
if (!magazine || m_Spent.Contains(magazine) || !Contains(m_Truck.Entity, magazine)) continue;
for (int slot = 0; slot < strength; slot++)
{
if (++checks > 128) return false;
IEntity actor = recipient.StatusSampler.InitialMember(slot);
if (!actor || !recipient.StatusSampler.CanAttribute(slot, actor) || !ERR_Actors.CanFight(actor)) continue;
if (ERR_InfantryAmmoTransfer.Compatible(actor, magazine, true)) return true;
}
}
return false;
}
bool TryPlanLauncher(''');p.write_text(s)
p=P/'tests/test_infantry_ammo_transfer.py';s=p.read_text().replace("'BaseMagazineComponent.Cast(exactMagazine.FindComponent(BaseMagazineComponent))':", "'InventoryItemComponent.Cast(loaded.GetOwner().FindComponent(InventoryItemComponent))':'loaded->GetOwner()->item',\n 'BaseMagazineComponent.Cast(exactMagazine.FindComponent(BaseMagazineComponent))':")
s=s.replace("'magazine','loaded','manager'", "'magazine','loaded','loadedItem','loadedSlot','manager'")
s=s.replace('using InventoryStorageManagerComponent=Inventory*;', 'using InventoryStorageSlot=Slot*;using InventoryStorageManagerComponent=Inventory*;')
s=s.replace('struct Slot{Storage*storage=nullptr;IEntity occupant=nullptr;', 'struct Slot{Storage*storage=nullptr;IEntity occupant=nullptr;Muzzle*container=nullptr;IEntity attached=nullptr;Muzzle*GetParentContainer(){return container;}IEntity GetAttachedEntity(){return attached;}')
s=s.replace('struct LauncherFixture:SupplyFixture{Entity loaded;Magazine empty;', 'struct LauncherFixture:SupplyFixture{Entity loaded;Magazine empty;Item loadedItem;Slot loadedSlot;')
s=s.replace('empty.rounds=0;muzzle.loaded=&empty;', 'empty.rounds=0;muzzle.loaded=&empty;loaded.item=&loadedItem;loadedItem.slot=&loadedSlot;loadedSlot.container=&muzzle;loadedSlot.attached=&loaded;')
s=s.replace('if(bad==4)f.loaded.parent=nullptr;', 'if(bad==4)f.loadedSlot.attached=nullptr;')
p.write_text(s)
p=P/'tests/test_infantry_resupply_planning.py';s=p.read_text().replace("'bool TryPlanLauncher(',", "'protected bool LauncherStock(', 'bool TryPlanLauncher(',")
s=s.replace("'ERR_InfantryMineTransfer','ERR_ConvoyRules'", "'ERR_InfantryMineTransfer','ERR_InfantryAmmoTransfer','ERR_ConvoyRules'")
s=s.replace("s=s.replace('bool available;'", "s=s.replace('int checks;', 'int checks=0;')\n s=s.replace('bool available;'")
s=s.replace('struct Service{', 'struct ERR_InfantryAmmoTransfer{static inline bool compatible=true;static bool Compatible(IEntity actor,IEntity item,bool launcher){return actor&&item&&launcher&&compatible;}};\nstruct Service{')
s=s.replace('int main(){', '''int main(){
{Fixture f;f.s.Stock(0);ERR_InfantryAmmoTransfer::compatible=false;assert(!f.s.TryPlanLauncher(&f.recipient,&f.donor,&f.demand,&f.donorStatus,0)&&f.truck.SupplyToken==0);ERR_InfantryAmmoTransfer::compatible=true;}
''')
p.write_text(s)