Exemple #1
0
        // Function from file: work_tools.dm
        public bool layCable(Tile new_turf = null)
        {
            double?fdirn           = null;
            Obj_Structure_Cable LC = null;
            Obj_Structure_Cable NC = null;
            Powernet            PN = null;


            if (this.equip_ready || !(new_turf is Tile) || !this.dismantleFloor(new_turf))
            {
                this.reset(); return(false);
            }
            fdirn = Num13.Rotate(this.chassis.dir, 180);

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


                if (LC.d1 == fdirn || LC.d2 == fdirn)
                {
                    this.reset(); return(false);
                }
            }

            if (!this.use_cable(1))
            {
                this.reset(); return(false);
            }
            NC = new Obj_Structure_Cable(new_turf);
            NC.cableColor("red");
            NC.d1 = 0;
            NC.d2 = fdirn;
            NC.updateicon();
            PN = null;

            if (this.last_piece != null && this.last_piece.d2 != this.chassis.dir)
            {
                this.last_piece.d1 = Num13.MinInt(((int)(this.last_piece.d2 ?? 0)), this.chassis.dir);
                this.last_piece.d2 = Num13.MaxInt(((int)(this.last_piece.d2 ?? 0)), this.chassis.dir);
                this.last_piece.updateicon();
                PN = this.last_piece.powernet;
            }

            if (!(PN != null))
            {
                PN = new Powernet();
                GlobalVars.powernets.Add(PN);
            }
            NC.powernet = PN;
            PN.cables.Add(NC);
            NC.mergeConnectedNetworks(NC.d2);
            this.last_piece = NC;
            return(true);
        }
Exemple #2
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;
        }