Example #1
0
 // Start is called before the first frame update
 public void SetZone()
 {
     if (ZoneName != "" && ZoneManager.GetZone(ZoneName) != null)
     {
         SetTargetObj(ZoneManager.GetZone(ZoneName).gameObject);
     }
 }
Example #2
0
 public Zone_Stockpile(StorageSettingsPreset preset, ZoneManager zoneManager)
     : base(preset.PresetName(), zoneManager)
 {
     settings = new StorageSettings(this);
     settings.SetFromPreset(preset);
     slotGroup = new SlotGroup(this);
 }
Example #3
0
        public void UpdateMemberRank(GuildMember Member, GuildRank NewRank)
        {
            Member.Rank = NewRank;
            Member.Save();


            //broadcast to members
            using (var packet = new Packet(SH29Type.UpdateGuildMemberRank))
            {
                packet.WriteString(Member.Character.Character.Name, 16);
                packet.WriteByte((byte)NewRank);


                Broadcast(packet);
            }


            //broadcast to zones
            using (var packet = new InterPacket(InterHeader.ZoneGuildMemberRankUpdate))
            {
                packet.WriteInt(ID);
                packet.WriteInt(Member.Character.ID);
                packet.WriteByte((byte)NewRank);


                ZoneManager.Broadcast(packet);
            }
        }
    private void ApplyZone()
    {
        RaycastHit hit;

        if (Physics.BoxCast(transform.position, zoneDetectionHalfSize, transform.rotation * Vector3.down, out hit, transform.rotation, zoneDetectionDistance + halfHeight, zoneMask))
        {
            newZoneTag = hit.collider.tag;
        }
        else
        {
            newZoneTag = "";
        }
        if (!newZoneTag.Equals(currentZoneTag))
        {
            if (currentZone != null && currentZone.LoopSound)
            {
                zoneAudio.Stop();
            }
            currentZone    = ZoneManager.GetZone(newZoneTag);
            currentZoneTag = newZoneTag;
            if (currentZone != null && currentZone.SoundFxClip != null)
            {
                zoneAudio.clip   = currentZone.SoundFxClip;
                zoneAudio.loop   = currentZone.LoopSound;
                zoneAudio.volume = currentZone.Volume;
                zoneAudio.Play();
            }
        }
        if (currentZone != null)
        {
            currentZone.ApplyZone(this);
        }
    }
Example #5
0
 public override void OnSight(Observable o)
 {
     Debug.Log("On sight of : " + o);
     if (o.GetComponent<FactionHolder>() == null ||
         (IgnoreNeutral || o.GetComponent<FactionHolder>().Faction == FactionType.NEUTRAL))
         return;
     if (MasterAI.GetComponent<FactionHolder>().CanAttack(o.GetComponent<FactionHolder>().Faction))
     {
         Debug.Log("Faction is: " + o.GetComponent<FactionHolder>().Faction);
         float d = Vector2.Distance(new Vector2(MasterAI.transform.position.x, MasterAI.transform.position.z),
             new Vector2(o.transform.position.x, o.transform.position.z));
         if (IfSeenInZone != "NONE" && 
             (DistanceCriteria == TransitionDistanceCriteria.WITHIN_DISTANCE_OF && d < WithinDistance ||
             DistanceCriteria == TransitionDistanceCriteria.OUTSIDE_DISTANCE_OF && d > WithinDistance))
         {
             bool inZone = ZoneManager.IsPointInZone(o.transform.position, IfSeenInZone);
             if (inZone && InvertInZoneCondition)
             {
                 return;
             }
             if (!inZone && InvertInZoneCondition)
             {
                 return;
             }
         }
         TargetTask.SetTargetObj(o.gameObject);
         TriggerTransition();
     }
 }
Example #6
0
 void Start()
 {
     asource = objetAFaireApparaitre.GetComponent <AudioSource>();
     objetAFaireApparaitre.SetActive(false);
     zoneManager  = GetComponent <ZoneManager>();
     zoneActuelle = zoneManager.zoneActuelle;
 }
        public override void OnBuildingCreated(ushort id)
        {
            base.OnBuildingCreated(id);

            if (Singleton <BuildingManager> .exists)
            {
                ZoneManager       zm      = Singleton <ZoneManager> .instance;
                ItemClass.Service service = Singleton <BuildingManager> .instance.m_buildings.m_buffer[id].Info.GetService();
                int drop = Singleton <GameSpeedManager> .instance.Parameters.DemandDropAfterBuildingCreated;

                switch (service)
                {
                case ItemClass.Service.Residential:
                    zm.m_actualResidentialDemand = Mathf.Max(0, zm.m_actualResidentialDemand - drop);
                    break;

                case ItemClass.Service.Commercial:
                    zm.m_actualCommercialDemand = Mathf.Max(0, zm.m_actualCommercialDemand - drop);
                    break;

                case ItemClass.Service.Industrial:
                    zm.m_actualWorkplaceDemand = Mathf.Max(0, zm.m_actualWorkplaceDemand - drop);
                    break;

                case ItemClass.Service.Office:
                    zm.m_actualWorkplaceDemand = Mathf.Max(0, zm.m_actualWorkplaceDemand - drop);
                    break;
                }
            }
        }
