Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* --- Pump --- */
- local pInPipe;
- local pOutPipe;
- local aMat; //0=Mat;1=Amount
- public func Timer()
- {
- //Energycheck
- //Pump is empty
- if ((aMat[1] == 0) || (aMat[0] == -1))
- {
- //Get new Mats
- aMat = pInPipe->GetLiquid(-1, 5, this);
- //No Material to pump
- if (aMat[1] == 0)
- return 0;
- }
- aMat[1] -= BoundBy(pOutPipe->PutLiquid(aMat[0], aMat[1], this), 0, aMat[1]);
- return 1;
- }
- /* --- LiquidPipe --- */
- //returns extracted mat + amount
- public func GetLiquid(int dnMat, int dnMaxAmount, object pPump)
- {
- var aMat;
- if (GetActionTarget(0) != pPump)
- aMat = GetActionTarget(0)->~LiquidOutput(dnMat, dnMaxAmount, pPump, this);
- else
- if (GetActionTarget(1) != pPump)
- aMat = GetActionTarget(1)->~LiquidOutput(dnMat, dnMaxAmount, pPump, this);
- if (GetType(aMat) != C4V_Array)
- return [-1, 0];
- if ((aMat[0] == -1) || (GetLength(aMat) == 1))
- aMat[1] = 0;
- if (aMat[1] < 0)
- aMat[0] = -1;
- return aMat;
- }
- //returns inserted mat amount
- public func PutLiquid(int dnMat, int dnMaxAmount, object pPump)
- {
- if (dnMat == -1)
- return 0;
- if (GetActionTarget(0) != pPump)
- return BoundBy(GetActionTarget(0)->~LiquidInput(dnMat, dnMaxAmount, pPump, this), 0, dnMaxAmount);
- else
- if (GetActionTarget(1) != pPump)
- return BoundBy(GetActionTarget(1)->~LiquidInput(dnMat, dnMaxAmount, pPump, this), 0, dnMaxAmount);
- return 0;
- }
- /* --- Sample Building (Tank/Reservoir) --- */
- local dMat;
- local dMatAmount;
- local dMatMaxAmount;
- //returns extracted mat + amount
- public func LiquidOutput(int dnMat, int dnMaxAmount, object pPump, object pPipe)
- {
- //Wrong material?
- if (dnMat == -1)
- dnMat = dMat;
- if ((dnMat != dMat) || (dMat == -1))
- dnMaxAmount = 0;
- dnMaxAmount = Min(dnMaxAmount, dMatAmount);
- dMatAmount -= dnMaxAmount;
- return [dMat, dnMaxAmount];
- }
- //returns inserted mat amount
- public func LiquidInput(int dnMat, int dnMaxAmount, object pPump, object pPipe)
- {
- if (dnMat != dMat)
- return 0;
- dnMaxAmount = Min(dMatMaxAmount - dMatAmount, dnMaxAmount);
- dMatAmount += dnMaxAmount;
- return dnMaxAmount;
- }
- /* --- Sample Building (Base/Barrelstorage)--- */
- //returns extracted mat + amount
- public func LiquidOutput(int dnMat, int dnMaxAmount, object pPump, object pPipe)
- {
- if (dnMat == -1)
- {
- var ptBarrel = FindObject(Find_Container(this), Find_Func("IsBarrel"), Find_Not(Find_Func("IsEmpty")));
- if (ptBarrel)
- dnMat = ptBarrel->GetBarrelMaterial(); //i don't know the real name...
- //Nothing to pump
- if (dnMat == -1)
- return [-1, 0];
- }
- var dtFound = 0;
- for (var ptBarrel in FindObjects(Find_Container(this), Find_Func("IsBarrel"), Find_Func("IsContainerForMaterial", dnMat)))
- {
- dtFound += BoundBy(ptBarrel->GetLiquid(dnMat, dnMaxAmount - dtFound, this), 0, dnMaxAmount);
- if (dtFound == dnMaxAmount)
- break;
- }
- return [dnMat, dtFound];
- }
- //returns inserted mat amount
- public func LiquidInput(int dnMat, int dnMaxAmount, object pPump, object pPipe)
- {
- var dtAmount = dnMaxAmount;
- for (var ptBarrel in FindObjects(Find_Container(this), Find_Func("IsBarrel"), Find_Func("IsContainerForMaterial", dnMat), Find_Not(Find_Func("IsFull"))))
- {
- dtAmount -= BoundBy(ptBarrel->PutLiquid(dnMat, dtAmount, this), 0, dtAmount);
- if (!dtAmount)
- return dnMaxAmount;
- }
- for (var ptBarrel in FindObjects(Find_Container(this), Find_Func("IsBarrel"), Find_ID(EmptyBarrel)))
- {
- dtAmount -= BoundBy(ptBarrel->PutLiquid(dnMat, dtAmount, this), 0, dtAmount);
- if (!dtAmount)
- return dnMaxAmount;
- }
- return dnMaxAmount - dtAmount;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement