private void OnDeserialized(StreamingContext context)
 {
     Flags = RevisionFlags.None;
     if (Minor)
     {
         Flags |= RevisionFlags.Minor;
     }
     if (Bot)
     {
         Flags |= RevisionFlags.Bot;
     }
     if (New)
     {
         Flags |= RevisionFlags.Create;
     }
     if (Anon)
     {
         Flags |= RevisionFlags.Anonymous;
     }
     if (Patrolled)
     {
         PatrolStatus = PatrolStatus.Patrolled;
     }
     else if (Unpatrolled)
     {
         PatrolStatus = PatrolStatus.Unpatrolled;
     }
     else
     {
         PatrolStatus = PatrolStatus.Unknown;
     }
     if (Patrolled && Unpatrolled)
     {
         Site.Logger.LogWarning("Patrolled and Unpatrolled are both set for rcid={Id}, page {Page}.", Id, Title);
     }
 }
Ejemplo n.º 2
0
 void UpdatePatrolStatus(PatrolStatus pat)
 {
     patrolStatus.RemoveAll(c => c.unitID == pat.unitID);
     patrolStatus.Add(pat);
 }
Ejemplo n.º 3
0
    //Officer update
    void OfficerUpdate()
    {
        //If there's nothing to say and say nothing and nothing to heard
        if (brain.mouth.HasNothingToSay() && !brain.mouth.IsTalkingToRadio() && !brain.ears.IsListeningRadio())
        {
            //Get all orders of this type
            IAInformation order = brain.memory.GetLastOrderOfTypes(IAInformation.InformationType.DEVIATETOZONE,
                                                                   IAInformation.InformationType.BRINGTOOFFICER,
                                                                   IAInformation.InformationType.MEETOFFICER);
            //If there's order it means that the officer ask for status update and waiting to give the order
            if (order != null)
            {
                //Update the patrol status
                UpdatePatrolStatus();
                if (IsPatrolStatusInitialized())
                {
                    if (patrolStatus.Count > maxPatrolStatus)
                    {
                        maxPatrolStatus = patrolStatus.Count;
                    }
                    //If there's a patrol that didn't answer since a certain amount of time
                    if (!HasAPatrolSlientSince(order.timeCreation))
                    {
                        //We clean the order to gives and gives the order
                        brain.memory.CleanOrders();
                        if (order.type == IAInformation.InformationType.DEVIATETOZONE)
                        {
                            Zone zoneToSearch = brain.GetValidZoneToSearch().FindLast(c => true);
                            brain.mouth.TellInformationToOthers(IAInformation.InformationType.DEVIATETOZONE, 1f, GetClosestUnitName(zoneToSearch) + "$" + zoneToSearch.zoneName, true);
                            brain.ChangeState(IAStateTag.WORKING);
                        }
                        else if (order.type == IAInformation.InformationType.BRINGTOOFFICER)
                        {
                            List <Zone> zonesToTake = ZoneManager.instance.allZones.FindAll(c => c.zoneEntries.Count == 1 && c != brain.defaultZone);
                            Zone        zoneToTake  = zonesToTake[Random.Range(0, zonesToTake.Count)];
                            brain.mouth.TellInformationToOthers(IAInformation.InformationType.BRINGTOOFFICER, 4f, GetClosestUnitName(zoneToTake) + "$" + zoneToTake.zoneName + "$" + Random.Range(0, 2).ToString(), true);
                            brain.ChangeState(IAStateTag.WORKING);
                            attendingInfo = brain.mouth.GetLastInfoToCommunicate();
                            timeAttending = Time.time;
                        }
                        else
                        {
                            brain.mouth.TellInformationToOthers(IAInformation.InformationType.MEETOFFICER, 4f, order.parameters, true);
                            brain.ChangeState(IAStateTag.WORKING);
                            attendingInfo = brain.mouth.GetLastInfoToCommunicate();
                            timeAttending = Time.time;
                        }
                    }
                    else //If a patrol didn't answer
                    {
                        //Check if a unit has disappear
                        ConfirmDisappearedUnit(order.timeCreation);
                    }
                }
            }
            else //If not order
            {
                //If we are waiting confirmation from the unit who receive the order
                if (brain.GetOrderConfirmation() != null)
                {
                    UpdatePatrolStatus();
                    string[]     orderParameterSplit = brain.GetOrderConfirmation().parameters.Split('$');
                    PatrolStatus pat = patrolStatus.Find(c => c.unitID == orderParameterSplit[0]);
                    //If the unit has talk since the order, we relaunch the order
                    if (pat != null && pat.lastMessage > brain.GetOrderConfirmation().timeCreation)
                    {
                        brain.mouth.TellInformationToOthers(brain.GetOrderConfirmation().type, 4f, brain.GetOrderConfirmation().parameters, true);
                    }
                    else //Else we check if the unit has disappear
                    {
                        ConfirmDisappearedUnit(brain.GetOrderConfirmation().timeCreation);
                    }
                }
                //If the order has been given and the unit is on his way
                else if (attendingInfo != null)
                {
                    Debug.Log("We are attendig info");
                    //Checinkg the time the unit operate
                    if (Time.time > timeAttending + (attendingInfo.type == IAInformation.InformationType.MEETOFFICER ? 60f : 120f))
                    {
                        Debug.Log("It's too long !");
                        //Update patrol status
                        UpdatePatrolStatus();
                        //Prepare to re-ask the task
                        brain.mouth.TellInformationToOthers(IAInformation.InformationType.ASKSTATUS, 1f, "all", true);
                        brain.memory.RegisterMemory(new IAInformation(brain.unitID, attendingInfo.type, 0f, attendingInfo.parameters, true), true);
                    }
                    else
                    {
                        //It's normal, lets back to work
                        Debug.Log("its normal lets work");
                        brain.ChangeState(IAStateTag.WORKING);
                    }
                }
                else
                {
                    Debug.Log("Choose order");

                    brain.memory.CleanOrders();
                    brain.SetOrderConfirmation(null);

                    float rangeIdle = Random.Range(0f, 100f);
                    if (rangeIdle < 33f) //We choose to ask a unit to meet the officer
                    {
                        List <string> allPatrol      = UnitManager.instance.GetAllUnits().FindAll(c => c.Contains("PATROL"));
                        string        patrolSelected = allPatrol[Random.Range(0, allPatrol.Count)];
                        brain.mouth.TellInformationToOthers(IAInformation.InformationType.MEETOFFICER, 4f, patrolSelected, true);
                        brain.ChangeState(IAStateTag.WORKING);
                        attendingInfo = brain.mouth.GetLastInfoToCommunicate();
                        timeAttending = Time.time;
                    }
                    else if (rangeIdle >= 33f && rangeIdle < 66f) //We choose to ask status to bring something to the officer
                    {
                        UpdatePatrolStatus();
                        brain.mouth.TellInformationToOthers(IAInformation.InformationType.ASKSTATUS, 1f, "all", true);
                        brain.memory.RegisterMemory(new IAInformation(brain.unitID, IAInformation.InformationType.BRINGTOOFFICER, 0f, "", true), true);
                    }
                    else if (rangeIdle >= 66f && rangeIdle < 99f) //We choose to ask status to check a zone
                    {
                        UpdatePatrolStatus();
                        brain.mouth.TellInformationToOthers(IAInformation.InformationType.ASKSTATUS, 1f, "all", true);
                        brain.memory.RegisterMemory(new IAInformation(brain.unitID, IAInformation.InformationType.DEVIATETOZONE, 0f, "", true), true);
                    }
                    else //Back to work
                    {
                        Debug.Log("back to work :(");
                        brain.ChangeState(IAStateTag.WORKING);
                    }
                }
            }
        }
    }