Example #8
0
 void Awake()
 {
     Instance               = this;
     m_ActionRangeMaxLine   = transform.Find("ActionRangeMax").GetComponent <LineRenderer> ();
     m_ActionRangeMinLine   = transform.Find("ActionRangeMin").GetComponent <LineRenderer> ();
     m_ActionRangeSightLine = transform.Find("ActionRangeSight").GetComponent <LineRenderer> ();
 }
Example #9
0
 public void RestartGame()
 {
     gameIsPaused   = false;
     Time.timeScale = 1;
     SharedInfo.RestartInfo();
     ZoneManager.LoadZone(0);
 }
Example #10
0
        /// <inheritdoc />
        /// <summary>
        /// Will get the EAV ZoneId for the current tennant
        /// Always returns a valid value, as it will otherwise create one if it was missing
        /// </summary>
        /// <param name="tennantId"></param>
        /// <returns></returns>
        public int GetZoneId(int tennantId)
        {
            // additional protection agains invalid portalid which may come from bad dnn configs and execute in search-index mode
            // see https://github.com/2sic/2sxc/issues/1054
            if (tennantId < 0)
            {
                throw new Exception("Can't get zone for invalid portal ID: " + tennantId);
            }

            var zoneSettingKey = Settings.PortalSettingsPrefix + "ZoneID";
            var c = PortalController.Instance.GetPortalSettings(tennantId);
            var portalSettings = new PortalSettings(tennantId);

            int zoneId;

            // Create new zone automatically
            if (!c.ContainsKey(zoneSettingKey))
            {
                zoneId = ZoneManager.CreateZone(portalSettings.PortalName + " (Portal " + tennantId + ")", Log);
                PortalController.UpdatePortalSetting(tennantId, Settings.PortalSettingZoneId, zoneId.ToString());
            }
            else
            {
                zoneId = Int32.Parse(c[zoneSettingKey]);
            }

            return(zoneId);
        }
Example #11
0
        public static void Convert_Old_Stockpiles_To_Lazy(ZoneManager __instance, Zone[] ___zoneGrid)
        {
            Zone[]                zoneGrid    = ___zoneGrid;
            ZoneManager           manager     = __instance;
            Map                   map         = manager.map;
            CellIndices           cellIndices = manager.map.cellIndices;
            List <Zone>           zones       = manager.AllZones;
            List <Zone_Stockpile> deregister  = new List <Zone_Stockpile>();
            List <Lazy_Stockpile> register    = new List <Lazy_Stockpile>();


            for (int i = 0; i < zones.Count; i++)
            {
                Zone z = zones[i];
                if (z as Zone_Stockpile != null && z as Lazy_Stockpile == null)
                {
                    Lazy_Stockpile tmp = new Lazy_Stockpile(z as Zone_Stockpile);
                    manager.AllZones.Remove(z);
                    manager.AllZones.Add(tmp);
                    foreach (IntVec3 c in tmp)
                    {
                        zoneGrid[cellIndices.CellToIndex(c)] = tmp;
                    }
                    //deregister.Add(z as Zone_Stockpile);
                    //register.Add(tmp);
                    Log.Message($"The stockpile {z.label} has been converted to a lazy stockpile");
                }
            }
        }
Example #12
0
    /// <summary>
    /// Makes the player lose HP
    /// Restarts the current level if they die
    /// </summary>
    /// <param name="damage">Damage (Positive; this method will subtract)</param>
    public void TakeDamage(float damage)
    {
        hp           -= damage;
        hitFlashTimer = 10 * Helper.frame;
        Cancel();

        if (hp <= 0)
        {
            Debug.Log("Player died");
            //TODO: Death stuff
            SoundManager.PlaySound(SoundManager.SoundEffects.PlayerDeath, this.gameObject);
            //Flag as not in encounter to fix that up
            enemyMan.EncounterActive = false;
            ZoneManager zoneMan = GameObject.Find("ZoneManagerGO").GetComponent <ZoneManager>();
            switch (zoneMan.CurrentZone.zone)
            {
            case ZoneManager.ZoneNames.PrincessRescue:
                zoneMan.ChangeZone(zoneMan.GetNextZone());
                break;

            default:
                zoneMan.ChangeZone(zoneMan.CurrentZone);
                break;
            }
            hp = 100;
            entity.FacingRight = true;
        }
        else
        {
            //Play not-death sound effect
            SoundManager.PlaySound(SoundManager.SoundEffects.PlayerHit, this.gameObject);
        }
    }
Example #13
0
    public void Awake()
    {
#if SPACE_MAIN
        Collider = GetComponent <MeshCollider>();
        ZoneManager.Register(this);
#endif
    }
Example #14
0
        private static void On_CharacterManager_CharacterLogout(WorldCharacter Character)
        {
            GuildMember member;

            if (Character.Guild != null &&
                Character.Guild.GetMember(Character.Character.Name, out member))
            {
                //send guild member logged out to other guild members
                using (var packet = new Packet(SH29Type.GuildMemberLoggedOut))
                {
                    packet.WriteString(Character.Character.Name, 16);


                    Character.Guild.Broadcast(packet, member);
                }


                //send packet to zone that guild member logged out
                using (var packet = new InterPacket(InterHeader.ZoneGuildMemberLogout))
                {
                    packet.WriteInt(Character.Guild.ID);
                    packet.WriteInt(Character.ID);


                    ZoneManager.Broadcast(packet);
                }
            }
        }
Example #15
0
    public override void OnUpdate()
    {
        if (Time.timeSinceLevelLoad > m_nextCheck)
        {
            if (ZoneName == "noZone")
            {
                return; //TODO, check for No Zone.
            }
            bool IfSeenInZone = ZoneManager.IsHaveObject(MasterAI.GetComponent <AITaskManager>(), ZoneName);

            if (IfSeenInZone && !InvertIfSeenInZoneCondition)
            {
                Zone z = ZoneManager.GetZone(ZoneName);
                if (z != null)
                {
                    TargetTask.SetTargetObj(z.gameObject);
                    TriggerTransition();
                }
            }
            if (!IfSeenInZone && InvertIfSeenInZoneCondition)
            {
                Zone z = ZoneManager.GetZone(ZoneName);
                if (z != null)
                {
                    TargetTask.SetTargetObj(z.gameObject);
                    TriggerTransition();
                }
            }
            m_nextCheck += CHECK_INTERVAL;
        }
    }
Example #16
0
 public override void OnSight(Observable o)
 {
     if (false)
     {
         if (IfSeenInZone != "NONE")
         {
             bool  inZone = ZoneManager.IsPointInZone(o.transform.position, IfSeenInZone);
             float d      = Vector2.Distance(new Vector2(MasterAI.transform.position.x, MasterAI.transform.position.z),
                                             new Vector2(o.transform.position.x, o.transform.position.z));
             if (DistanceCriteria == TransitionDistanceCriteria.WITHIN_DISTANCE_OF && d < WithinDistance ||
                 DistanceCriteria == TransitionDistanceCriteria.OUTSIDE_DISTANCE_OF && d > WithinDistance)
             {
                 return;
             }
             if (inZone && !TriggerIfInZone)
             {
                 return;
             }
             if (!inZone && TriggerIfInZone)
             {
                 return;
             }
         }
         TargetTask.SetTargetObj(o.gameObject);
         TriggerTransition();
     }
 }
Example #17
0
 void DeleteFile(bool delete)
 {
     if (delete)
     {
         if (currentDeleteFile != null)
         {
             Destroy(currentDeleteFile.gameObject);
         }
         if (currentDeleteZone != null)
         {
             Destroy(currentDeleteZone.gameObject);
         }
     }
     else
     {
         if (currentDeleteFile != null)
         {
             currentDeleteFile.transform.position = currentDeleteFile.handle.GetComponent <UIElementDragger>().lastPosition;
             currentDeleteFile.gameObject.SetActive(true);
             currentDeleteFile = null;
         }
         if (currentDeleteZone != null)
         {
             currentDeleteZone.transform.position = currentDeleteZone.handle.GetComponent <UIElementDragger>().lastPosition;
             currentDeleteZone.gameObject.SetActive(true);
             currentDeleteZone = null;
         }
     }
     popupPanels.gameObject.SetActive(false);
 }
Example #18
0
        public async Task AddPresetAsync(int id, ZonePresetType presetType)
        {
            var addedResources = new List <ZoneResource>();

            switch (presetType)
            {
            case ZonePresetType.RDungeon:
            {
                addedResources.AddRange(ZoneManager.AddResources(id, ZoneResourceType.Dungeons, 1));
                addedResources.AddRange(ZoneManager.AddResources(id, ZoneResourceType.RDungeons, 1));
                addedResources.AddRange(ZoneManager.AddResources(id, ZoneResourceType.Maps, 5));
                addedResources.AddRange(ZoneManager.AddResources(id, ZoneResourceType.NPCs, 25));
                addedResources.AddRange(ZoneManager.AddResources(id, ZoneResourceType.Stories, 5));
            }
            break;
            }

            var responseBuilder = new StringBuilder();

            responseBuilder.AppendLine("New resources have been added:");
            responseBuilder.AppendLine();
            var resourceListing = GenerateResourceListing(addedResources);

            responseBuilder.Append(resourceListing);

            await Context.Channel.SendMessageAsync(responseBuilder.ToString());
        }
Example #19
0
    void Start()
    {
        activatedNodes.Clear();
        GameObject zoneManagerObject = GameObject.FindGameObjectWithTag("PlayerZoneManager");

        zoneManager = zoneManagerObject.GetComponent <ZoneManager>();
    }
