Example #1
0
		public int GetDirection(MTRandom rnd)
		{
			var visited = true;
			var direction = 0;

			while (visited)
			{
				direction = (int)rnd.GetUInt32() & 3;
				visited = this.Directions[direction] != 0;
			}

			this.Directions[direction] = 1;

			return direction;
		}
Example #2
0
		public bool GenerateCriticalPath(MTRandom rnd, int critPathMin, int critPathMax)
		{
			if (this.isCriticalPathGenerated)
				return true;

			if (critPathMin > critPathMax)
			{
				var min = critPathMin;
				critPathMin = critPathMax;
				critPathMax = min;
			}

			//this._critPathMinResult = 0;
			this._critPathMaxResult = 0;
			this.isCriticalPathGenerated = this.GenerateCriticalPathRecursive(0, critPathMin, critPathMax, -1, rnd);

			return this.isCriticalPathGenerated;
		}
Example #3
0
		/// <summary>
		/// Section of teh floor, contain Puzzles.
		/// </summary>
		/// <param name="startRoom">Start room of this section.</param>
		/// <param name="path">Critical path for this section.</param>
		/// <param name="haveBossRoom">Should we place a boss door in this section.</param>
		/// <param name="rng">Randrom generator for this dungeon.</param>
		public DungeonFloorSection(RoomTrait startRoom, List<MazeMove> path, bool haveBossRoom, MTRandom rng)
		{
			_lockColorProvider = new LockColorProvider();
			_lockedDoorCandidates = new LinkedList<LockedDoorCandidateNode>();
			this.Places = new List<PlaceNode>();
			this.Puzzles = new List<Puzzle>();

			_placeBossDoor = haveBossRoom;
			_rng = rng;

			this.InitLists(startRoom, path);
		}
Example #4
0
        public override float GetWeather(DateTime dt)
        {
            int passed = this.GetPassedIntervals(dt);
            if (_cacheIdx == passed)
                return _cache;

            // Skip till we get to the current time
            var rnd = new MTRandom(_seed);
            for (int i = 0; i < passed; ++i)
                rnd.GetUInt32();

            // Cache
            _cacheIdx = passed;

            // Generate
            // Ratio similar to official.
            var r = rnd.GetUInt32(1, 10000);
            // 0.92%
            if (r <= 92)
            {
                _cache = 2.00f;
            }
            // 16.60%
            else if (r <= 92 + 1660)
            {
                var n = 100f / (92 + 1660) * r / 100f;
                _cache = 1.95f + 0.04f * n;
            }
            // 24.50%
            else if (r <= 92 + 1660 + 2450)
            {
                var n = 100f / (92 + 1660 + 2450) * r / 100f;
                _cache = 1f + 0.9f * n;
            }
            // 57.98%
            else
            {
                _cache = 0.50f;
            }

            return _cache;
        }
Example #5
0
        /// <summary>
        /// Changes item colors, using MTRandom and hash.
        /// </summary>
        /// <remarks>
        /// The hash is converted into an int, which is used as seed for
        /// MTRandom, the RNG Mabi is using. That is used to get specific
        /// "random" colors from the color map db.
        /// 
        /// Used to generate "random" colors on the equipment of
        /// new characters and partners.
        /// </remarks>
        private void GenerateItemColors(ref List<Item> items, string hash)
        {
            int ihash = 5381;
            foreach (var ch in hash)
                ihash = ihash * 33 + (int)ch;

            var rnd = new MTRandom(ihash);
            foreach (var item in items.Where(a => a.Info.Pocket != Pocket.Face && a.Info.Pocket != Pocket.Hair))
            {
                var dataInfo = AuraData.ItemDb.Find(item.Info.Id);
                if (dataInfo == null)
                    continue;

                item.Info.Color1 = (item.Info.Color1 != 0 ? item.Info.Color1 : AuraData.ColorMapDb.GetRandom(dataInfo.ColorMap1, rnd));
                item.Info.Color2 = (item.Info.Color2 != 0 ? item.Info.Color2 : AuraData.ColorMapDb.GetRandom(dataInfo.ColorMap2, rnd));
                item.Info.Color3 = (item.Info.Color3 != 0 ? item.Info.Color3 : AuraData.ColorMapDb.GetRandom(dataInfo.ColorMap3, rnd));
            }
        }
