% % Load Minerals for Fighter / Torpedo Building % % This provides a ship command `LoadForBuild' that will load the amount % of minerals for building that ship's ammunition. % % You'll be prompted for the number of torps/fighters you want. The % input line will be pre-initialized with the maximum number this % script thinks is possible. Enter the desired amount and hit Enter. % % + 14/Jul/2002 by Stefan Reuther % + 10/Aug/2002 refuse to run on freighters % + 14/Jan/2005 added ability to load arbitrary type (for suppliers). % This is not on a key, use 'LoadForBuild 0,1' to call it. % % Needs PCC 1.0.18 or above. % Print "[load.q 14/Jan/2005]" Sub LoadForBuild (Optional pAmount, pAsk) Local lCost, lMass, lMC, UI.Result, Cargo.Remainder, lType, lName, i If Not Orbit$ Or (Planet(Orbit$).Owner$<>Owner$) Then MessageBox "We're not orbiting one of our planets." Return EndIf If pAsk Then With Listbox("Cargo Type") Do For i:=1 To 10 Do AddItem i, Torpedo(i).Name AddItem 11, "Fighter" Run EndWith If IsEmpty(UI.Result) Then Return lType := UI.Result If lType <= 10 Then lName := Torpedo(lType).Name.Short Else lName := 'Ftr' EndIf Else If IsEmpty(Z(Aux$)) Then MessageBox 'This ship does not have secondary weapons.' Return EndIf lType := Aux$ lName := Aux.Short EndIf If lType=11 Then % Fighters lCost := '3t 2m 5s' lMass := 10 Else % Torps lCost := Torpedo(lType).Cost.Str lMass := 3 EndIf lMC := CExtract(lCost, '$') % FIXME: we assume here that we don't need supplies AND megacredits at the same time Local lAmount := Cargo.Free \ lMass If lMC Then lAmount := Min(lAmount, Min((10000 - Cargo.Money), Planet(Orbit$).Money + Planet(Orbit$).Supplies) \ lMC) If CExtract(lCost, 't') Then lAmount := Min(lAmount, Planet(Orbit$).Mined.T \ CExtract(lCost, 't')) If CExtract(lCost, 'd') Then lAmount := Min(lAmount, Planet(Orbit$).Mined.D \ CExtract(lCost, 'd')) If CExtract(lCost, 'm') Then lAmount := Min(lAmount, Planet(Orbit$).Mined.M \ CExtract(lCost, 'm')) If CExtract(lCost, 's') Then lAmount := Min(lAmount, Planet(Orbit$).Supplies \ CExtract(lCost, 's')) If Not IsEmpty(pAmount) And pAmount<>0 Then UI.Result := Str(pAmount) Else UI.Input "Count:", "Load Mineral for " & lName, 5, "n", lAmount EndIf If UI.Result Then CargoUpload CMul(lCost, Val(UI.Result)), "n" If Cargo.Remainder And Not CRemove(Cargo.Remainder, '$') Then CargoUpload CExtract(Cargo.Remainder, '$') & 's', "ns" If Cargo.Remainder Then MessageBox "Note: " & CExtract(Cargo.Remainder, 's') & ' mc did not fit on the ship." Else If Cargo.Remainder Then MessageBox "Note: " & Cargo.Remainder & " did not fit on the ship." EndIf EndIf EndSub Bind ShipScreen 'c-c' := 'LoadForBuild UI.Prefix'