Example #1
0
        // Function from file: machines.dm
        public void makepowernets(dynamic zlevel = null)
        {
            Powernet            PN    = null;
            Obj_Structure_Cable PC    = null;
            Powernet            NewPN = null;


            foreach (dynamic _a in Lang13.Enumerate(this.powernets, typeof(Powernet)))
            {
                PN = _a;

                GlobalFuncs.qdel(PN);
            }
            this.powernets.Cut();

            foreach (dynamic _b in Lang13.Enumerate(GlobalVars.cable_list, typeof(Obj_Structure_Cable)))
            {
                PC = _b;


                if (!(PC.powernet != null))
                {
                    NewPN = new Powernet();
                    NewPN.add_cable(PC);
                    GlobalFuncs.propagate_network(PC, PC.powernet);
                }
            }
            return;
        }
Example #2
0
        // Function from file: cable.dm
        public void mergeConnectedNetworks(double?direction = null)
        {
            double?fdir               = null;
            Tile   TB                 = null;
            Obj_Structure_Cable C     = null;
            Powernet            newPN = null;

            fdir = (!Lang13.Bool(direction) ? 0 : Num13.Rotate(direction, 180));

            if (!(this.d1 == direction || this.d2 == direction))
            {
                return;
            }
            TB = Map13.GetStep(this, ((int)(direction ?? 0)));

            foreach (dynamic _a in Lang13.Enumerate(TB, typeof(Obj_Structure_Cable)))
            {
                C = _a;


                if (!(C != null))
                {
                    continue;
                }

                if (this == C)
                {
                    continue;
                }

                if (C.d1 == fdir || C.d2 == fdir)
                {
                    if (!(C.powernet != null))
                    {
                        newPN = new Powernet();
                        newPN.add_cable(C);
                    }

                    if (this.powernet != null)
                    {
                        GlobalFuncs.merge_powernets(this.powernet, C.powernet);
                    }
                    else
                    {
                        C.powernet.add_cable(this);
                    }
                }
            }
            return;
        }
Example #3
0
        // Function from file: machines.dm
        public void setup_template_powernets(ByTable cables = null)
        {
            dynamic  A     = null;
            dynamic  PC    = null;
            Powernet NewPN = null;


            foreach (dynamic _a in Lang13.Enumerate(cables))
            {
                A = _a;

                PC = A;

                if (!Lang13.Bool(PC.powernet))
                {
                    NewPN = new Powernet();
                    NewPN.add_cable(PC);
                    GlobalFuncs.propagate_network(PC, PC.powernet);
                }
            }
            return;
        }
Example #4
0
        // Function from file: cable.dm
        public void cable_join(Obj_Structure_Cable C = null, dynamic user = null)
        {
            Ent_Static          U     = null;
            Ent_Static          T     = null;
            double?             dirn  = null;
            double?             fdirn = null;
            Obj_Structure_Cable LC    = null;
            dynamic             NC    = null;
            Powernet            newPN = null;
            double?             nd1   = null;
            double?             nd2   = null;
            Obj_Structure_Cable LC2   = null;

            U = user.loc;

            if (!(U is Tile))
            {
                return;
            }
            T = C.loc;

            if (!(T is Tile) || Lang13.Bool(((dynamic)T).intact))
            {
                return;
            }

            if (Map13.GetDistance(C, user) > 1)
            {
                user.WriteMsg("<span class='warning'>You can't lay cable at a place that far away!</span>");
                return;
            }

            if (U == T)
            {
                this.place_turf(T, user);
                return;
            }
            dirn = Map13.GetDistance(C, user);

            if (C.d1 == dirn || C.d2 == dirn)
            {
                if (!Lang13.Bool(((dynamic)U).can_have_cabling()))
                {
                    user.WriteMsg("<span class='warning'>You can only lay cables on catwalks and plating!</span>");
                    return;
                }

                if (Lang13.Bool(((dynamic)U).intact))
                {
                    user.WriteMsg("<span class='warning'>You can't lay cable there unless the floor tiles are removed!</span>");
                    return;
                }
                else
                {
                    fdirn = Num13.Rotate(dirn, 180);

                    foreach (dynamic _a in Lang13.Enumerate(U, typeof(Obj_Structure_Cable)))
                    {
                        LC = _a;


                        if (LC.d1 == fdirn || LC.d2 == fdirn)
                        {
                            user.WriteMsg("<span class='warning'>There's already a cable at that position!</span>");
                            return;
                        }
                    }
                    NC    = this.get_new_cable(U);
                    NC.d1 = 0;
                    NC.d2 = fdirn;
                    ((Ent_Static)NC).add_fingerprint();
                    NC.updateicon();
                    newPN = new Powernet();
                    newPN.add_cable(NC);
                    ((Obj_Structure_Cable)NC).mergeConnectedNetworks(NC.d2);
                    ((Obj_Structure_Cable)NC).mergeConnectedNetworksOnTurf();

                    if ((((int)(NC.d2 ?? 0)) & ((int)((NC.d2 ?? 0) - 1))) != 0)
                    {
                        ((Obj_Structure_Cable)NC).mergeDiagonalsNetworks(NC.d2);
                    }
                    this.use(1);

                    if (((Obj_Structure_Cable)NC).shock(user, 50))
                    {
                        if (Rand13.PercentChance(50))
                        {
                            ((Obj)NC).Deconstruct();
                        }
                    }
                    return;
                }
            }
            else if (C.d1 == 0)
            {
                nd1 = C.d2;
                nd2 = dirn;

                if ((nd1 ?? 0) > (nd2 ?? 0))
                {
                    nd1 = dirn;
                    nd2 = C.d2;
                }

                foreach (dynamic _b in Lang13.Enumerate(T, typeof(Obj_Structure_Cable)))
                {
                    LC2 = _b;


                    if (LC2 == C)
                    {
                        continue;
                    }

                    if (LC2.d1 == nd1 && LC2.d2 == nd2 || LC2.d1 == nd2 && LC2.d2 == nd1)
                    {
                        user.WriteMsg("<span class='warning'>There's already a cable at that position!</span>");
                        return;
                    }
                }
                C.cableColor(this.item_color);
                C.d1 = nd1;
                C.d2 = nd2;
                C.update_stored(2, this.item_color);
                C.add_fingerprint();
                C.updateicon();
                C.mergeConnectedNetworks(C.d1);
                C.mergeConnectedNetworks(C.d2);
                C.mergeConnectedNetworksOnTurf();

                if ((((int)(C.d1 ?? 0)) & ((int)((C.d1 ?? 0) - 1))) != 0)
                {
                    C.mergeDiagonalsNetworks(C.d1);
                }

                if ((((int)(C.d2 ?? 0)) & ((int)((C.d2 ?? 0) - 1))) != 0)
                {
                    C.mergeDiagonalsNetworks(C.d2);
                }
                this.use(1);

                if (C.shock(user, 50))
                {
                    if (Rand13.PercentChance(50))
                    {
                        C.Deconstruct();
                        return;
                    }
                }
                C.denode();
                return;
            }
            return;
        }
Example #5
0
        // Function from file: cable.dm
        public void place_turf(Ent_Static T = null, dynamic user = null)
        {
            double?dirn            = null;
            Obj_Structure_Cable LC = null;
            dynamic             C  = null;
            Powernet            PN = null;


            if (!(user.loc is Tile))
            {
                return;
            }

            if (!Lang13.Bool(((dynamic)T).can_have_cabling()))
            {
                user.WriteMsg("<span class='warning'>You can only lay cables on catwalks and plating!</span>");
                return;
            }

            if ((this.get_amount() ?? 0) < 1)
            {
                user.WriteMsg("<span class='warning'>There is no cable left!</span>");
                return;
            }

            if (Map13.GetDistance(T, user) > 1)
            {
                user.WriteMsg("<span class='warning'>You can't lay cable at a place that far away!</span>");
                return;
            }
            else
            {
                if (user.loc == T)
                {
                    dirn = Lang13.DoubleNullable(user.dir);
                }
                else
                {
                    dirn = Map13.GetDistance(T, user);
                }

                foreach (dynamic _a in Lang13.Enumerate(T, typeof(Obj_Structure_Cable)))
                {
                    LC = _a;


                    if (LC.d2 == dirn && LC.d1 == 0)
                    {
                        user.WriteMsg("<span class='warning'>There's already a cable at that position!</span>");
                        return;
                    }
                }
                C    = this.get_new_cable(T);
                C.d1 = 0;
                C.d2 = dirn;
                ((Ent_Static)C).add_fingerprint(user);
                C.updateicon();
                PN = new Powernet();
                PN.add_cable(C);
                ((Obj_Structure_Cable)C).mergeConnectedNetworks(C.d2);
                ((Obj_Structure_Cable)C).mergeConnectedNetworksOnTurf();

                if ((((int)(C.d2 ?? 0)) & ((int)((C.d2 ?? 0) - 1))) != 0)
                {
                    ((Obj_Structure_Cable)C).mergeDiagonalsNetworks(C.d2);
                }
                this.use(1);

                if (((Obj_Structure_Cable)C).shock(user, 50))
                {
                    if (Rand13.PercentChance(50))
                    {
                        ((Obj)C).Deconstruct();
                    }
                }
            }
            return;
        }
Example #6
0
        // Function from file: cable.dm
        public void mergeDiagonalsNetworks(double?direction = null)
        {
            Tile T = null;
            Obj_Structure_Cable C      = null;
            Powernet            newPN  = null;
            Obj_Structure_Cable C2     = null;
            Powernet            newPN2 = null;

            T = Map13.GetStep(this, ((int)(direction ?? 0)) & 3);

            foreach (dynamic _a in Lang13.Enumerate(T, typeof(Obj_Structure_Cable)))
            {
                C = _a;


                if (!(C != null))
                {
                    continue;
                }

                if (this == C)
                {
                    continue;
                }

                if (C.d1 == (((int)(direction ?? 0)) ^ 3) || C.d2 == (((int)(direction ?? 0)) ^ 3))
                {
                    if (!(C.powernet != null))
                    {
                        newPN = new Powernet();
                        newPN.add_cable(C);
                    }

                    if (this.powernet != null)
                    {
                        GlobalFuncs.merge_powernets(this.powernet, C.powernet);
                    }
                    else
                    {
                        C.powernet.add_cable(this);
                    }
                }
            }
            T = Map13.GetStep(this, ((int)(direction ?? 0)) & 12);

            foreach (dynamic _b in Lang13.Enumerate(T, typeof(Obj_Structure_Cable)))
            {
                C2 = _b;


                if (!(C2 != null))
                {
                    continue;
                }

                if (this == C2)
                {
                    continue;
                }

                if (C2.d1 == (((int)(direction ?? 0)) ^ 12) || C2.d2 == (((int)(direction ?? 0)) ^ 12))
                {
                    if (!(C2.powernet != null))
                    {
                        newPN2 = new Powernet();
                        newPN2.add_cable(C2);
                    }

                    if (this.powernet != null)
                    {
                        GlobalFuncs.merge_powernets(this.powernet, C2.powernet);
                    }
                    else
                    {
                        C2.powernet.add_cable(this);
                    }
                }
            }
            return;
        }
Example #7
0
        // Function from file: cable.dm
        public void mergeConnectedNetworksOnTurf(  )
        {
            ByTable             to_connect = null;
            Powernet            newPN      = null;
            dynamic             AM         = null;
            dynamic             C          = null;
            dynamic             N          = null;
            dynamic             M          = null;
            Obj_Machinery_Power PM         = null;

            to_connect = new ByTable();

            if (!(this.powernet != null))
            {
                newPN = new Powernet();
                newPN.add_cable(this);
            }

            foreach (dynamic _a in Lang13.Enumerate(this.loc))
            {
                AM = _a;


                if (AM is Obj_Structure_Cable)
                {
                    C = AM;

                    if (C.d1 == this.d1 || C.d2 == this.d1 || C.d1 == this.d2 || C.d2 == this.d2)
                    {
                        if (C.powernet == this.powernet)
                        {
                            continue;
                        }

                        if (Lang13.Bool(C.powernet))
                        {
                            GlobalFuncs.merge_powernets(this.powernet, C.powernet);
                        }
                        else
                        {
                            this.powernet.add_cable(C);
                        }
                    }
                }
                else if (AM is Obj_Machinery_Power_Apc)
                {
                    N = AM;

                    if (!Lang13.Bool(N.terminal))
                    {
                        continue;
                    }

                    if (N.terminal.powernet == this.powernet)
                    {
                        continue;
                    }
                    to_connect.Add(N.terminal);
                }
                else if (AM is Obj_Machinery_Power)
                {
                    M = AM;

                    if (M.powernet == this.powernet)
                    {
                        continue;
                    }
                    to_connect.Add(M);
                }
            }

            foreach (dynamic _b in Lang13.Enumerate(to_connect, typeof(Obj_Machinery_Power)))
            {
                PM = _b;


                if (!PM.connect_to_network())
                {
                    PM.disconnect_from_network();
                }
            }
            return;
        }