public void ConnectTo(PipeSocket newSocket) { if ((newSocket == null || newSocket.parent != source) && connectedTo != newSocket) { PipeSocket oldConnection = connectedTo; connectedTo = newSocket; if (oldConnection != null) { oldConnection.RemoveConnection(this); } if (newSocket != null) { if (!newSocket.AddConnection(this)) { connectedTo = null; ShowDisconnected(); } } else { ShowDisconnected(); } source.UpdatePipes(); } }
public bool PushOutput(ChemicalSignature signature) { foreach (OutputPipe pipe in pipes) { PipeSocket socket = pipe.connectedTo; if (socket != null) { string errorMessage = ""; if (socket.parent.ReceiveInput(signature, ref errorMessage)) { pipe.AnimatePip(); didOutput = true; return(true); } } } return(false); }
public bool PushOutput(ChemicalSignature signature, ref string errorMessage) { foreach (OutputPipe pipe in pipes) { PipeSocket socket = pipe.connectedTo; if (socket != null) { if (queuedOutput != null) { if (socket.parent.ReceiveInput(queuedOutput, ref errorMessage)) { pipe.AnimatePip(); didOutput = true; queuedOutput = null; } else { return(false); } } if (socket.parent.ReceiveInput(signature, ref errorMessage)) { pipe.AnimatePip(); didOutput = true; return(true); } } } // failed to output - try to queue it if (queuedOutput != null) { errorMessage = "Output not connected"; return(false); } queuedOutput = signature; return(true); }
void CalcIncomePerLoop() { incomePerLoop = 0; foreach (FactoryCommand command in commands) { // for each command, iterate through all inputs and outputs, determine money spent/received // add up switch (command.type) { case FactoryCommandType.EARNMONEY: incomePerLoop += command.amount; break; case FactoryCommandType.INPUT: { PipeSocket socket = command.amount == 0 ? leftSocket : rightSocket; foreach (OutputPipe pipe in socket.connectedPipes) { if (pipe.source.GetOutputChemical() == command.signature) { incomePerLoop -= pipe.source.outputPrice; break; } } } break; case FactoryCommandType.OUTPUT: foreach (OutputPipe pipe in pipes) { if (pipe.connectedTo != null && pipe.connectedTo.parent.GetInputChemical() == command.signature) { incomePerLoop += pipe.connectedTo.parent.inputPrice; break; } } break; } } }
public ChemicalSignature GetInputChemical(int inputIndex) { PipeSocket socket = inputIndex == 0 ? leftSocket : rightSocket; foreach (OutputPipe pipe in socket.connectedPipes) { if (pipe == null || pipe.source == null) { continue; } ChemicalSignature signature = pipe.source.GetOutputChemical(); if (signature == null) { continue; } return(signature); } return(null); }
public ChemicalSignature ConsumeInput(int inputIndex, ChemicalSignature specificInput, ref string errorMessage) { OutputPipe pipe = null; PipeSocket socket = inputIndex == 0 ? leftSocket : rightSocket; foreach (OutputPipe currentPipe in socket.connectedPipes) { if (currentPipe.source.GetOutputChemical() == specificInput) { pipe = currentPipe; break; } } if (pipe == null) { errorMessage = "Input not connected"; return(null); } ChemicalSignature signature = pipe.source.RequestOutput(pipe, ref errorMessage); return(signature); }
void InitPipes() { numCores = DEFAULT_NUM_CORES; ui = new UIContainer(bounds.XY); ui.Add(new UIButton("Record", TextureCache.record_icon, new Rectangle(((int)bounds.Width - 90) / 2, (int)bounds.Height + 5, 90, 35), Game1.buttonStyle, button_Play)); leftSocket = new PipeSocket(this, new Vector2(14, 14), 1); if (canDrag) { rightSocket = new PipeSocket(this, new Vector2(32, 14), 1); } if (isBigFactory) { AddOutputPipe(new Vector2(-6, 36)); AddOutputPipe(new Vector2(53, 36)); } else { AddOutputPipe(new Vector2(15, 39)); } //unlimitedPipes = canDrag; }
public void Update(CityLevel metaGame, CityUIBlackboard blackboard) { if (!movable) { return; } hovering = blackboard.inputState.hoveringElement == this;// cachedHandleRect.Contains(blackboard.inputState.MousePos); if (hovering && blackboard.inputState.WasMouseLeftJustPressed()) { dragging = true; blackboard.selectedObject = null; } if (cachedOffset.Y < 0) { ConnectTo(null); } if (dragging) { ConnectTo(null); CityObject overObject = metaGame.GetObjectAt(blackboard.inputState.MousePos); PipeSocket overSocket = null; if (overObject != null) { overSocket = overObject.GetNearestSocket(blackboard.inputState.MousePos); if (overSocket != null && overSocket.pos.Y < sourcePos.Y) { overSocket = null; } } Vector2 clampedPos = blackboard.inputState.MousePos; if (clampedPos.Y <= sourcePos.Y) { clampedPos.Y = sourcePos.Y; } if (blackboard.inputState.mouseLeft.isDown) { if (overSocket != null) { UpdateForTargetPos(overSocket.pos); } else { UpdateForTargetPos(clampedPos); } } else { dragging = false; if (overSocket != null && overSocket.parent != source) { ConnectTo(overSocket); } else { ShowDisconnected(); } } } }
void InitObjects() { Vector2 playerPos = new Vector2(50, 200); if (player != null) { playerPos = player.bounds.XY; } objects = new List <PlatformObject>(); triggerables = new List <Command>(); isDoubleFactory = (factory.rightSocket != null && factory.rightSocket.connectedPipes.Count > 0); isBigFactory = factory.isBigFactory; if (isBigFactory) { objects.Add(new PlatformObject(TextureCache.cement, new Vector2(-16, 0), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(-16, 128), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(-16, 256), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(-16, 384), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(550, 0), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(550, 128), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(550, 256), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(550, 384), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(187 - 32, 272), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(187 - 32, 400), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.woodFloor, new Vector2(187, 272), new Vector2(192, 32))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(187 + 192, 272), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(187 + 192, 400), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.buttonHood, new Vector2(0, 64), new Vector2(32, 32))); //objects.Add(new PlatformObject(TextureCache.cement_dark, new Vector2(187-32, 230), new Vector2(128, 42), Color.White, PlatformObjectType.JumpThrough)); Command_Spawn spawner = new Command_Spawn(new Vectangle(250, -36, 78, 32), factory, 0); triggerables.Add(spawner); objects.Add(new PushButton(spawner, TextureCache.clear, TextureCache.white, new Vector2(16, 96), new Vector2(8, 32), Color.Red)); if (isDoubleFactory) { objects.Add(new PlatformObject(TextureCache.buttonHood, new Vector2(550 - 16, 64), new Vector2(32, 32))); Command_Spawn spawner2 = new Command_Spawn(new Vectangle(256, -36, 78, 32), factory, 1); triggerables.Add(spawner2); objects.Add(new PushButton(spawner2, TextureCache.clear, TextureCache.white, new Vector2(550 - 8, 96), new Vector2(8, 32), Color.Red)); } ChemicalSignature outputChemical1 = null; ChemicalSignature outputChemical2 = null; bool setOutput1 = true; foreach (OutputPipe pipe in factory.pipes) { PipeSocket receiver = pipe.connectedTo; if (setOutput1) { if (receiver != null) { outputChemical1 = receiver.parent.GetInputChemical(); } setOutput1 = false; } else { if (receiver != null) { outputChemical2 = receiver.parent.GetInputChemical(); } break; } } objects.Add(new OutputZone(outputChemical1, null, new Vector2(32, 400), new Vector2(155, 32))); objects.Add(new OutputZone(outputChemical2, null, new Vector2(187 + 192 + 32, 400), new Vector2(155, 32))); saveButton.frame = new Rectangle(185, 302, 100, 40); } else { objects.Add(new PlatformObject(TextureCache.cement, new Vector2(-16, 0), new Vector2(32, 136))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(0, 136), new Vector2(32, 136))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(400, 0), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(400, 128), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(400, 256), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(400, 384), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.buttonHood, new Vector2(16, 204), new Vector2(32, 32))); objects.Add(new PlatformObject(TextureCache.woodFloor, new Vector2(0, 272), new Vector2(192, 32))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(192, 272), new Vector2(32, 128))); objects.Add(new PlatformObject(TextureCache.cement, new Vector2(192, 400), new Vector2(32, 128))); if (factory.internalSeller != null) { objects.Add(new SellerZone(factory.internalSeller, factory.sellerPrice, factory.sellerAction, new Vector2(192, 300), new Vector2(160, 32))); } else { //ChemicalSignature inputChemical = new ChemicalSignature(2, new ChemicalElement[] { ChemicalElement.WHITE, ChemicalElement.GREEN }); ChemicalSignature outputChemical = null; ChemicalSignature outputChemical2 = null; foreach (OutputPipe pipe in factory.pipes) { PipeSocket receiver = pipe.connectedTo; if (receiver != null) { if (outputChemical == null) { outputChemical = receiver.parent.GetInputChemical(); } else { outputChemical2 = receiver.parent.GetInputChemical(); break; } } } objects.Add(new OutputZone(outputChemical, outputChemical2, new Vector2(192, 300), new Vector2(192, 32))); } Command_Spawn spawner = new Command_Spawn(new Vectangle(92, -36, 78, 32), factory, 0); triggerables.Add(spawner); objects.Add(new PushButton(spawner, TextureCache.clear, TextureCache.white, new Vector2(32, 240), new Vector2(8, 32), Color.Red)); if (isDoubleFactory) { objects.Add(new PlatformObject(TextureCache.buttonHood, new Vector2(382, 28), new Vector2(32, 32))); objects.Add(new PlatformObject(TextureCache.woodFloor, new Vector2(192, 96), new Vector2(208, 32))); Command_Spawn spawner2 = new Command_Spawn(new Vectangle(256, -36, 78, 32), factory, 1); triggerables.Add(spawner2); objects.Add(new PushButton(spawner2, TextureCache.clear, TextureCache.white, new Vector2(400 - 8, 64), new Vector2(8, 32), Color.Red)); } saveButton.frame = new Rectangle(10, 302, 100, 40); } player = new PlatformCharacter(TextureCache.character, playerPos, new Vector2(14, 32), Color.White, new Rectangle(9, 0, 14, 32)); objects.Add(player); //weaponButtons.selectedButton = rivetGunButton; projectiles = new List <Projectile>(); paused = false; recordedCommands.Clear(); currentTime = 0; UpdateAnyBlocksLeft(); /* if (rightSlotUI != null && Game1.instance.inventory.rightWeapon.weapon != null) * { * ui.Add(rightSlotUI); * rightSlotUI = null; * }*/ if (Game1.instance.inventory.newWeaponAdded) { Game1.instance.splashes.Add(new Splash("NEW WEAPON", TextAlignment.CENTER, Game1.font, Color.Orange, new Vector2(600, 425), new Vector2(0, -5), 0.90f, 0, 2)); Game1.instance.inventory.newWeaponAdded = false; } weaponSlots.Clear(); Rectangle currentRect = new Rectangle(600, 425, 175, 50); int WEAPON_SPACING = 55; currentRect.Y -= Game1.instance.inventory.availableWeapons.Count * WEAPON_SPACING; foreach (Weapon w in Game1.instance.inventory.availableWeapons) { weaponSlots.Add(new UIWeaponButton(w, Game1.instance.inventory.leftWeapon, Game1.instance.inventory.rightWeapon, currentRect, weaponButtonStyle)); currentRect.Y += WEAPON_SPACING; } }
public void SetPipeSocket(Vector2 offset, Vector2 offset2) { pipeSocket = new PipeSocket(this, offset, offset2); }
public void SetPipeSocket(Vector2 offset, int maxConnections) { pipeSocket = new PipeSocket(this, offset, maxConnections); }