예제 #1
0
파일: Journey.cs 프로젝트: jmarymee/CampSim
 public void InitJourney(JourneyMan jman, Person pers, Vehicle vehi, BldRoom br1, BldRoom br2, string description, float finsecs = 5, float starsecs = 3, string jorg = "")
 {
     this.jman = jman;
     jindex    = jman.curjidx++;
     //jgo = new GameObject();
     this.description = description;
     //this.description = description;
     name             = "j" + jindex.ToString("D3") + " " + this.description;
     transform.parent = jman.transform;
     legs             = new List <Leg>();
     //pathctrl = jgo.AddComponent<PathCtrl>();
     pathctrl = gameObject.AddComponent <PathCtrl>();
     pathctrl.SetSceneMan(jman.sman);
     //birdctrl = jgo.AddComponent<BirdCtrl>();
     birdctrl      = gameObject.AddComponent <BirdCtrl>();
     birdctrl.sman = jman.sman;
     createtime    = Time.time;
     person        = pers;
     vehicle       = vehi;
     if (jman.sman.fastMode)
     {
         startSecsToDelay    = Mathf.Min(starsecs, 1.2f);
         finishSecsToDestroy = Mathf.Min(finsecs, 1.2f);
     }
     else
     {
         startSecsToDelay    = starsecs;
         finishSecsToDestroy = finsecs;
     }
     failedSecsToDestroy = 10;
     person.journey      = this;
     status  = JourneyStatE.WaitingToStart;
     jnyTime = Time.time;
     jman.LogJourney(this, br1, br2);
 }
예제 #2
0
 public void LogJourney(Journey jny, BldRoom b1, BldRoom b2)
 {
     if (!logJourneys)
     {
         return;
     }
     try
     {
         if (journeysLogged == 0)
         {
             StartLoggingJourneys();
             var headline = "njny,pname,aname,vid,vtype,roomfr,roomto,time,desc\n";
             System.IO.File.AppendAllText(jnyLogFileName, headline);
         }
         jny.jnyTime = Time.time - startJnyTime;
         var pname  = (jny.person ? jny.person.name : "");
         var aname  = (jny.person ? jny.person.avatarName : "");
         var vname  = (jny.vehicle ? jny.vehicle.name : "");
         var fname  = (jny.vehicle ? jny.vehicle.formName : "");
         var r1name = (b1 ? b1.roomFullName : "");
         var r2name = (b2 ? b2.roomFullName : "");
         var line   = journeysLogged + "," + pname + "," + aname + "," + vname + "," + fname + "," + r1name + "," + r2name + "," + jny.jnyTime.ToString("f3") + "," + jny.description + "\n";
         System.IO.File.AppendAllText(jnyLogFileName, line);
         journeysLogged++;
     }
     catch (System.Exception ex)
     {
         logJourneys = false;
         var msg = "Error logging journey";
         Debug.LogError(msg + ex.ToString());
     }
 }
예제 #3
0
 public void RegisterRoom(string roomname, BldRoom bldRoom)
 {
     if (roomlookup.ContainsKey(roomname))
     {
         Debug.Log("In BuildingMan - Room being registered twice:" + roomname);
     }
     roomlookup[roomname] = bldRoom;
 }
예제 #4
0
파일: Person.cs 프로젝트: jmarymee/CampSim
        public BldRoom GetCurrentRoom()
        {
            BldRoom rv = null;

            if (bm.IsRoom(placeRoom))
            {
                rv = bm.GetBroom(placeRoom);
            }
            return(rv);
        }
예제 #5
0
 public void init(BldRoom room, int ncap, float length, float width, bool slotsCanExpand)
 {
     occlookup           = new roomSlotStatE[ncap];
     this.room           = room;
     this.length         = length;
     this.width          = width;
     this.rad            = 0.8f * Mathf.Min(length, width) / 2;
     this.slotsCanExpand = slotsCanExpand;
     this.ncap           = ncap;
     this.orincap        = ncap;
     occDict             = new Dictionary <string, Person>();
 }
예제 #6
0
        public void CalcBldRoomFrames(BldRoom broom, personDetectModeE personDetectMode)
        {
            int icnt    = 0;
            var persons = broom.GetPersons();
            var vz      = Vector3.zero;

            foreach (var person in persons)
            {
                //var rendgo = pers.roomPogo;
                //if (showOnlyFlaggedPeople && !person.flagged) continue;

                var rendgo = GetBodyPart(person, personDetectMode);
                if (rendgo == null)
                {
                    continue;
                }

                if (!GraphAlgos.GraphUtil.ClipToCameraBox(rendgo, clipdist: maxFrameDist))
                {
                    continue;
                }
                var obrect        = GraphAlgos.GraphUtil.GUIRectWithObject(rendgo);
                var obrectvisible = GraphAlgos.GraphUtil.ClipToScreen(obrect);
                if (obrectvisible)
                {
                    var cmt = person.personName + " (" + person.empStatus + ") in room " + broom.roomFullName;
                    var clr = GetPersColor(person, Color.magenta);
                    var pt  = rendgo.transform.position;
                    var rot = rendgo.transform.localEulerAngles;
                    //var debstr = person.placeBld+"/"+person.placeNode +"/"+person.placeRoom;
                    //AddFoundLabel(LableClassE.person, person.avatarName, person.personName, person.empStatus.ToString(),debstr, obrect,pt,rot,vz, broom.roomFullName, cmt, clr, 2);
                    AddFoundLabel(person, obrect, pt, rot, vz, broom.roomFullName, cmt, clr, 2);
                    icnt++;
                }
            }
        }
예제 #7
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);
            }
        }
예제 #8
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);
            }
        }
예제 #9
0
 public void AssociateNodeWithRoom(string nodename, BldRoom broom)
 {
     noderoomlookup[nodename] = broom;
 }