Exemple #1
0
 public FactoryCommand(int currentTime, FactoryCommandType type, int amount, ChemicalSignature signature)
 {
     this.time      = currentTime;
     this.type      = type;
     this.amount    = amount;
     this.signature = signature;
 }
Exemple #2
0
 public SellerZone(ChemicalSignature signature, int sellPrice, FactoryCommandType sellAction, Vector2 pos, Vector2 size) : base(null, pos, size)
 {
     objectType      = PlatformObjectType.Trigger;
     this.signature  = signature;
     this.sellPrice  = sellPrice;
     this.sellAction = sellAction;
 }
Exemple #3
0
        void UpdateThreads()
        {
            int numThreads;

            if (commands.Count == 0)
            {
                numThreads = 0;
            }
            else
            {
                int coresPerRecording = (int)Math.Ceiling(commands.Last().time / (60.0f * TIME_PER_CORE));
                numThreads = (int)Math.Floor(numCores / (float)coresPerRecording);
                if (numThreads == 0)
                {
                    numThreads = 1;
                }
            }

            threads = new List <FactoryThread>(numThreads);
            for (int Idx = 0; Idx < numThreads; ++Idx)
            {
                threads.Add(new FactoryThread());
            }
            queuedOutput = null;

            CalcIncomePerLoop();
        }
Exemple #4
0
        public override void Run()
        {
            switch (state)
            {
            case CentrifugeState.EMPTY:
                ChemicalSignature newInputSig = PullInput();
                if (newInputSig != null)
                {
                    inputSignature  = newInputSig;
                    outputSignature = MakeRotation(mode, inputSignature);
                    state           = CentrifugeState.SPINNING;
                    timer           = 0;
                }
                break;

            case CentrifugeState.SPINNING:
                timer++;
                if (timer >= EMIT_TIMER)
                {
                    state = CentrifugeState.WAITING;
                }
                break;

            case CentrifugeState.WAITING:
                if (PushOutput(outputSignature))
                {
                    state = CentrifugeState.EMPTY;
                }
                break;
            }
        }
Exemple #5
0
 public override bool ReceiveInput(ChemicalSignature signature, ref string errorMessage)
 {
     if (this.signature == null)
     {
         this.signature = signature;
         amount         = 1;
         return(true);
     }
     else if (this.signature == signature)
     {
         if (amount < maxAmount)
         {
             amount++;
             return(true);
         }
         else
         {
             errorMessage = "Silo is full";
             return(false);
         }
     }
     else
     {
         errorMessage = "Wrong output chemical!";
         return(false);
     }
 }
Exemple #6
0
        public void DoOutput()
        {
            ChemicalSignature signature = GetSignature();

            DestroyAll();

            Game1.instance.platformLevel.ProduceChemical(signature);
            Game1.instance.platformLevel.UpdateAnyBlocksLeft();
        }
Exemple #7
0
 public Centrifuge(CityLevel cityLevel, JSONTable template) : base(
         cityLevel,
         TextureCache.centrifuge,
         template.getVector2("pos")
         )
 {
     this.inputSignature = new ChemicalSignature(template.getArray("chemical"));
     canDrag             = template.getBool("movable", true);
     Init();
 }
Exemple #8
0
        public ChemicalSignature SpawnInputChemical(int inputIndex)
        {
            ChemicalSignature signature = factory.GetInputChemical(inputIndex);

            if (signature != null)
            {
                recordedCommands.Add(new FactoryCommand(currentTime, FactoryCommandType.INPUT, inputIndex, signature));
            }
            return(signature);
        }
Exemple #9
0
 public ChemicalSilo(CityLevel cityLevel, JSONTable template) : base(
         cityLevel,
         TextureCache.silo,
         template.getVector2("pos"),
         TextureCache.silo.Size()
         )
 {
     this.signature = new ChemicalSignature(template.getArray("chemical"));
     canDrag        = template.getBool("movable", true);
     Init();
 }
Exemple #10
0
 public override bool ReceiveInput(ChemicalSignature signature, ref string errorMessage)
 {
     if (this.signature == signature)
     {
         Game1.instance.inventory.GainMoney(price, bounds.Center, cityLevel);
         didOutput = true;
         return(true);
     }
     else
     {
         errorMessage = "Wrong output chemical!";
         return(false);
     }
 }
Exemple #11
0
        public override ChemicalSignature RequestOutput(OutputPipe pipe, ref string errorMessage)
        {
            if (queuedOutput != null)
            {
                ChemicalSignature result = queuedOutput;
                queuedOutput = null;
                didOutput    = true;
                pipe.AnimatePip();
                return(result);
            }

            errorMessage = "Waiting for input";
            return(null);
        }
Exemple #12
0
 public override bool ReceiveInput(ChemicalSignature signature, ref string errorMessage)
 {
     if (this.signature == signature)
     {
         Game1.instance.inventory.GainCrystals(numCrystals);// bounds.Center);
         didOutput = true;
         return(true);
     }
     else
     {
         errorMessage = "Wrong output chemical!";
         return(false);
     }
 }
