예제 #1
0
        public Journey AddPersonBldroomJourney(Person person, BldRoom broom, int roomslot)
        {
            if (!person)
            {
                Debug.LogWarning("Null person in AddPersonBldroomJourney");
                return(null);
            }
            var fr_node = person.placeNode;
            var tu_node = broom.roomNodeName;

            if (!NodeExists(fr_node))
            {
                return(null);
            }
            if (!NodeExists(tu_node))
            {
                return(null);
            }
            GarageSlot sm1 = null;
            GarageSlot sm2 = null;

            try
            {
                var jsnode = fr_node;
                var jenode = tu_node;
                var gm     = GameObject.FindObjectOfType <GarageMan>();

                var perform = person.avatarName;
                var frroom  = bm.GetBroom(person.placeRoom);

                Leg leg1 = new Leg
                {
                    snode    = jsnode,
                    enode    = "",
                    form     = BirdFormE.person,
                    capneed  = LcCapType.walk,
                    formname = perform,
                    vel      = 2 * lvelfak
                };
                var spos = linkctrl.GetNode(jsnode).pt;
                sm1 = gm.GetClosestFreeCar(spos);
                if (sm1 == null)
                {
                    if (journeyMessages)
                    {
                        Debug.LogWarning("Could not create journey for " + person.personName + "- no free cars at start point");
                    }
                    broom.UnReserveRoomSlot(roomslot);
                    return(null);
                }
                sm1.ReserveCar();
                leg1.enode = sm1.nodename;
                if (!NodeExists(leg1.enode))
                {
                    return(null);
                }
                //Debug.Log("leg1.enode:" + leg1.enode + " pername:" + perform + " carname:" + sm1.carname);

                var carform = BirdFormE.car;
                if (gm.slotform.Get() == SlotFormE.Node)
                {
                    carform = BirdFormE.sphere;
                }
                Leg leg2 = new Leg
                {
                    snode    = leg1.enode,
                    enode    = "",
                    form     = carform,
                    capneed  = LcCapType.drive,
                    vehicle  = sm1.vehicle,
                    formname = sm1.carformname,
                    vel      = 20 * lvelfak
                };

                var epos = linkctrl.GetNode(jenode).pt;
                sm2 = gm.GetClosestAvailableSlot(epos);
                if (sm2 == null)
                {
                    if (journeyMessages)
                    {
                        Debug.LogWarning("Could not create journey for " + person.personName + "  to  " + broom.name + " - no parking slots at dest");
                    }
                    if (sm1)
                    {
                        sm1.UnReserveCar();
                    }
                    broom.UnReserveRoomSlot(roomslot);
                    return(null);
                }
                leg2.enode = sm2.nodename;
                if (!NodeExists(leg2.enode))
                {
                    return(null);
                }

                //Debug.Log("leg2.enode:" + leg2.enode);
                var gslotAvail = sm2.ReserveSlot();
                if (!gslotAvail)
                {
                    if (journeyMessages)
                    {
                        Debug.LogWarning("Could not create journey for " + person.personName + "  to  " + broom.name + " - cound not reserve parking slot at dest");
                    }
                    broom.UnReserveRoomSlot(roomslot);
                    if (sm1)
                    {
                        sm1.UnReserveCar();
                    }
                    if (sm2)
                    {
                        sm2.UnReserveSlot();
                    }
                    return(null);
                }

                Leg leg3 = new Leg
                {
                    snode    = leg2.enode,
                    enode    = jenode,
                    form     = BirdFormE.person,
                    capneed  = LcCapType.walk,
                    formname = perform,
                    vel      = 2 * lvelfak
                };
                var msg = person.personName + " traveling to " + broom.name + " with a " + sm1.carformname;
                person.PersonStateStartWaitingToTravel();
                var stardelay = GraphAlgos.GraphUtil.GetRanFloat(0.5f, 5f);
                var jgo       = new GameObject();
                var jny       = jgo.AddComponent <Journey>();
                // jny.InitJourney(this, null, msg);
                jny.InitJourney(this, person, sm1.vehicle, frroom, broom, msg, 5, stardelay, jorg: "pers,bld,rm");
                jny.AddLeg(leg1);
                jny.AddLeg(leg2);
                jny.AddLeg(leg3);
                AddJ(jny);
                return(jny);
            }
            catch (UnityException ex)
            {
                Debug.LogWarning("Could not add journey for " + person.personName + " from " + fr_node + " to " + tu_node + " " + ex.Message);
                return(null);
            }
        }