Example #20
0
 private static void InitializeZones()
 {
     ZoneManager = new ZoneManager();
     foreach (ZoneConfig zonecfg in serverConfig.zones)
     {
         List <Type> extensions = new List <Type>();
         foreach (string extensionName in zonecfg.zone_extensions)
         {
             if (ExtensionManager.extensions.ContainsKey(extensionName))
             {
                 extensions.Add(ExtensionManager.extensions[extensionName]);
             }
             else
             {
                 LogManager.GetCurrentClassLogger().Warn($"Zone '{zonecfg.zone_name}' requires an extension '{extensionName}', which is not installed!");
             }
         }
         Zone zone = new Zone(zonecfg.zone_name, extensions);
         foreach (RoomConfig roomcfg in zonecfg.zone_rooms)
         {
             Room room = new Room(roomcfg);
             zone.RoomManager.AddRoom(room);
         }
         ZoneManager.AddZone(zone);
     }
     ZoneManager.RaiseZonesReady();
 }
Example #21
0
        public async Task DisableAsync(int zoneID, ZoneOption zoneOption)
        {
            if (!ZoneManager.Zones.Zones.ContainsKey(zoneID))
            {
                await Context.Channel.SendMessageAsync("Invalid zone id specified.");

                return;
            }

            if (await ZoneSupport.IsUserLeader(Context, zoneID, Context.User) == false)
            {
                await Context.Channel.SendMessageAsync("You are not a leader of this zone.");

                return;
            }

            var zone = ZoneManager.Zones[zoneID];

            switch (zoneOption)
            {
            case ZoneOption.Visitors:
            {
                zone.AllowVisitors = false;
            }
            break;
            }

            ZoneManager.SaveZone(zoneID);

            await Context.Channel.SendMessageAsync($"The `{zoneOption}` option is now disabled on `{zone.Name}`!");
        }
Example #22
0
        internal AllPlayClient(IService service) : base(service)
        {
            IInterface mediaPlayer = null;
            IInterface mcu         = null;
            IInterface volume      = null;
            IInterface zoneManager = null;

            mediaPlayer = GetInterface("net.allplay.MediaPlayer");
            zoneManager = GetInterface("net.allplay.ZoneManager");
            mcu         = GetInterface("net.allplay.MCU");
            volume      = GetInterface("org.alljoyn.Control.Volume");

            this.MediaPlayer = new MediaPlayer(mediaPlayer);
            if (volume != null)
            {
                Volume = new Volume(volume);
            }
            if (zoneManager != null)
            {
                ZoneManager = new ZoneManager(zoneManager);
            }
            if (mcu != null)
            {
                Mcu = new Mcu(mcu);
            }
        }
Example #23
0
        private async void Form1_Load(object sender, EventArgs e)
        {
            settings = LoadSettings();
            ApplySettings();
            sim         = new InputSimulator();
            zoneManager = new ZoneManager();
            bool initResult   = API.API.TryInit();
            int  newApiInited = SAMP_API.API.Init();

            Log("Ожидаем запуск sampiqa");
            var loadingTask = Task.Run(() =>
            {
                while (!initResult && newApiInited < 1)
                {
                    initResult   = API.API.TryInit();
                    newApiInited = SAMP_API.API.Init();
                    Thread.Sleep(10);
                }
                if (this.InvokeRequired)
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        Log("SAMP обнаружен");
                    }));
                }
            });
            await loadingTask;

            LoadAll();
        }
        public static int GetCurrentRCIValue(RCIType _type)
        {
            int _tmp = 0;

            if (ColossalFramework.Singleton <ZoneManager> .exists)
            {
                ZoneManager _ZoneManager = ColossalFramework.Singleton <ZoneManager> .instance;

                switch (_type)
                {
                case RCIType.Residential:
                    _tmp = _ZoneManager.m_residentialDemand;
                    break;

                case RCIType.Commercial:
                    _tmp = _ZoneManager.m_commercialDemand;
                    break;

                case RCIType.Industrial:
                    _tmp = _ZoneManager.m_workplaceDemand;
                    break;
                }
            }
            else
            {
                Debug.LogError("Can't find ZoneManager !");
            }

            return(_tmp);
        }
        public IEnumerator <YieldInstruction> Replay(ReplayData replay)
        {
            GameManager.Instance.BGM("", true);
            yield return(CoroutineManager.Instance.StartCoroutine(GameManager.Instance.FadeOut(false)));

            DataManager.Instance.MsgLog.Clear();

            if (replay.States.Count > 0)
            {
                GameState state = replay.ReadState();
                if (state.Save.NextDest.IsValid())
                {
                    DataManager.Instance.SetProgress(state.Save);
                    LuaEngine.Instance.LoadSavedData(DataManager.Instance.Save); //notify script engine
                    ZoneManager.LoadFromState(state.Zone);

                    DataManager.Instance.CurrentReplay = replay;
                    yield return(CoroutineManager.Instance.StartCoroutine(GameManager.Instance.MoveToZone(DataManager.Instance.Save.NextDest)));

                    yield break;
                }
            }

            yield return(CoroutineManager.Instance.StartCoroutine(MenuManager.Instance.SetDialogue(Text.FormatKey("DLG_NO_ADVENTURE"))));

            GameManager.Instance.SceneOutcome = GameManager.Instance.ReturnToReplayMenu();
        }