Exemple #13
0
        public static ChemicalSignature MakeRotation(CentrifugeMode mode, ChemicalSignature signature)
        {
            if (signature == null)
            {
                return(null);
            }

            switch (mode)
            {
            case CentrifugeMode.TurnRight: return(signature.Rotate());

            case CentrifugeMode.Turn180: return(signature.Rotate().Rotate());

            case CentrifugeMode.TurnLeft: return(signature.Rotate().Rotate().Rotate());

            default: throw new InvalidOperationException();
            }
        }
        public BuildingSite(CityLevel cityLevel, JSONTable template) : base(cityLevel, TextureCache.building_site, template.getVector2("pos"), TextureCache.building_site.Size())
        {
            this.price   = template.getInt("price");
            this.canDrag = false;

            JSONArray signatureTemplate = template.getArray("chemical", null);

            if (signatureTemplate != null)
            {
                this.signature = new ChemicalSignature(signatureTemplate);
                this.spawn     = new ChemicalInbox(cityLevel, signature, 0, bounds.XY);
            }
            else
            {
                this.spawn = CityObject.FromTemplate(cityLevel, template.getJSON("built"));
            }

            Init();
        }
Exemple #15
0
        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);
        }
Exemple #16
0
        public override ChemicalSignature GetOutputChemical()
        {
            if (outputSignature != null)
            {
                return(outputSignature);
            }

            foreach (OutputPipe pipe in pipeSocket.connectedPipes)
            {
                ChemicalSignature tryChemical = pipe.source.GetOutputChemical();
                if (tryChemical != null)
                {
                    outputSignature = tryChemical;
                    return(outputSignature);
                }
            }

            return(null);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        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);
        }
Exemple #19
0
        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);
        }
Exemple #20
0
        public override ChemicalSignature RequestOutput(OutputPipe pipe, ref string errorMessage)
        {
            if (amount > 0)
            {
                amount--;
                pipe.AnimatePip();
                return(signature);
            }

            foreach (OutputPipe pipe2 in pipeSocket.connectedPipes)
            {
                string            unused = "";
                ChemicalSignature result = pipe2.source.RequestOutput(pipe, ref unused);
                if (result != null)
                {
                    pipe.AnimatePip();
                    pipe2.AnimatePip();
                    return(result);
                }
            }

            errorMessage = "Silo is empty";
            return(null);
        }
Exemple #21
0
        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;
            }
        }
Exemple #22
0
        public void ProduceChemical(ChemicalSignature signature)
        {
            recordedCommands.Add(new FactoryCommand(currentTime, FactoryCommandType.OUTPUT, signature));

//            factory.PushOutput(signature);
        }
Exemple #23
0
 public override bool ReceiveInput(ChemicalSignature signature, ref string errorMessage)
 {
     errorMessage = "Waiting for output";
     return(false);
 }
Exemple #24
0
 void UpdateOutputSignature()
 {
     outputSignature = MakeRotation(mode, inputSignature);
 }
        public void Update(List <PlatformObject> objects)
        {
            if (!triggered)
            {
                return;
            }

            foreach (PlatformObject obj in objects)
            {
                if (obj.bounds.Intersects(bounds))
                {
                    return;
                }
            }

            ChemicalSignature signature = Game1.instance.platformLevel.SpawnInputChemical(inputIndex);

            if (signature == null)
            {
                return;
            }

            triggered = false;

            int height = signature.height;
            int width  = signature.width;

            float startX = bounds.CenterX - width * 32 / 2;
            float startY = bounds.CenterY - height * 32 / 2;
            float curX   = startX;
            float curY   = startY;

            ChemBlock[,] blocksSpawned = new ChemBlock[width, height];

            for (int col = 0; col < width; ++col)
            {
                for (int row = 0; row < height; ++row)
                {
                    ChemicalElement c = signature[col, row];
                    if (c != ChemicalElement.NONE)
                    {
                        ChemBlock newBlock = new ChemBlock(c, c.ToTexture(false), new Vector2(curX, curY), new Vector2(32, 32), c.ToColor());
                        objects.Add(newBlock);

                        blocksSpawned[col, row] = newBlock;

                        if (col > 0 && blocksSpawned[col - 1, row] != null)
                        {
                            blocksSpawned[col - 1, row].NailOnto(newBlock);
                        }

                        if (row > 0 && blocksSpawned[col, row - 1] != null)
                        {
                            blocksSpawned[col, row - 1].NailOnto(newBlock);
                        }
                    }

                    curY += 32.5f;
                }

                curX += 32.5f;
                curY  = startY;

                Game1.instance.platformLevel.UpdateAnyBlocksLeft();
            }
        }
Exemple #26
0
 public ChemicalOutbox(CityLevel cityLevel, ChemicalSignature signature, int price, Vector2 pos) : base(cityLevel, TextureCache.outbox, pos, TextureCache.outbox.Size())
 {
     this.signature = signature;
     this.price     = price;
     Init();
 }
Exemple #27
0
 public ChemicalOutbox(CityLevel cityLevel, JSONTable template) : base(cityLevel, TextureCache.outbox, template.getVector2("pos"), TextureCache.outbox.Size())
 {
     this.signature = new ChemicalSignature(template.getArray("chemical"));
     this.price     = template.getInt("price");
     Init();
 }
Exemple #28
0
 public OutputZone(ChemicalSignature signature, ChemicalSignature signature2, Vector2 pos, Vector2 size) : base(null, pos, size)
 {
     objectType      = PlatformObjectType.Trigger;
     this.signature  = signature;
     this.signature2 = signature2;
 }
Exemple #29
0
 public virtual bool ReceiveInput(ChemicalSignature signature, ref string errorMessage)
 {
     return(false);
 }
Exemple #30
0
 public ChemicalSilo(CityLevel cityLevel, ChemicalSignature signature, int amount, Vector2 pos) : base(cityLevel, TextureCache.silo, pos, TextureCache.silo.Size())
 {
     this.signature = signature;
     this.amount    = amount;
     Init();
 }