public override void OnInitialized() { DailyRoutine dailyRoutine = null; if (worlditem.Has <DailyRoutine> (out dailyRoutine)) { if (!State.UseDailyRoutine) { dailyRoutine.Finish(); } else { FlagSet occupationFlags = null; GameWorld.Get.FlagSetByName("Occupation", out occupationFlags); dailyRoutine.OccupationFlags = occupationFlags.GetFlagValue(MovementFlags); } } }
public IEnumerator SpawnCharactersOverTime() { if (Globals.MissionDevelopmentMode) { //we don't care about random characters in mission dev mode HasSpawnedCharacters = true; mSpawningCharacters = false; yield break; } List <ActionNodeState> actionNodeStates = null; while (!GameManager.Is(FGameState.InGame) || (mSpawningCharacters && (location.LocationGroup == null || !location.LocationGroup.Is(WIGroupLoadState.Loaded)))) { yield return(null); } //set owner once it's available location.LocationGroup.Owner = worlditem; bool hasSpawnedMinorStructures = false; while (mSpawningCharacters && !hasSpawnedMinorStructures) { hasSpawnedMinorStructures = true; for (int i = 0; i < State.MinorStructures.Count; i++) { if (State.MinorStructures [i].LoadState != StructureLoadState.ExteriorLoaded) { hasSpawnedMinorStructures = false; break; } } double waitUntil = WorldClock.RealTime + 0.25f + UnityEngine.Random.value; while (WorldClock.RealTime < waitUntil) { yield return(null); } } if (!mSpawningCharacters) { yield break; } yield return(null); if (gTransformHelper == null) { gTransformHelper = new GameObject("City Transform Helper").transform; } gTransformHelper.position = worlditem.tr.position; gTransformHelper.rotation = worlditem.tr.rotation; gTransformHelper.localScale = worlditem.tr.lossyScale; //transform the movement node positions MovementNode mn = MovementNode.Empty; for (int i = 0; i < State.MovementNodes.Count; i++) { mn = State.MovementNodes [i]; mn.Position = MovementNode.GetPosition(gTransformHelper, mn); State.MovementNodes [i] = mn; } yield return(null); //TODO move this functionality into the Spawner script if (worlditem.Group.GetParentChunk().GetNodesForLocation(location.LocationGroup.Props.PathName, out actionNodeStates)) { Character spawnedCharacter = null; for (int i = 0; i < actionNodeStates.Count; i++) { if (!mSpawningCharacters) { //whoops, time to stop yield break; } spawnedCharacter = null; ActionNodeState actionNodeState = actionNodeStates [i]; if (actionNodeState.IsLoaded && actionNodeState.UseAsSpawnPoint && !actionNodeState.HasOccupant) { if (string.IsNullOrEmpty(actionNodeState.OccupantName)) { Characters.SpawnRandomCharacter( actionNodeState.actionNode, State.RandomResidentTemplateNames, State.ResidentFlags, location.LocationGroup, out spawnedCharacter); } else { Characters.SpawnRandomCharacter( actionNodeState.actionNode, actionNodeState.OccupantName, State.ResidentFlags, location.LocationGroup, out spawnedCharacter); } if (spawnedCharacter != null) { //let the character know it can use the city for movement nodes if it wants them DailyRoutine dailyRoutine = null; if (spawnedCharacter.worlditem.Is <DailyRoutine> (out dailyRoutine)) { dailyRoutine.ParentSite = this; } SpawnedCharacters.Add(spawnedCharacter); } } double waitUntil = WorldClock.RealTime + 0.5f + UnityEngine.Random.value; while (WorldClock.RealTime < waitUntil) { yield return(null); } } } HasSpawnedCharacters = true; //do we need to update our characters? if (SpawnedCharacters.Count > 0) { enabled = true; } mSpawningCharacters = false; yield break; }