Beispiel #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);
            }
        }
Beispiel #2
0
        public Journey AddInterBuildingJourney(Person pers, BldRoom broom, int roomslot)
        {
            //Debug.Log("Adding Interbuilding Journey for " + pers.personName + " to " + broom.name);
            CheckFastMode();
            var frbroom = pers.GetCurrentRoom();

            if (!frbroom)
            {
                Debug.LogWarning(pers.personName + " is not in a room so can't do interbuilding journey - placeRoom:" + pers.placeRoom);
                return(null);
            }
            if (broom == frbroom)
            {
                if (journeyMessages)
                {
                    Debug.LogWarning(pers.personName + " starting journey to same room - no journey - room:" + broom.roomFullName);
                }
                broom.UnReserveRoomSlot(roomslot); // same room - no journey
                return(null);
            }
            //else
            //{
            //    Debug.Log("Clearly room " + broom.name + " is not the same as " + frbroom.name);
            //}


            var bld1 = frbroom.bld;
            var bld2 = broom.bld;

            if (!(bld1.name == bld2.name))
            {
                Debug.LogWarning("Not the same building - no journey frbroom:" + frbroom.roomFullName + "  broom:" + broom.roomFullName);
                broom.UnReserveRoomSlot(roomslot);// not in same building
                return(null);
            }

            var perform = pers.avatarName;

            try
            {
                var jsnode = pers.placeNode;

                Leg leg = new Leg
                {
                    snode    = jsnode,
                    enode    = "",
                    form     = BirdFormE.person,
                    capneed  = LcCapType.walk,
                    formname = perform,
                    vel      = 2 * lvelfak
                };
                var spos = linkctrl.GetNode(jsnode).pt;

                leg.enode = broom.roomNodeName;
                if (!NodeExists(leg.enode))
                {
                    return(null);
                }

                pers.PersonStateStartWaitingToTravel();
                var msg = (pers.personName + " interbuiding leg.snode:" + leg.snode + " enode:" + leg.enode);
                if (journeyMessages)
                {
                    Debug.Log(msg);
                }
                var stardelay     = GraphAlgos.GraphUtil.GetRanFloat(0.5f, 5f);
                var jgo           = new GameObject();
                var jny           = jgo.AddComponent <Journey>();
                var findelaysecs  = 2f;
                var stardelaysecs = GraphAlgos.GraphUtil.GetRanFloat(0, 15);
                jny.InitJourney(this, pers, null, frbroom, broom, msg, findelaysecs, stardelaysecs, jorg: "interbld");
                jny.AddLeg(leg);
                AddJ(jny);
                return(jny);
            }
            catch (UnityException ex)
            {
                Debug.LogWarning("Could not add interbuilding journey for " + pers.personName + " from" + frbroom.name + " to " + broom.name + " " + ex.Message);
                broom.UnReserveRoomSlot(roomslot);
                return(null);
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
 public void AddLeg(Leg leg)
 {
     legdesc.Add(leg.ToString());
     legs.Add(leg);
 }