예제 #2
0
        public Journey AddBldBldJourney(string fr_node, string tu_node, string pathname)
        {
            if (!NodeExists(fr_node))
            {
                return(null);
            }
            if (!NodeExists(tu_node))
            {
                return(null);
            }
            bool       reservedCar  = false;
            bool       reservedSlot = false;
            GarageSlot sm1          = null;
            GarageSlot sm2          = null;

            try
            {
                var jsnode = fr_node;
                var jenode = tu_node;
                var gm     = GameObject.FindObjectOfType <GarageMan>();

                var perform = GetPersonFormname();


                Leg leg1 = new Leg {
                    snode    = jsnode,
                    enode    = "",
                    form     = BirdFormE.person,
                    capneed  = LcCapType.walk,
                    formname = perform,
                    vel      = 2 * lvelfak
                };
                var spos = linkctrl.GetNode(jsnode).pt;
                sm1 = gm.GetClosestFreeCar(spos);
                if (sm1 == null)
                {
                    if (journeyMessages)
                    {
                        Debug.LogWarning("Could not create journey from " + pathname + "- no free cars at start point");
                    }
                    return(null);
                }
                sm1.ReserveCar();
                reservedCar = true;
                leg1.enode  = sm1.nodename;
                if (!NodeExists(leg1.enode))
                {
                    return(null);
                }
                //Debug.Log("leg1.enode:" + leg1.enode + " pername:" + perform + " carname:" + sm1.carname);

                var carform = BirdFormE.car;
                if (gm.slotform.Get() == SlotFormE.Node)
                {
                    carform = BirdFormE.sphere;
                }
                Leg leg2 = new Leg {
                    snode    = leg1.enode,
                    enode    = "",
                    form     = carform,
                    vehicle  = sm1.vehicle,
                    capneed  = LcCapType.drive,
                    formname = sm1.carformname,
                    vel      = 20 * lvelfak
                };
                var epos = linkctrl.GetNode(jenode).pt;
                sm2 = gm.GetClosestAvailableSlot(epos);
                if (sm2 == null)
                {
                    if (journeyMessages)
                    {
                        if (reservedCar)
                        {
                            sm1.UnReserveCar();
                        }
                        Debug.LogWarning("Could not create journey from " + pathname + " - no parking slots available at destination");
                    }
                    return(null);
                }
                leg2.enode = sm2.nodename;
                if (!NodeExists(leg2.enode))
                {
                    return(null);
                }

                //Debug.Log("leg2.enode:" + leg2.enode);
                sm2.ReserveSlot();
                reservedSlot = true;

                Leg leg3 = new Leg {
                    snode    = leg2.enode,
                    enode    = jenode,
                    form     = BirdFormE.person,
                    capneed  = LcCapType.walk,
                    formname = perform,
                    vel      = 2 * lvelfak
                };
                var description = " - " + pathname + " " + perform + " " + sm1.carformname;
                var jgo         = new GameObject();
                var jny         = jgo.AddComponent <Journey>();
                jny.InitJourney(this, null, null, null, null, description, jorg: "ephemeral");
                jny.AddLeg(leg1);
                jny.AddLeg(leg2);
                jny.AddLeg(leg3);
                AddJ(jny);
                return(jny);
            }
            catch (UnityException ex)
            {
                Debug.LogWarning("Could not add journey from " + fr_node + " to " + tu_node + " " + ex.Message);
                if (reservedCar)
                {
                    sm1.UnReserveCar();
                }
                if (reservedSlot)
                {
                    sm1.UnReserveSlot();
                }
                return(null);
            }
        }