Example #26
0
    public GameObject RunebookGO()
    {
        Zone zone = new Zone(7);
        int  i    = 0;

        for (int x = 0; x < 7; x++)
        {
            for (int y = 0; y < 7; y++)
            {
                if (zone.tiles[x, y].type != TileType.None)
                {
                    if (i < 32)
                    {
                        zone.tiles[x, y] = runes[i].tile;
                        i++;
                    }
                }
            }
        }
        GameObject   rr = GameObject.Find("RuneRenderer");
        ZoneRenderer zr = rr.GetComponent <ZoneRenderer>();
        ZoneManager  zm = rr.GetComponent <ZoneManager>();

        //GameObject output = zr.RenderZone(zone, zm.regularTileSet)[0];
        return(zr.RenderZone(zone, zm.regularTileSet)[0]);
    }
        public GameController(Game game, StateManager stateManager, ZoneManager <GameZone> zoneManager)
        {
            Game          = game;
            _stateManager = stateManager;
            _zoneManager  = zoneManager;

            InputManager.RegisterHandler(this);
        }
        private FactionMapData(int factionId, Map map) : this(map)
        {
            this.factionId = factionId;

            designationManager = new DesignationManager(map);
            areaManager        = new AreaManager(map);
            zoneManager        = new ZoneManager(map);
        }
Example #29
0
 protected virtual void Start()
 {
     _wakeables   = GetComponentsInChildren <ISceneryWakeable>().ToList();
     _resettables = GetComponentsInChildren <IResettable>().ToList();
     _enemies     = GetComponentsInChildren <Enemy>().ToList();
     ZoneManager.AddZone(this);
     _checkpoint = GetComponentInChildren <CheckPoint>();
 }
