Ejemplo n.º 1
0
        public void Sim200ms(float dt)
        {
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("sent_joules", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, deal with it
                int spare = (int)message["spare"];
                if ((outstanding_joules - spare) > 0)
                {
                    this.battery.ConsumeEnergy(outstanding_joules - spare);
                }
                outstanding        = false;
                outstanding_joules = 0;
            }
            // Only send messages to the server if we are actually enabled
            if (!outstanding && ztransporter.is_enabled_and_linked())
            {
                // We are not currently waiting for a message
                // so make a message, and then wait for response
                int int_joules_to_send = (int)this.battery.JoulesAvailable;
                if (int_joules_to_send > 0)
                {
                    outstanding_joules = int_joules_to_send;
                    message            = Network.make_message("send_joules", x, y);
                    message["joules"]  = int_joules_to_send;
                    Z.net.send_message(message);
                    outstanding = true;
                }
            }
        }
Ejemplo n.º 2
0
        public void Sim1000ms(float dt)
        {
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("got_object", x, y);

            if (outstanding && message != null)
            {
                outstanding = false;
                // We have a response from the server, finally ya lazy basterd
                if (message["object"] != null &&
                    message["object"].Type == JTokenType.String)
                {
                    GameObject opaque_object = convert_to_gameobject((string)message["object"]);
                    storage.Store(opaque_object); // Note: We are not *adding*
                                                  // we are *storing*
                }
            }
            // Only send when we are enabled
            if (!outstanding && !storage.IsFull() && ztransporter.is_enabled())
            {
                // Send a message to the server asking for an object

                message = Network.make_message("recv_object", x, y);
                Z.net.send_message(message);
                outstanding = true;
            }

            return;
        }
Ejemplo n.º 3
0
        #pragma warning restore 0649

        public override void EnergySim200ms(float dt)
        {
            base.EnergySim200ms(dt);
            //this.AssignJoulesAvailable(Math.Min(this.JoulesAvailable, this.WattageRating * dt));

            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("got_joules", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, check it out

                // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -SB
                int amount_to_add = (int)message["joules"];
                if (amount_to_add > 0)
                {
                    this.GenerateJoules(amount_to_add, true);
                }
                // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa. -SB
                outstanding = false;
            }
            // Only send a message if we need to, AND the building has not been
            // disabled
            if (!outstanding && ztransporter.is_enabled())
            {
                // Time to make a message to send to the server
                int amount_to_request = (int)(this.Capacity - this.JoulesAvailable);
                if (amount_to_request > 0)
                {
                    message = Network.make_message("recv_joules", x, y);
                    message["max_joules"] = amount_to_request;
                    Z.net.send_message(message);
                    outstanding = true;
                }
            }
        }
Ejemplo n.º 4
0
        public void Sim1000ms(float dt)
        {
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            // Buffer five objects to send, that way you dont only get
            // 20g (or whatever) per second
            if (autoSend && (objects.Count <= 5))
            {
                add_to_object_list();
            }

            JObject message = Z.net.get_message_for("sent_object", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, deal with it
                if ((bool)message["accepted"])
                {
                    objects.RemoveAt(0);
                }
                outstanding = false;
            }
            // Only send message when enabled, you know the rest
            if (!outstanding && objects.Count != 0 && ztransporter.is_enabled_and_linked())
            {
                // We are not currently waiting for a message
                // so make a message, and then wait for response
                message = Network.make_message("send_object", x, y);
                String object_to_send = objects[0];
                message["object"] = object_to_send;
                // We need to (re)send the current message to the server
                Z.net.send_message(message);
                outstanding = true;
            }
        }
Ejemplo n.º 5
0
        public void Dispense(float dt)
        {
            // Because of how complex materials, we are NOT going to only
            // use the internal buffer of the tank/whatever.
            // As soon as we get a suitable element to send, we are going to
            // cache it in a special buffer, and that buffer has these rules:
            //  1. There can only EVER be one thing buffered at a time
            //  2. Any thing that enters the buffer MUST exit
            //     by being sent to the server, it cannot use any other way
            // using these two simple rules, that should prevent a lot of
            // possible exploits from happening, like asking the server to
            // take 500g of 21 degree temperture, and then having it rise by
            // 5 degrees while waiting for a response, and this having
            // the 5 degrees destroyed
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("sent_packet", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, deal with it
                if ((bool)message["accepted"])
                {
                    buffered = null; // Message sent and received, KILL IT
                }
                outstanding = false;
            }
            // Only make and send a message if we are enabled
            if (!outstanding && ztransporter.is_enabled_and_linked())
            {
                // We are not currently waiting for a message
                // so make a message (if necessary), and then wait for response

                if (buffered == null)
                {
                    // We need to remove some of the primary element, make a
                    // message out of it and then send that to the sever

                    PrimaryElement suitableElement
                        = this.FindSuitableElement();
                    // If the suitableElement returned is null, then we
                    // don't have any suitable elements in our storage,
                    // so skip this whole section
                    if (suitableElement != null)
                    {
                        suitableElement.KeepZeroMassObject = false;
                        message          = Network.make_message("send_packet", x, y);
                        message["phase"] = (this.isGas ? "Gas" : "Liquid");
                        message["packet"]
                            = convert_from_primary(suitableElement);

                        buffered = message;
                    }
                }
                if (buffered != null)
                {
                    // We need to (re)send the current message to the server
                    Z.net.send_message(buffered);
                    outstanding = true;
                }
            }
        }
Ejemplo n.º 6
0
        private PrimaryElement FindSuitableElement()
        {
            PrimaryElement ret = null;
            // Maybe make it buffer an extra message, that might help?

            // better version: grab stuff from our ass, I mean network - BR

            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("got_packet", x, y);

            if (outstanding && message != null)
            {
                outstanding = false;
                // We have a response from the server, finally ya lazy basterd
                if (message["packet"] != null &&
                    message["packet"].Type == JTokenType.Object)
                {
                    JObject mat_packet  = (JObject)message["packet"];
                    JObject germ_packet = null;
                    if (mat_packet["germs"] != null &&
                        mat_packet["germs"].Type == JTokenType.Object)
                    {
                        germ_packet = (JObject)mat_packet["germs"];
                    }
                    if (dave == null)
                    {
                        dave = GasSourceManager.Instance.CreateChunk(
                            (SimHashes)(-1528777920), 0f, 456f,
                            255, 0, this.transform.GetPosition());
                        steve = dave.GetComponent <PrimaryElement>();
                        steve.KeepZeroMassObject = true;
                    }
                    steve.SetElement((SimHashes)((int)mat_packet["element"]));
                    steve.SetMassTemperature((float)mat_packet["mass"],
                                             (float)mat_packet["temperature"]);
                    string reason = conduitType == ConduitType.Liquid
                        ? "Storage.AddLiquid" : "Storage.AddGasChunk";
                    steve.ModifyDiseaseCount(-steve.DiseaseCount, reason);
                    if (germ_packet != null)
                    {
                        steve.AddDisease((byte)germ_packet["id"],
                                         (int)germ_packet["count"],
                                         reason);
                    }

                    message = null;

                    ret = steve;
                }
            }
            // Only ask for goodies when we are enabled
            if (!outstanding && ztransporter.is_enabled())
            {
                // Send a message to the server asking for goodies

                message = Network.make_message("recv_packet", x, y);
                message.Add("phase", this.conduitType == ConduitType.Liquid ?
                            "Liquid" : "Gas");
                Z.net.send_message(message);
                outstanding = true;
            }
            return(ret);
        }