Example #6
0
		public bool GenerateSubPath(MTRandom rnd, int coverageFactor, int branchProbability)
		{
			if (!this.isCriticalPathGenerated)
				return false;

			if (this.isSubPathGenerated)
				return true;

			if (coverageFactor > 100)
				coverageFactor = 100;

			if (branchProbability > 100)
				branchProbability = 100;

			var freeRooms = 0;
			for (int y = 0; y < this.Height; ++y)
			{
				for (var x = 0; x < this.Width; ++x)
				{
					if (!this.Rooms[x][y].Occupied)
						freeRooms += 1;
				}
			}

			var coverage = (int)(freeRooms * coverageFactor / 100);
			var toVector = new List<Position>();

			if (this.CriticalPath.Count > 0)
			{
				foreach (var move in this.CriticalPath)
					toVector.Add(move.PosTo);

				toVector.RemoveAt(toVector.Count - 1);
			}

			toVector = this.GenerateSubPathSub1(toVector);

			if (coverage <= 0)
				return true;

			var tempVector = new List<Position>();
			for (int i = 0; i < coverage; ++i)
			{
				var vect = toVector;
				var flag = false;

				if (tempVector.Count == 0)
				{
					if (toVector.Count == 0)
						break;

					flag = true;
				}
				else
				{
					if (toVector.Count == 0)
					{
						flag = false;
						vect = tempVector;
					}
					else
					{
						var rndNum = rnd.GetUInt32() % 100;
						flag = branchProbability >= rndNum;
						if (!flag)
							vect = tempVector;
					}
				}

				int rndIndex = (int)(rnd.GetUInt32() % (uint)vect.Count());
				var pos = vect[rndIndex];
				var room = this.GetRoom(pos);
				var directions = new int[] { 0, 0, 0, 0 };
				var rndDirection = -1;
				var direction = 0;

				while (true)
				{
					rndDirection = this.GenerateSubPathRandomDir(rnd, directions);
					if (room.GetPassageType(rndDirection) == 0)
					{
						if (this.IsRoomInDirectionFree(pos, rndDirection))
							break;
					}

					direction += 1;

					if (direction >= 4)
						break;
				}

				if (direction >= 4)
				{
					tempVector = this.GenerateSubPathSub3(tempVector, toVector);
					toVector = this.GenerateSubPathSub1(toVector);
					continue;
				}

				var biasedPos = pos.GetBiasedPosition(rndDirection);
				var room2 = this.GetRoom(biasedPos);

				room.Directions[rndDirection] = 2;
				room2.Directions[Direction.GetOppositeDirection(rndDirection)] = 1;

				_counter += 1;

				room2.VisitedCount = _counter;
				tempVector.Add(biasedPos);

				if (!flag)
				{
					tempVector.RemoveAt(rndIndex);
					toVector.Add(pos);
				}

				tempVector = this.GenerateSubPathSub3(tempVector, toVector);
				toVector = this.GenerateSubPathSub1(toVector);
			}

			this.isSubPathGenerated = true;

			return true;
		}
Example #7
0
		private bool GenerateCriticalPathRecursive(int critPathPos, int critPathMin, int critPathMax, int direction, MTRandom rnd)
		{
			var directions = new int[4];
			_critPathMaxResult += 1;

			if (_critPathMaxResult <= 10 * critPathMax)
			{
				if (critPathMin <= critPathPos && critPathPos <= critPathMax && this.IsRoomInDirectionFree(_currentPos, StartDirection))
				{
					this.StartPos = _currentPos;

					foreach (var move in this.CriticalPath)
					{
						int temp = move.PosFrom.X;
						move.PosFrom.X = move.PosTo.X;
						move.PosTo.X = temp;

						temp = move.PosFrom.Y;
						move.PosFrom.Y = move.PosTo.Y;
						move.PosTo.Y = temp;

						move.Direction = Direction.GetOppositeDirection(move.Direction);
					}

					this.CriticalPath.Reverse();

					return true;
				}
				else
				{
					critPathPos += 1;
					var count = 0;

					if (critPathPos <= critPathMax)
					{
						if (direction != -1)
							direction = Direction.GetOppositeDirection(direction);

						for (int i = 0; i < 4; i++)
						{
							if (i == direction)
								directions[i] = 0;
							else
							{
								var next_pos = _currentPos.GetBiasedPosition(i);
								directions[i] = Sub(next_pos);
								count += directions[i];
							}
						}

						while (count > 0)
						{
							var rndNum = rnd.GetUInt32() % count + 1;
							int cnt2 = 0;

							var iDir = 0;
							while (iDir < 4)
							{
								cnt2 += directions[iDir];
								if (cnt2 >= rndNum)
									break;

								iDir++;
							}

							count -= directions[iDir];
							directions[iDir] = 0;

							if (this.MakeMove(iDir))
							{
								if (this.GenerateCriticalPathRecursive(critPathPos, critPathMin, critPathMax, iDir, rnd))
									return true;

								this.UndoMove();
							}
						}
					}
				}
			}

			return false;
		}
Example #8
0
		private int GenerateSubPathRandomDir(MTRandom rnd, int[] directions)
		{
			for (int i = 0; i < 4; i++)
			{
				if (directions[i] == 0)
				{
					while (true)
					{
						int random_dir = (int)(rnd.GetUInt32() & 3);
						if (directions[random_dir] == 0)
						{
							directions[random_dir] = 1;
							return random_dir;
						}
					}
				}
			}

			return -1;
		}