Example #30
0
    void Start()
    {
        zoneManager      = FindObjectOfType <ZoneManager>();
        needsObjects     = zoneManager.getAllNeedsInteractables().ToArray();
        needsObjectCount = needsObjects.Length;

        OnFollowEnter();
    }
 private static void SimulationStepImplAlt(ZoneManager _this, int subStep)
 {
     Debug.Log($"SimulationStepImpl {subStep}");
 }
        public static void ReleaseBlock(ZoneManager _this, ushort block)
        {
            if (_this.m_blocks.m_buffer[block].m_flags != 0u)
            {
                cachedBlockIDs.Add(block);
            }

            // Call original method
            ReleaseBlockRedirector.Revert();
            _this.ReleaseBlock(block);
            ReleaseBlockRedirector.Apply();
        }
        public static bool CreateBlock(ZoneManager _this, out ushort block, ref Randomizer randomizer, Vector3 position, float angle, int rows, uint buildIndex)
        {
            bool result;
            var columns = NetManagerDetour.newBlockColumnCount;

            if (columns == 0) // create no blocks if desired zone depth is 0
            {
                block = 0;
                result = false;
            }
            else
            {
                // Call original method
                CreateBlockRedirector.Revert();
                result = _this.CreateBlock(out block, ref randomizer, position, angle, rows, buildIndex);
                CreateBlockRedirector.Apply();

                if (result)
                {
                    // --- support for larger zones ---
                    if (DataExtension.zones3 != null) DataExtension.zones3[block] = 0UL;
                    if (DataExtension.zones4 != null) DataExtension.zones4[block] = 0UL;

                    // --- dynamic column count ---
                    // TODO should only affect new roads, not ones replaced or splitted by the game (see Network Skins source code)
                    ZoneBlockDetour.SetColumnCount(ref _this.m_blocks.m_buffer[(int) block], columns);
                }
            }
            return result;
        }
        public static void CheckSpace(ZoneManager _this, ushort block, Vector3 position, float angle, int width, int length, ref ulong space1, ref ulong space2, ref ulong space3, ref ulong space4)
        {
            ZoneBlock zoneBlock = _this.m_blocks.m_buffer[(int)block];

            // difference of 2 radian angles (360 deg = 2*PI * 0.6366197f = 4f)
            // that means an angle difference of 90 deg would result in 1f
            float angleDiff = Mathf.Abs(zoneBlock.m_angle - angle) * 0.6366197f;
            float rightAngleDiff = angleDiff - Mathf.Floor(angleDiff);

            // check if the input angle and the zone block are in right angle (0 90 180 270 deg), otherwise return
            if ((double)rightAngleDiff >= 0.0199999995529652 && (double)rightAngleDiff <= 0.980000019073486) return;

            float searchRadius = Mathf.Min(72f, (float)(width + length) * 4f) + 6f;

            float minX = position.x - searchRadius;
            float minZ = position.z - searchRadius;
            float maxX = position.x + searchRadius;
            float maxZ = position.z + searchRadius;

            // check if the zone block is in the area of interest, otherwise return
            if ((double)zoneBlock.m_position.x + 46.0 < (double)minX || (double)zoneBlock.m_position.x - 46.0 > (double)maxX
                || ((double)zoneBlock.m_position.z + 46.0 < (double)minZ || (double)zoneBlock.m_position.z - 46.0 > (double)maxZ))
            {
                return;
            }

            // width of the zone block
            int rowCount = zoneBlock.RowCount;
            int columnCount = ZoneBlockDetour.GetColumnCount(ref zoneBlock); // modified

            // orientation of the zone block
            Vector3 columnDirection = new Vector3(Mathf.Cos(zoneBlock.m_angle), 0.0f, Mathf.Sin(zoneBlock.m_angle)) * 8f;
            Vector3 rowDirection = new Vector3(columnDirection.z, 0.0f, -columnDirection.x);

            // direction vectors for the given angle
            Vector3 angleParallelDirection = new Vector3(Mathf.Cos(angle), 0.0f, Mathf.Sin(angle)) * 8f;
            Vector3 angleOrthogonalDirection = new Vector3(angleParallelDirection.z, 0.0f, -angleParallelDirection.x);

            for (int row = 0; row < rowCount; ++row)
            {
                Vector3 rowMiddleLength = ((float)row - 3.5f) * rowDirection;

                for (int column = 0; (long)column < columnCount; ++column)
                {
                    // check if the current cell is valid (not shared, not occupied)
                    if (((long)zoneBlock.m_valid & ~(long)zoneBlock.m_shared & ~((long)zoneBlock.m_occupied1 | (long)zoneBlock.m_occupied2) & 1L << (row << 3 | column)) != 0L)
                    {
                        Vector3 columnMiddleLength = ((float)column - 3.5f) * columnDirection;

                        // absolute position of the zone block cell
                        Vector3 cellPosition = zoneBlock.m_position + columnMiddleLength + rowMiddleLength;

                        // check if the cell is in search radius
                        if ((double)Mathf.Abs(position.x - cellPosition.x) < (double)searchRadius && (double)Mathf.Abs(position.z - cellPosition.z) < (double)searchRadius)
                        {
                            // cycle through every cell of the building plot
                            // find the cell that is in the same position as the zone block cell
                            bool cellsMatch = false;
                            for (int plotColumn = 0; plotColumn < length && !cellsMatch; ++plotColumn)
                            {
                                Vector3 plotColumnMiddleLength = (float)((double)plotColumn - (double)length * 0.5 + 0.5) * angleOrthogonalDirection;

                                for (int plotRow = 0; plotRow < width && !cellsMatch; ++plotRow)
                                {
                                    Vector3 plotRowMiddleLength = (float)((double)plotRow - (double)width * 0.5 + 0.5) * angleParallelDirection;

                                    // absolute position of the building plot cell
                                    Vector3 plotCellPosition = position + plotRowMiddleLength + plotColumnMiddleLength;

                                    // check if zone block cell and building plot cell positions match
                                    if ((double)Mathf.Abs(plotCellPosition.x - cellPosition.x) < 0.200000002980232 && (double)Mathf.Abs(plotCellPosition.z - cellPosition.z) < 0.200000002980232)
                                    {
                                        cellsMatch = true;
                                        // depending on column, use one of the 4 masks to report that a cell was found
                                        if (plotColumn < 4)
                                            space1 = space1 | (ulong)(1L << (plotColumn << 4 | plotRow));
                                        else if (plotColumn < 8)
                                            space2 = space2 | (ulong)(1L << (plotColumn - 4 << 4 | plotRow));
                                        else if (plotColumn < 12)
                                            space3 = space3 | (ulong)(1L << (plotColumn - 8 << 4 | plotRow));
                                        else
                                            space4 = space4 | (ulong)(1L << (plotColumn - 12 << 4 | plotRow));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 private static void UpdateDemand(ZoneManager z, ref int demand, int target)
 {
     int lastDemand = demand;
     int nextDemand = demand;
     if (target > lastDemand)
         nextDemand = Mathf.Min(lastDemand + 2, target);
     else if (target < demand)
         nextDemand = Mathf.Max(lastDemand - 2, target);
     z.m_DemandWrapper.OnUpdateDemand(lastDemand, ref nextDemand, target);
     demand = nextDemand;
 }
 private static void InitializeBlock(ZoneManager zm, ushort block, ref ZoneBlock data)
 {
     int num = Mathf.Clamp((int)(data.m_position.x / 64f + HALFGRID), 0, GRIDSIZE - 1);
     int num2 = Mathf.Clamp((int)(data.m_position.z / 64f + HALFGRID), 0, GRIDSIZE - 1);
     int num3 = num2 * GRIDSIZE + num;
     while (!Monitor.TryEnter(zoneGrid, SimulationManager.SYNCHRONIZE_TIMEOUT))
     {
     }
     try
     {
         ZoneManager.instance.m_blocks.m_buffer[(int)block].m_nextGridBlock = zoneGrid[num3];
         zoneGrid[num3] = block;
     }
     finally
     {
         Monitor.Exit(zoneGrid);
     }
 }
        public static void SimulationStepImpl(ZoneManager z, int subStep)
        {
            if (z.m_blocksUpdated)
            {
                int length = z.m_updatedBlocks.Length;
                for (int index1 = 0; index1 < length; ++index1)
                {
                    ulong num = z.m_updatedBlocks[index1];
                    if ((long)num != 0L)
                    {
                        for (int index2 = 0; index2 < 64; ++index2)
                        {
                            if (((long)num & 1L << index2) != 0L)
                            {
                                ushort blockID = (ushort)(index1 << 6 | index2);
                                z.m_blocks.m_buffer[(int)blockID].CalculateBlock1(blockID);
                            }
                        }
                    }
                }
                for (int index1 = 0; index1 < length; ++index1)
                {
                    ulong num = z.m_updatedBlocks[index1];
                    if ((long)num != 0L)
                    {
                        for (int index2 = 0; index2 < 64; ++index2)
                        {
                            if (((long)num & 1L << index2) != 0L)
                            {
                                ushort blockID = (ushort)(index1 << 6 | index2);
                                FakeZoneBlock.CalculateBlock2(ref z.m_blocks.m_buffer[(int)blockID], blockID);
                            }
                        }
                    }
                }
                for (int index1 = 0; index1 < length; ++index1)
                {
                    ulong num = z.m_updatedBlocks[index1];
                    if ((long)num != 0L)
                    {
                        for (int index2 = 0; index2 < 64; ++index2)
                        {
                            if (((long)num & 1L << index2) != 0L)
                            {
                                ushort blockID = (ushort)(index1 << 6 | index2);
                                z.m_blocks.m_buffer[(int)blockID].CalculateBlock3(blockID);
                            }
                        }
                    }
                }
                z.m_blocksUpdated = false;
                for (int index1 = 0; index1 < length; ++index1)
                {
                    ulong num = z.m_updatedBlocks[index1];
                    if ((long)num != 0L)
                    {
                        z.m_updatedBlocks[index1] = 0UL;
                        for (int index2 = 0; index2 < 64; ++index2)
                        {
                            if (((long)num & 1L << index2) != 0L)
                            {
                                ushort blockID = (ushort)(index1 << 6 | index2);
                                z.m_blocks.m_buffer[(int)blockID].UpdateBlock(blockID);
                            }
                        }
                    }
                }
                for (int index = 0; index < z.m_cachedBlocks.m_size; ++index)
                    z.m_cachedBlocks.m_buffer[index].UpdateBlock((ushort)0);
                z.m_cachedBlocks.Clear();
            }
            GuideController guideController = Singleton<GuideManager>.instance.m_properties;
            if (subStep != 0)
            {
                SimulationManager instance1 = Singleton<SimulationManager>.instance;
                if ((int)instance1.m_currentBuildIndex == (int)z.m_lastBuildIndex)
                {
                    int num1 = (int)instance1.m_currentFrameIndex & 1023;
                    int num2 = num1 * 32;
                    int num3 = (num1 + 1) * 32 - 1;
                    for (int index = num2; index <= num3; ++index)
                    {
                        if (((int)z.m_blocks.m_buffer[index].m_flags & 1) != 0)
                        {
                            FakeZoneBlock.SimulationStep(ref z.m_blocks.m_buffer[index], (ushort)index);
                            if ((int)instance1.m_currentBuildIndex != (int)z.m_lastBuildIndex)
                                break;
                        }
                    }
                    for (int index = 0; index < 8; ++index)
                    {
                        int num4 = (int)z.m_goodAreaFound[index];
                        if (num4 != 0 && num4 > -1024)
                            z.m_goodAreaFound[index] = (short)(num4 - 1);
                    }
                }
                if (((int)instance1.m_currentFrameIndex & 7) == 0)
                    z.m_lastBuildIndex = instance1.m_currentBuildIndex;
                if (((int)instance1.m_currentFrameIndex & (int)byte.MaxValue) == 0)
                {
                    if (z.m_fullDemand)
                    {
                        z.m_actualResidentialDemand = 100;
                        z.m_actualCommercialDemand = 100;
                        z.m_actualWorkplaceDemand = 100;
                        z.m_residentialDemand = 100;
                        z.m_commercialDemand = 100;
                        z.m_workplaceDemand = 100;
                    }
                    else
                    {
                        DistrictManager instance2 = Singleton<DistrictManager>.instance;
                        var p = new object[] { instance2.m_districts.m_buffer[0] };
                        int target1 = (int)typeof(ZoneManager).GetMethod("CalculateResidentialDemand", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(z, p);
                        int target2 = (int)typeof(ZoneManager).GetMethod("CalculateCommercialDemand", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(z, p);
                        int target3 = (int)typeof(ZoneManager).GetMethod("CalculateWorkplaceDemand", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(z, p);
                        UpdateDemand(z, ref z.m_actualResidentialDemand, target1);
                        UpdateDemand(z, ref z.m_actualCommercialDemand, target2);
                        UpdateDemand(z, ref z.m_actualWorkplaceDemand, target3);
                        int target4 = z.m_actualResidentialDemand + instance2.m_districts.m_buffer[0].CalculateResidentialDemandOffset();
                        int target5 = z.m_actualCommercialDemand + instance2.m_districts.m_buffer[0].CalculateCommercialDemandOffset();
                        int target6 = z.m_actualWorkplaceDemand + instance2.m_districts.m_buffer[0].CalculateWorkplaceDemandOffset();
                        UpdateDemand(z, ref z.m_residentialDemand, target4);
                        UpdateDemand(z, ref z.m_commercialDemand, target5);
                        UpdateDemand(z, ref z.m_workplaceDemand, target6);
                    }
                }
            }
            if (subStep <= 1 && guideController != null)
            {
                switch ((int)Singleton<SimulationManager>.instance.m_currentTickIndex & 1023)
                {
                    case 100:
                        if (Singleton<UnlockManager>.instance.Unlocked(ItemClass.Zone.ResidentialLow))
                        {
                            if (z.m_residentialDemand > 80)
                            {
                                if (Singleton<SimulationManager>.instance.m_randomizer.Int32(3U) == 0)
                                {
                                    z.m_zoneDemandResidential.Activate(guideController.m_generalDemand, ItemClass.Zone.ResidentialLow);
                                    break;
                                }
                                z.m_zoneDemandResidential.Activate(guideController.m_zoningDemand, ItemClass.Zone.ResidentialLow);
                                break;
                            }
                            if (z.m_residentialDemand < 80)
                            {
                                z.m_zoneDemandResidential.Deactivate();
                                break;
                            }
                            break;
                        }
                        break;

                    case 200:
                        if (Singleton<UnlockManager>.instance.Unlocked(ItemClass.Zone.CommercialLow))
                        {
                            if (z.m_commercialDemand > 80)
                            {
                                if (Singleton<SimulationManager>.instance.m_randomizer.Int32(3U) == 0)
                                {
                                    z.m_zoneDemandCommercial.Activate(guideController.m_generalDemand, ItemClass.Zone.ResidentialLow);
                                    break;
                                }
                                z.m_zoneDemandCommercial.Activate(guideController.m_zoningDemand, ItemClass.Zone.CommercialLow);
                                break;
                            }
                            if (z.m_commercialDemand < 80)
                            {
                                z.m_zoneDemandCommercial.Deactivate();
                                break;
                            }
                            break;
                        }
                        break;

                    case 300:
                        if (Singleton<UnlockManager>.instance.Unlocked(ItemClass.Zone.Industrial))
                        {
                            if (z.m_workplaceDemand > 80)
                            {
                                if (Singleton<SimulationManager>.instance.m_randomizer.Int32(3U) == 0)
                                {
                                    z.m_zoneDemandWorkplace.Activate(guideController.m_generalDemand, ItemClass.Zone.ResidentialLow);
                                    break;
                                }
                                z.m_zoneDemandWorkplace.Activate(guideController.m_zoningDemand, ItemClass.Zone.Industrial);
                                break;
                            }
                            if (z.m_workplaceDemand < 80)
                            {
                                z.m_zoneDemandWorkplace.Deactivate();
                                break;
                            }
                            break;
                        }
                        break;

                    case 400:
                        if (Singleton<UnlockManager>.instance.Unlocked(UnlockManager.Feature.Zoning))
                        {
                            z.m_zonesNotUsed.Activate(guideController.m_zoningNotUsed1);
                            break;
                        }
                        break;
                }
            }
            if (subStep > 1 || guideController == null)
                return;
            int num5 = (int)Singleton<SimulationManager>.instance.m_currentTickIndex & 1023;
            int num6 = num5 * 8 >> 10;
            int num7 = ((num5 + 1) * 8 >> 10) - 1;
            for (int index = num6; index <= num7; ++index)
            {
                if (Singleton<UnlockManager>.instance.Unlocked((ItemClass.Zone)index))
                    z.m_zoneNotUsed[index].Activate(guideController.m_zoningNotUsed2, (ItemClass.Zone)index);
            }
        }
        private static void SimulationStepImpl(ZoneManager _this, int subStep)
        {
            bool blocksUpdated = _this.m_blocksUpdated;

            // Call original method
            SimulationStepImplRedirector.Revert();
            SimulationStepImplAlt(_this, subStep);
            SimulationStepImplRedirector.Apply();

            if(blocksUpdated) cachedBlockIDs.Clear();
        }
Example #39
0
    void InitializeZone()
    {
        zoneManager = GameObject.FindWithTag("Zone Manager").GetComponent<ZoneManager>();
        zoneRenderer = zoneManager.GetComponent<ZoneRenderer>();

        // --- Input

        // --- Network

        // --- Zone
        if (currentZoneObjects != null && currentZoneObjects.Count > 0)
        {
          foreach (GameObject g in currentZoneObjects)
        Destroy (g);
        }
        int safety = 100;
        bool buildingZone = true;
        int minimumSize = 1750;

        Triangle tri = new Triangle(new Vector3(0, 0, 0), new Vector3(18, 0, 24), new Vector3(0, 0, 36));

        while (buildingZone)
        {
          currentZone = new Zone(tri);

          if (currentZone.landArea > minimumSize)
          {
        Debug.Log("Zone generated with a land mass of "+currentZone.landArea+" hex.");
        buildingZone = false;
          }
          else if (currentZone.landArea>0)
          {
        Debug.Log("Land mass is too low. New level being generated....");
          }
          else
          {
        Debug.Log("Underwater level detected. New level being generated....");
          }

          safety--;
          if (safety < 0)
        break;
        }

        currentZoneObjects = zoneRenderer.RenderZone(currentZone, zoneManager.regularTileSet);
        zoneManager.Initialize(currentZone);
    }