Beispiel #1
0
	// Use this for initialization
	void Start () {
		//move it to some MapScript MonoBehaviour, attach MapScript to child GameObject of Main GO and add link in Main:
		//public MapScript Map = blah blah blah;
		map = GameMap.Generate();
		foreach (var p in map.provinces)
		{
			var provinceGO = new GameObject(p.Name + " Province");
			var meshFilter = provinceGO.AddComponent<MeshFilter>();
			meshFilter.mesh = CreateMesh(p);
			var renderer = provinceGO.AddComponent<MeshRenderer>();
			renderer.material.shader = Shader.Find("Toon/Basic");
			renderer.material.SetColor("_Color", Color.red);
			provinceGO.transform.parent = gameObject.transform;
			
			var borderObject = new GameObject("NewBorder");
			var bMeshFilter = borderObject.AddComponent<MeshFilter>();
			bMeshFilter.mesh = CreateBorder(meshFilter.mesh, 0.2f);
			var bRenderer = borderObject.AddComponent<MeshRenderer>();
			bRenderer.material.shader = Shader.Find("Toon/Basic");
			bRenderer.material.SetColor("_Color", Color.black);
			borderObject.transform.parent = provinceGO.transform;
			provinceGO.AddComponent<MeshCollider>();
			ProvinceScript provinceScript = provinceGO.AddComponent<ProvinceScript>();
			provinceScript.border = borderObject;
			provinceScript.name = p.Name;
		}
	}
 public static string GetLeaderboardForMap(GameMap map)
 {
     if (!leaderboards.ContainsKey(map)) {
         return NO_LEADERBOARD;
     }
     return leaderboards[map];
 }
Beispiel #3
0
	void Start ()
	{
		_instanceMap ();
		gameMap = new GameMap ();
		gameMap.RandomPosValue ();
		ResetMap ();
	}
Beispiel #4
0
    public void Setup(bool same)
    {
        if (!same)  //If new map
        {
            map = new GameMap();
            map.Start();
        }
        endGame = false;    //setup
        wump = new Wumpus();
        player = new Player();
        bats = new Bat();

        wump.room = map.getWump();
        player.room = map.getCurrent();
        int[] temp = map.getAdjacent(player.room);
        doors[0] = GameObject.Find("Left Door");
        doors[1] = GameObject.Find("Middle Door");
        doors[2] = GameObject.Find("Right Door");
        for (int i = 0; i < 3; i++)
        {
            doors[i].GetComponent<Door>().doorNum = temp[i];
        }
        bats.room = map.getBat();
        currentNum.text = "Current Room: " + player.room;
        //GameObject[] doors = FindObjectsOfType(typeof(Door)) as GameObject[];
        for (int i = 0; i < 20; i++)
        {
            rooms[i] = GameObject.Find("/Rooms/Room (" + i + ")");
        }
        Warnings(); //check for initial warnings
    }
Beispiel #5
0
        public override bool Update(GameTime gameTime, GameMap gameMap, List<Fighter> fighters, List<Enemy> enemies)
        {
            float s = speed * (gameTime.ElapsedGameTime.Ticks) * 0.00001f;

            Vector2 shift = new Vector2(target.X - position.X, target.Y - position.Y);

            if (shift != Vector2.Zero)
                shift.Normalize();
            shift *= s;

            if ((position + shift).Similar(target, s)) return true;

            position += shift;

            Object colide;

            if ((colide = Collision(gameMap,fighters,enemies)) != null)
            {
                if (colide is Enemy || colide is Fighter)
                {
                    if (((Unit)colide).IsAlive)
                        ((Unit)colide).Die(fighters);
                }
                return true;
            }

            return false;
        }
 public async Task CreateGame(dynamic args)
 {
     string allowSpectators = GameJsApiService.GetAllowSpectators((string)args.spectators);
     int num = (int)args.mapId;
     string str = (string)args.name;
     string str1 = (string)args.password;
     int num1 = (int)args.gctId;
     int num2 = (int)args.players;
     RiotAccount riotAccount = JsApiService.RiotAccount;
     PracticeGameConfig practiceGameConfig = new PracticeGameConfig()
     {
         AllowSpectators = allowSpectators
     };
     PracticeGameConfig practiceGameConfig1 = practiceGameConfig;
     GameMap gameMap = new GameMap()
     {
         MapId = num,
         TotalPlayers = num2
     };
     practiceGameConfig1.GameMap = gameMap;
     practiceGameConfig.GameMode = GameJsApiService.GetGameMode(num);
     practiceGameConfig.GameName = str;
     practiceGameConfig.GamePassword = str1;
     practiceGameConfig.GameTypeConfig = num1;
     practiceGameConfig.MaxNumPlayers = num2;
     await riotAccount.InvokeAsync<object>("gameService", "createPracticeGame", practiceGameConfig);
 }
 public MoveStrategy(GameMap gameMap, List<Fighter> fighters, List<Enemy> enemies, Unit unit)
 {
     this.gameMap = gameMap;
     this.fighters = fighters;
     this.enemies = enemies;
     this.unit = unit;
 }
Beispiel #8
0
 // Awake is called when the script instance is being loaded
 public void Awake()
 {
     slider = GetComponent<Slider>();
     valueLabel = transform.FindChild("Value").GetComponent<Text>();
     gameMap = FindObjectOfType<GameMap>();
     cam = Camera.main;
 }
        public static Point GetMapPosition(this Vector2 v, GameMap gameMap)
        {
            /*
            int j = (int)Math.Floor((2 * (int)v.Y) / GameMap.TileShift.Y);
            int i = (int)Math.Floor((int)v.X / GameMap.TileShift.X - ((j % 2 == 1) ? 1 / 2 : 0));
            if (i < 0) i = 0;
            if (i > gameMap.width) i = gameMap.width - 1;
            if (j < 0) j = 0;
            if (j > gameMap.height - 1) j = gameMap.height - 1;
            */

            // Małe współrzędne
            int x = (int)Math.Floor(v.X * 2 / GameMap.TileShift.X);
            int y = (int)Math.Floor(v.Y * 2 / GameMap.TileShift.Y);

            // Duże współrzędne
            int i = (int)Math.Floor(((double)x) / 2);
            int j = 2 * (int)Math.Floor((double)y / 2);

            // 4 przypadki i w każdym jeszcze po 2
            // TODO: do poprawy, maja byc uwzglednione punkty na calej mapie a nie cos dziwnego co tu zrobilem

            if (x % 2 == 0 && y % 2 == 0)
            {
                float a = (GameMap.TileShift.Y) / (-GameMap.TileShift.X);
                float b = GameMap.TileShift.Y / 2 * (y + 1) - a * GameMap.TileShift.X / 2 * x;
                if (v.Y < a * v.X + b)
                {
                    i--;
                    j--;
                }
            }
            else if (x % 2 == 1 && y % 2 == 0)
            {
                float a = GameMap.TileShift.Y / GameMap.TileShift.X;
                float b = GameMap.TileShift.Y / 2 * y - a * GameMap.TileShift.X / 2 * x;
                if (v.Y < a * v.X + b)
                    j--;
            }
            else if (x % 2 == 0 && y % 2 == 1)
            {
                float a = GameMap.TileShift.Y / GameMap.TileShift.X;
                float b = GameMap.TileShift.Y / 2 * y - a * GameMap.TileShift.X / 2 * x;
                if (v.Y > a * v.X + b)
                {
                    i--;
                    j++;
                }
            }
            else if (x % 2 == 1 && y % 2 == 1)
            {
                float a = (GameMap.TileShift.Y) / (-GameMap.TileShift.X);
                float b = GameMap.TileShift.Y / 2 * (y + 1) - a * GameMap.TileShift.X / 2 * x;
                if (v.Y > a * v.X + b)
                    j++;
            }

            return new Point(i, j);
        }
Beispiel #10
0
 public void TestConstructor()
 {
     GameMap map = new GameMap(80, 20, 1, 1, new Point(40, 0), new Ball(40, 0));
     Assert.AreEqual(80, map.Width);
     Assert.AreEqual(20, map.Height);
     Assert.IsNotNull(map.GameObjects);
     Assert.IsNotNull(map.GameObjects.Count());
 }
Beispiel #11
0
 public Patrol(GameMap gameMap, List<Fighter> fighters, List<Enemy> enemies, Unit unit, Vector2 p1, Vector2 p2, float wait)
     : base(gameMap, fighters, enemies, unit)
 {
     point1 = p1;
     point2 = p2;
     direction = p1;
     waitTime = wait;
 }
    public float GetFactorForMap(GameMap map)
    {
        float factor = DEFAULT_FACTOR;
        if (factors.ContainsKey(map)) {
            factor = factors[map];
        }

        return factor / relativeFactor;
    }
Beispiel #13
0
    // Use this for initialization
    void Start()
    {
        gameMap = GetComponent<GameMap>();

        spawnBoats = new GameObject[gameMap.map.HumanSpawnPoints.Count];
        waveNumber = 0;

        waveEnd();
    }
        public NonePlayerMovementHandler(float size, Action<Cell[]> setCells, Action<Vector2, Vector2, bool> translate)
        {
            this.size = size;
            this.setCells = setCells;
            this.translate = translate;

            cellSize = GameConst.UNITS_PER_CELL;
            map = GameMap.I;
        }
 public void Dispose()
 {
     disposed = true;
     gamemap = null;
     handler = null;
     if (items != null)
         items.Clear();
     delayedTriggeringUsers.Clear();
 }
 public void Awake()
 {
     instance = this;
     mapTransform = transform.FindChild("Map");
     GameMap = spawmer.GenerateGameMap();
     GenerateGameCharacter();
     PlaceGameCharactersOnMap();
     //GenerateCombatMenuUI
     //ActivateFirstPlayer
 }
Beispiel #17
0
    public static GameObject CreateAgent(GameObject agent, Vector3 location, Quaternion rotation, GameMap gameMap, Genome genome)
    {
        GameObject newAgent = Agent.CreateAgent(agent, location, rotation, gameMap);

        TrainingAgent ta = newAgent.GetComponent<TrainingAgent>();

        ta.brain = genome;

        return newAgent;
    }
Beispiel #18
0
        public void TestAddGameObject_Player()
        {
            GameMap map = new GameMap(80, 20, 1, 1, new Point(40, 0), new Ball(40, 0));
            IGameObject ball = new Ball(1, 1);
            map.AddGameObject(ball);

            IGameObject lastGameObject = map.GameObjects.Last();
            Assert.AreSame(lastGameObject, ball);
            Assert.AreSame(map, ball.Map);
        }
 public ToggleItemState(GameMap gamemap, WiredHandler handler, List<RoomItem> items, int delay, RoomItem Item)
 {
     this.item = Item;
     this.gamemap = gamemap;
     this.handler = handler;
     this.items = items;
     this.delay = delay;
     this.cycles = 0;
     this.delayedTriggeringUsers = new Queue();
     this.disposed = false;
 }
 public void Dispose()
 {
     disposed = true;
     gamemap = null;
     handler = null;
     if (items != null)
         items.Clear();
     items = null;
     if (delayedUsers != null)
         delayedUsers.Clear();
 }
Beispiel #21
0
        protected Object Collision(GameMap gameMap, List<Fighter> fighters, List<Enemy> enemies)
        {
            int i = position.GetMapPosition(gameMap).X;
            int j = position.GetMapPosition(gameMap).Y;

            for (int k = -1; k <= 1; k++)
            {
                for (int l = -1; l <= 1; l++)
                {
                    if (i + k >= 0 && j + l >= 0 && i + k < gameMap.width && j + l < gameMap.height)
                    {
                        foreach (var mo in gameMap.mapTiles[i + k][j + l].mapObjects)
                        {
                            if ((j + l) % 2 == 0)
                            {
                                if (mo.boundaries.Intersects(boundaries + position)) return mo;
                            }
                            else
                            {
                                if (mo.boundaries.Intersects(boundaries + position)) return mo;
                            }
                        }
                    }
                }
            }

            Boundaries b;
            List<Vector2> points = new List<Vector2>();

            points.Add(new Vector2(-5, -25));
            points.Add(new Vector2(5, -25));
            points.Add(new Vector2(5, 0));
            points.Add(new Vector2(-5, 0));

            b = Boundaries.CreateFromPoints(points);

            if (faction == Faction.Enemies)
                foreach (Fighter f in fighters)
                {
                    //if ((boundaries + position).Intersects(f.boundaries + f.position + new Vector2(0, -15)))
                    if (f.IsAlive && (boundaries + position).Intersects(b + f.position))
                        return f;
                }

            if (faction == Faction.Fighters)
                foreach (Enemy e in enemies)
                {
                    //if ((boundaries + position).Intersects(e.boundaries + e.position + new Vector2(0,-15)))
                    if (e.IsAlive && (boundaries + position).Intersects(b + e.position))
                        return e;
                }

            return null;
        }
Beispiel #22
0
    public static GameObject CreateAgent(GameObject agent, Vector3 location, Quaternion rotation, GameMap gameMap)
    {
        GameObject newAgent = Instantiate(agent, location, rotation) as GameObject;
        Agent agentScript = newAgent.GetComponent<Agent>();

        agentScript.gameMap = gameMap;
        agentScript.map = gameMap.map;
        agentScript.grid = gameMap.grid;

        return newAgent;
    }
Beispiel #23
0
 public GameMap GetConnectedMap(GameMap current)
 {
     if (current == GameMapA)
     {
         return GameMapB;
     }
     else
     {
         return GameMapA;
     }
 }
 public TeleportToItem(GameMap gamemap, WiredHandler handler, List<RoomItem> items, int delay, uint itemID)
 {
     this.gamemap = gamemap;
     this.handler = handler;
     this.items = items;
     this.delay = delay+2;
     this.itemID = itemID;
     this.cycles = 0;
     this.delayedUsers = new Queue();
     this.rnd = new Random();
     this.disposed = false;
 }
Beispiel #25
0
        public IGame CreateGame(string gameDir, GameMode mode, GameMap map)
        {
            MyTraceContext.ThreadTraceContext = new MyTraceContext("Server");

            WorldTickMethod tickMethod;

            switch (mode)
            {
                case GameMode.Fortress:
                    tickMethod = WorldTickMethod.Simultaneous;
                    break;

                case GameMode.Adventure:
                    tickMethod = WorldTickMethod.Sequential;
                    break;

                default:
                    throw new Exception();
            }

            var world = new World(mode, tickMethod);

            Action<World> worldCreator;

            switch (map)
            {
                case GameMap.Fortress:
                    worldCreator = Fortress.MountainWorldCreator.InitializeWorld;
                    break;

                case GameMap.Adventure:
                    var dwc = new Fortress.DungeonWorldCreator(world);
                    worldCreator = dwc.InitializeWorld;
                    break;

                case GameMap.Arena:
                    throw new Exception();

                default:
                    throw new Exception();
            }

            world.Initialize(delegate
            {
                worldCreator(world);
            });

            var engine = new GameEngine(world, mode);

            InitGame(engine, gameDir);

            return engine;
        }
Beispiel #26
0
        public void TestCanBePlaced_Player()
        {
            GameMap map = new GameMap(80, 20, 1, 1, new Point(40, 0), new Ball(40, 0));
            IGameObject diamond = new Diamond(GameBonus.Average ,1, 1);
            map.AddGameObject(diamond);

            Assert.IsTrue(map.CanBePlaced(diamond, 0, 0));
            Assert.IsTrue(map.CanBePlaced(diamond, 9, 4));
            Assert.IsTrue(map.CanBePlaced(diamond, 2, 1));

            Assert.IsFalse(map.CanBePlaced(diamond, -1, 0));
            Assert.IsFalse(map.CanBePlaced(diamond, 0, -1));
            Assert.IsFalse(map.CanBePlaced(diamond, 90, 0));
        }
 public void generateMap(int mapNumber)
 {
     gameMap = new GameMap(mapNumber);
     player = GameObject.Find("character"); //Generating the character
     player.transform.position = new Vector3(gameMap.spawn.x, 1, gameMap.spawn.y);
     generateWalls();
     generateFloor();
     generateDoors();
     generateMonsters();
     //Generating end of level
     GameObject levelEnd = (GameObject)Instantiate(Resources.Load("Prefabs/levelEnd"));
     levelEnd.transform.position = new Vector3(gameMap.end.x, 1.5F, gameMap.end.y);
     GameObject subtitle = GameObject.Find("subtitle");
     subtitle.GetComponent<Text>().text = gameMap.endPhrase;
 }
        public GlobalItemSpawnerAgent(GameMap map, GlobalItemSpawnerData.Agent data)
        {
            this.map = map;

            minCountPerTurn = data.minCountPerTurn;
            maxCountPerTurn = data.maxCountPerTurn;

            limitCount = data.limitCount;
            unlimitCount = limitCount == 0;

            limitDistanceFromCenter = data.limitDistanceFromCenter;
            unlimitDistanceFromCenter = limitDistanceFromCenter == 0;

            itemPrototype = data.Item;
        }
Beispiel #29
0
    public void Init()
    {
        hud = GetComponent<Hud>();
        hud.Init();

        grid = GetComponent<GameGrid>();
        grid.Init(this);

        map = GetComponent<GameMap>();
        map.Init(this, grid, hud);

        collectables = new List<Collectable>();

        paused = false;
    }
Beispiel #30
0
    //function to check path for shoot()
    public int checkPath(int start, int stop, GameMap m)
    {
        bool goodPath = false;
            if (m.isAdjacent(start, stop))    //if the next room is adjacent
            {
                goodPath = true;        //path is good
            }

            if (goodPath)   //if next room is adjacent
                return stop;//don't change it
            else
            {
                Random r = new Random();    //room wasn't adjacent
                int[] choose = m.getAdjacent(start);
                return choose[r.Next(3)]; //so pick a random room that is adjacent
            }
    }
Beispiel #31
0
    public static Cell FindPlayerCoordinates(this GameMap gm, CharacterObservable player)
    {
        var cells = gm.CellGameMap.Cast <Cell>().ToList();

        return(cells.FirstOrDefault(c => c.gridPosition == player.CurrentCoordinates.gridPosition));
    }
Beispiel #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameMapInfoAdapter"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 /// <param name="players">The players.</param>
 public GameMapInfoAdapter(GameMap map, IEnumerable <Player> players)
 {
     this.map     = map;
     this.players = players;
 }
Beispiel #33
0
 public ActionComponent(GameMap map)
 {
     Map = map;
 }
Beispiel #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NonPlayerCharacter"/> class.
 /// </summary>
 /// <param name="spawnInfo">The spawn information.</param>
 /// <param name="stats">The stats.</param>
 /// <param name="map">The map on which this instance will spawn.</param>
 public NonPlayerCharacter(MonsterSpawnArea spawnInfo, MonsterDefinition stats, GameMap map)
 {
     this.SpawnArea  = spawnInfo;
     this.Definition = stats;
     this.CurrentMap = map;
 }
        public bool Act(Monster monster, CommandSystem commandSystem)
        {
            GameMap     map        = Game.Map;
            Player      player     = Game.Player;
            FieldOfView monsterFov = new FieldOfView(map);

            // If the monster has not been alerted, compute a field-of-view
            // Use the monster's Awareness value for the distance in the FoV check
            // If the player is in the monster's FoV then alert it
            // Add a message to the MessageLog regarding this alerted status
            if (!monster.TurnsAlerted.HasValue)
            {
                monsterFov.ComputeFov(monster.X, monster.Y, monster.Awareness, true);
                if (monsterFov.IsInFov(player.X, player.Y))
                {
                    Game.MessageLog.Add($"{monster.Name} a envie de combattre {player.Name}");
                    monster.TurnsAlerted = 1;
                }
            }

            if (monster.TurnsAlerted.HasValue)
            {
                // Before we find a path, make sure to make the monster and player Cells walkable
                map.SetIsWalkable(monster.X, monster.Y, true);
                map.SetIsWalkable(player.X, player.Y, true);

                PathFinder pathFinder = new PathFinder(map);
                Path       path       = null;

                try
                {
                    path = pathFinder.ShortestPath(map.GetCell(monster.X, monster.Y), map.GetCell(player.X, player.Y));
                }
                catch (PathNotFoundException)
                {
                    // The monster can see the player, but cannot find a path to him
                    // This could be due to other monsters blocking the way
                    // Add a message to the message log that the monster is waiting
                    Game.MessageLog.Add($"{monster.Name} waits for a turn");
                }

                // Don't forget to set the walkable status back to false

                map.SetIsWalkable(monster.X, monster.Y, false);
                map.SetIsWalkable(player.X, player.Y, false);

                // In the case that there was a path, tell the CommandSystem to move the monster
                if (path != null)
                {
                    try
                    {
                        // Take the first step of the path
                        commandSystem.MoveMonster(monster, path.StepForward());
                    }
                    catch (NoMoreStepsException)
                    {
                        Game.MessageLog.Add($"{monster.Name} growls in frustration");
                    }
                }

                monster.TurnsAlerted++;

                // Lose alerted status every 15 turns.
                // As long as the player is still in FoV the monster will stay alert
                // Otherwise the monster will quit chasing the player.
                if (monster.TurnsAlerted > 15)
                {
                    monster.TurnsAlerted = null;
                }
            }
            return(true);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BasicMonsterIntelligence"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 public BasicMonsterIntelligence(GameMap map)
 {
     this.map = map;
 }
Beispiel #37
0
 public GameRoundProcessor(int round, GameMap gameMap, ILogger logger)
     : this(round, gameMap, logger, Settings.Default.PointsPlayer)
 {
 }
Beispiel #38
0
 public GameBlockEnumerator(GameMap gameMap)
 {
     _gameMap = gameMap;
     Reset();
 }
Beispiel #39
0
 public override void GenerateMap(GameMap map, Creature.Player player)
 {
     base.GenerateMap(map, player);
 }
Beispiel #40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttackAreaWhenPressedTrapIntelligence"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 public AttackAreaWhenPressedTrapIntelligence(GameMap map)
     : base(map)
 {
 }
Beispiel #41
0
    public static IEnumerable <bool> AreInRange(this GameMap gm, CharacterObservable self, params CharacterObservable[] characters)
    {
        var inRange = characters.Select(ch => IsInRange(gm, self, ch)).ToList();

        return(inRange);
    }
Beispiel #42
0
 public static IEnumerable <CharacterObservable> PlayersInRange(this GameMap gm, CharacterObservable self,
                                                                params CharacterObservable[] players)
 {
     return(players.Where(player => InRange(gm, self, player)));
 }
Beispiel #43
0
 public static bool IsTargetPositionAdjacentToSelf(this GameMap gm, Cell currentPos, Cell targetCell)
 {
     return(GetValidCardinalCells(gm, currentPos).Any((
                                                          cc => cc.gridPosition.x == targetCell.gridPosition.x && cc.gridPosition.y == targetCell.gridPosition.y)));
 }
 public SearchManager(Game game, Strategy strategy)
 {
     _game     = game;
     _gameMap  = _game.GameMap;
     _strategy = strategy;
 }
Beispiel #45
0
    public void UpdateUnit(UnitDefinition unit)
    {
        bool needsRegen = false;

        if ((MatPairStruct)this.unit.race != unit.race)
        {
            race       = CreatureRaws.Instance[unit.race.mat_type];
            caste      = race.caste[unit.race.mat_index];
            needsRegen = true;
        }
        if (oldWounds != null || unit.wounds != null)
        {
            if (oldWounds == null && unit.wounds != null)
            {
                needsRegen = true;
            }
            else if (oldWounds != null && unit.wounds == null)
            {
                needsRegen = true;
            }
            else if (oldWounds.Count != unit.wounds.Count)
            {
                needsRegen = true;
            }
            else
            {
                for (int i = 0; i < unit.wounds.Count; i++)
                {
                    if (oldWounds[i].severed_part != unit.wounds[i].severed_part)
                    {
                        needsRegen = true;
                        break;
                    }
                    if (oldWounds[i].parts.Count != unit.wounds[i].parts.Count)
                    {
                        needsRegen = true;
                        break;
                    }
                }
            }
        }
        oldWounds = unit.wounds;
        this.unit = unit;
        if (needsRegen || oldChibiSize != GameSettings.Instance.units.chibiness || oldScaleUnits != GameSettings.Instance.units.scaleUnits)
        {
            oldScaleUnits = GameSettings.Instance.units.scaleUnits;
            oldChibiSize  = GameSettings.Instance.units.chibiness;
            MakeBody();
        }

        if (((UnitFlags1)unit.flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground)
        {
            if (!onGround)
            {
                rootPart.transform.localRotation = Quaternion.Euler(90, 0, 0);
                rootPart.transform.localPosition = new Vector3(0, bounds.max.z, 0);
                onGround = true;
            }
        }
        else
        {
            if (onGround)
            {
                rootPart.transform.localRotation = Quaternion.identity;
                rootPart.transform.localPosition = new Vector3(0, -bounds.min.y, 0);
                onGround = false;
            }
        }
        if (unit.facing != null && GameMap.DFtoUnityDirection(unit.facing).sqrMagnitude > 0 && unit.rider_id < 0)
        {
            transform.rotation = Quaternion.LookRotation(GameMap.DFtoUnityDirection(unit.facing));
        }
        else if (unit.rider_id >= 0)
        {
            transform.rotation = Quaternion.identity;
        }

        if (InventoryChanged(unit.inventory))
        {
            foreach (var part in spawnedParts)
            {
                part.Value.inventory.Clear();
            }
            //Here we add pants first before shirts because otherwise the layering looks bad.
            foreach (var item in unit.inventory)
            {
                if (!ClothingTexture.GetTexture(item.item.type).isDress)
                {
                    AddInventoryItem(item);
                }
            }
            foreach (var item in unit.inventory)
            {
                if (ClothingTexture.GetTexture(item.item.type).isDress)
                {
                    AddInventoryItem(item);
                }
            }
            foreach (var part in spawnedParts)
            {
                part.Value.UpdateItems(unit);
            }
        }
    }
Beispiel #46
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RandomAttackInRangeTrapIntelligence"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 public RandomAttackInRangeTrapIntelligence(GameMap map)
     : base(map)
 {
 }
Beispiel #47
0
    IEnumerator DrawParticles()
    {
        while (true)
        {
            foreach (var item in flowTypes)
            {
                if (!flowParticles.ContainsKey(item.Key))
                {
                    var child = transform.Find(item.Key.ToString());
                    if (child == null)
                    {
                        if (!warningGiven.Contains(item.Key))
                        {
                            Debug.LogError("No particle system for " + item.Key);
                            warningGiven.Add(item.Key);
                        }
                        continue;
                    }
                    var particle = child.GetComponent <ParticleSystem>();
                    if (particle == null)
                    {
                        if (!warningGiven.Contains(item.Key))
                        {
                            Debug.LogError("Malformed particle system for " + item.Key);
                            warningGiven.Add(item.Key);
                        }
                        continue;
                    }
                    flowParticles[item.Key] = particle;
                }
                foreach (var particle in item.Value)
                {
                    if (!GameMap.IsInVisibleArea(particle.pos))
                    {
                        continue;
                    }
                    var emitParams = new ParticleSystem.EmitParams();
                    emitParams.position = GameMap.DFtoUnityTileCenter(particle.pos);
                    Color color = Color.white;
                    switch (item.Key)
                    {
                    case FlowType.Dragonfire:
                        color = ColorTemperature.Color(Mathf.Lerp(dragonColorTempMin, dragonColorTempMax, particle.density / 100.0f));
                        break;

                    case FlowType.Miasma:
                    case FlowType.Steam:
                    case FlowType.Mist:
                    case FlowType.Smoke:
                    case FlowType.MagmaMist:
                    case FlowType.CampFire:
                    case FlowType.Fire:
                    case FlowType.OceanWave:
                    case FlowType.SeaFoam:
                        color = Color.white;
                        break;

                    case FlowType.ItemCloud:
                        color = ContentLoader.GetColor(particle.item, particle.material);
                        flowParticles[item.Key].customData.SetVector(ParticleSystemCustomData.Custom1, 0, new ParticleSystem.MinMaxCurve(ImageManager.Instance.GetItemTile(particle.item)));
                        flowParticles[item.Key].customData.SetVector(ParticleSystemCustomData.Custom1, 1, new ParticleSystem.MinMaxCurve(ContentLoader.GetPatternIndex(particle.material)));
                        break;

                    case FlowType.MaterialGas:
                    case FlowType.MaterialVapor:
                    case FlowType.MaterialDust:
                    case FlowType.Web:
                    default:
                        color = ContentLoader.GetColor(particle.material);
                        break;
                    }
                    if (item.Key == FlowType.ItemCloud)
                    {
                        if (UnityEngine.Random.Range(0, 100) > particle.density)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        color.a = particle.density / 100f;
                    }
                    emitParams.startColor           = color;
                    emitParams.applyShapeToPosition = true;
                    flowParticles[item.Key].Emit(emitParams, 1);
                }
            }
            yield return(new WaitForSeconds(updateRate));
        }
    }
 void Awake()
 {
     gameMap = FindObjectOfType <GameMap>();
 }
Beispiel #49
0
    //Dictionary<string, Texture2D> diffuseTextures = new Dictionary<string, Texture2D>();
    //Dictionary<string, Texture2D> specularTextures = new Dictionary<string, Texture2D>();
    //Dictionary<string, geometry> geometryLibrary = new Dictionary<string, geometry>();
    //List<node> nodeList = new List<node>();

    //this is very similar to the blockmesher function.
    void CollectModel(MapDataStore.Tile tile, MeshLayer layer, DFCoord pos)
    {
        if (layer == MeshLayer.Collision)
        {
            return;
        }

        #region Mesh Selection
        MeshContent meshContent = null;
        switch (layer)
        {
        case MeshLayer.GrowthMaterial:
        case MeshLayer.GrowthMaterial1:
        case MeshLayer.GrowthMaterial2:
        case MeshLayer.GrowthMaterial3:
        case MeshLayer.GrowthCutout:
        case MeshLayer.GrowthCutout1:
        case MeshLayer.GrowthCutout2:
        case MeshLayer.GrowthCutout3:
        case MeshLayer.GrowthTransparent:
        case MeshLayer.GrowthTransparent1:
        case MeshLayer.GrowthTransparent2:
        case MeshLayer.GrowthTransparent3:
        {
            switch (tile.tiletypeMaterial)
            {
            case TiletypeMaterial.PLANT:
            case TiletypeMaterial.ROOT:
            case TiletypeMaterial.TREE_MATERIAL:
            case TiletypeMaterial.MUSHROOM:
                if (!ContentLoader.Instance.GrowthMeshConfiguration.GetValue(tile, layer, out meshContent))
                {
                    return;
                }
                break;

            default:
                return;
            }
        }
        break;

        //case MeshLayer.BuildingMaterial:
        //case MeshLayer.NoMaterialBuilding:
        //case MeshLayer.BuildingMaterialCutout:
        //case MeshLayer.NoMaterialBuildingCutout:
        //case MeshLayer.BuildingMaterialTransparent:
        //case MeshLayer.NoMaterialBuildingTransparent:
        //    {
        //        if (tile.buildingType == default(BuildingStruct))
        //            return;
        //        if (!ContentLoader.Instance.BuildingMeshConfiguration.GetValue(tile, layer, out meshContent))
        //            return;
        //    }
        //    break;
        default:
        {
            if (!ContentLoader.Instance.TileMeshConfiguration.GetValue(tile, layer, out meshContent))
            {
                return;
            }
        }
        break;
        }

        if (!meshContent.MeshData.ContainsKey(layer))
        {
            return;
        }
        #endregion

        node tileNode = new node();

        tileNode.id = string.Format("Tile[{0},{1},{2}]_{3}", pos.x, pos.y, pos.z, layer);

        tileNode.Items = new object[]
        {
            COLLADA.ConvertMatrix(Matrix4x4.TRS(
                                      GameMap.DFtoUnityCoord(pos),
                                      meshContent.GetRotation(tile),
                                      Vector3.one))
        };
        tileNode.ItemsElementName = new ItemsChoiceType2[] { ItemsChoiceType2.matrix };

        //string geometryName = "Mesh-" + meshContent.UniqueIndex;

        //if (!geometryLibrary.ContainsKey(geometryName))
        //{
        //    geometryLibrary[geometryName] = COLLADA.MeshToGeometry(meshContent.MeshData[layer], geometryName);
        //}

        //instance_geometry geometryInstance = new instance_geometry();
        //geometryInstance.url = "#" + geometryLibrary[geometryName].id;
        //tileNode.instance_geometry = new instance_geometry[] { geometryInstance };

        //nodeList.Add(tileNode);
        //return;
        //-----------------------------------------------------------
        //Put normal map stuff here! Remember!
        //-----------------------------------------------------------


        //string patternName = "Tex-";

        //Texture2D tiletexture = null;
        //TextureContent textureContent;
        //if (ContentLoader.Instance.MaterialTextureConfiguration.GetValue(tile, layer, out textureContent))
        //{
        //    tiletexture = textureContent.Texture;
        //    patternName += textureContent.UniqueIndex;
        //}
        //else patternName += "#";

        //patternName += "-#";

        //Color color = Color.grey;
        //ColorContent colorContent;
        //if (ContentLoader.Instance.ColorConfiguration.GetValue(tile, layer, out colorContent))
        //{
        //    color = colorContent.color;
        //}

        //patternName += string.Format("{0:X2}{1:X2}{2:X2}", ((Color32)color).r, ((Color32)color).g, ((Color32)color).b);

        //if (diffuseTextures.ContainsKey(patternName))
        //    return;

        //Color neutralSpec = new Color(0.04f, 0.04f, 0.04f);
        //Texture2D outputDiffuse;
        //Texture2D outputSpec;
        //if (tiletexture != null)
        //{
        //    outputDiffuse = new Texture2D(tiletexture.width, tiletexture.height);
        //    outputSpec = new Texture2D(tiletexture.width, tiletexture.height);
        //    Color[] colors = tiletexture.GetPixels();
        //    Color[] specs = new Color[colors.Length];
        //    for (int i = 0; i < colors.Length; i++)
        //    {
        //        var diffuseColor = OverlayBlend(colors[i], color);
        //        diffuseColor.a = 1;
        //        colors[i] = Color.Lerp(Color.black, diffuseColor, color.a);
        //        specs[i] = Color.Lerp(diffuseColor, neutralSpec, color.a);
        //    }
        //    outputDiffuse.SetPixels(colors);
        //    outputSpec.SetPixels(specs);
        //}
        //else
        //{
        //    outputDiffuse = ContentLoader.CreateFlatTexture(color);
        //    outputSpec = ContentLoader.CreateFlatTexture(neutralSpec);
        //}
        //outputDiffuse.name = patternName + "_Diffuse";
        //outputSpec.name = patternName + "_Specular";

        //diffuseTextures[patternName] = outputDiffuse;
        //specularTextures[patternName] = outputSpec;
    }
    public CollisionState CheckCollision(Vector3 pos)
    {
        var dfPos    = GameMap.UnityToDFCoord(pos);
        var localPos = pos - GameMap.DFtoUnityCoord(dfPos);
        var tile     = this[dfPos];

        if (tile == null)
        {
            return(CollisionState.None);
        }
        var shape = tile.shape;

        var state = CollisionState.None;

        switch (shape)
        {
        case TiletypeShape.NO_SHAPE:
        case TiletypeShape.EMPTY:
        case TiletypeShape.ENDLESS_PIT:
        case TiletypeShape.TWIG:
            state = CollisionState.None;
            break;

        case TiletypeShape.FLOOR:
        case TiletypeShape.BOULDER:
        case TiletypeShape.PEBBLES:
        case TiletypeShape.BROOK_TOP:
        case TiletypeShape.SAPLING:
        case TiletypeShape.SHRUB:
        case TiletypeShape.BRANCH:
        case TiletypeShape.TRUNK_BRANCH:
            if (localPos.y < 0.5f)
            {
                state = CollisionState.Solid;
            }
            else
            {
                state = CollisionState.None;
            }
            break;

        case TiletypeShape.WALL:
        case TiletypeShape.FORTIFICATION:
        case TiletypeShape.BROOK_BED:
        case TiletypeShape.TREE_SHAPE:
            state = CollisionState.Solid;
            break;

        case TiletypeShape.STAIR_UP:
            if (localPos.y < 0.5f)
            {
                state = CollisionState.Solid;
            }
            else
            {
                state = CollisionState.Stairs;
            }
            break;

        case TiletypeShape.STAIR_DOWN:
            if (localPos.y < 0.5f)
            {
                state = CollisionState.Stairs;
            }
            else
            {
                state = CollisionState.None;
            }
            break;

        case TiletypeShape.STAIR_UPDOWN:
            state = CollisionState.Stairs;
            break;

        case TiletypeShape.RAMP:
            DFCoord2d dir = SnapDirection(localPos);

            break;

        case TiletypeShape.RAMP_TOP:
            break;

        default:
            break;
        }
        return(state);
    }
Beispiel #51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TrapIntelligenceBase"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 protected TrapIntelligenceBase(GameMap map)
 {
     this.Map = map;
 }
        public void TestSetPlayerCoordinates_SetNegativeCoordinates_GetInvalidParameterException()
        {
            GameMap gameMap = GetTestGameMap();

            gameMap.SetPlayerCoordinates(new Coordinates(-1, -1));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AttackAreaTargetInDirectionTrapIntelligence"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 public AttackAreaTargetInDirectionTrapIntelligence(GameMap map)
     : base(map)
 {
 }
        public void TestSetPlayerCoordinates_SetOutOfBoundsCoordinates_GetInvalidParameterException()
        {
            GameMap gameMap = GetTestGameMap();

            gameMap.SetPlayerCoordinates(new Coordinates(GetTestGameMap().Width + 1, GetTestGameMap().Height + 1));
        }
 public TurnLeftIntentMapModifyer(GameMap currentMap) : base(currentMap)
 {
 }
Beispiel #56
0
        public static void Main(string[] args)
        {
            string name = args.Length > 0 ? args[0] : "Sharpie";

            Networking  networking = new Networking();
            GameMap     gameMap    = networking.Initialize(name);
            List <Move> moveList   = new List <Move>();
            int         myPlanets  = 0;
            int         numScouts  = 0;

            for (; ;)
            {
                moveList.Clear();
                gameMap.UpdateMap(Networking.ReadLineIntoMetadata());

                numScouts = 0;
                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.IsScout())
                    {
                        numScouts++;
                    }
                }

                myPlanets = 0;
                foreach (Planet p in gameMap.GetAllPlanets().Values)
                {
                    if (p.IsOwned() && p.GetOwner() == gameMap.GetMyPlayerId())
                    {
                        myPlanets++;
                    }
                }

                foreach (Ship ship in gameMap.GetMyPlayer().GetShips().Values)
                {
                    if (ship.GetDockingStatus() != Ship.DockingStatus.Undocked)
                    {
                        continue;
                    }

                    // if (numScouts < 1 && !(ship.IsScout()) && (myPlanets > 2))
                    // {
                    //     ship.SetScout(true);
                    //     numScouts++;
                    //     foreach (Planet p in gameMap.GetAllPlanets().Values){
                    //         if ( p.IsOwned() && p.GetOwner() != gameMap.GetMyPlayerId() ){
                    //             ship.SetTargetId(p.GetId());
                    //             break;
                    //         }
                    //     }
                    // }
                    //
                    // if (ship.IsScout())
                    // {
                    //     Planet target = gameMap.GetPlanet(ship.GetTargetId());
                    //     if (target.IsOwned() && target.GetOwner() != gameMap.GetMyPlayerId()) {
                    //         CirclePlanet(gameMap, ship, target, moveList);
                    //         break;
                    //     }
                    //     // else
                    //     // {
                    //     //     ship.SetScout(false);
                    //     //     numScouts--;
                    //     //     if (ship.CanDock(target))
                    //     //     {
                    //     //         moveList.Add(new DockMove(ship, target));
                    //     //         break;
                    //     //     }
                    //     // }
                    // }


                    var sorted = new SortedDictionary <double, Entity>(gameMap.NearbyEntitiesByDistance(ship));
                    foreach (KeyValuePair <double, Entity> item in sorted)
                    {
                        double distance = item.Key;
                        if (item.Value.GetType() == typeof(Ship) && distance < 80)
                        {
                            Ship targetShip = (Ship)item.Value;
                            if (targetShip.GetOwner() == gameMap.GetMyPlayerId())
                            {
                                continue;
                            }
                            else
                            {
                                FuckShipUp(gameMap, ship, targetShip, moveList);
                                break;
                            }
                        }

                        if (item.Value.GetType() == typeof(Planet))
                        {
                            Planet planet = (Planet)item.Value;
                            if (planet.IsOwned() && planet.GetOwner() != gameMap.GetMyPlayerId())
                            {
                                bool noMorePlanet = true;
                                foreach (Planet p in gameMap.GetAllPlanets().Values)
                                {
                                    if (!p.IsOwned())
                                    {
                                        noMorePlanet = false;
                                        break;
                                    }
                                }
                                if (noMorePlanet)
                                {
                                    // FuckPlanetUp(gameMap, ship, planet, moveList);
                                    CirclePlanet(gameMap, ship, planet, moveList);
                                    break;
                                }
                                continue;
                            }
                            else if (planet.IsOwned() && planet.IsFull())
                            {
                                // Can add guards to defend
                                // Random rnd = new Random();
                                // if (rnd.Next(1,10) > 9){
                                //     CirclePlanet(gameMap, ship, planet, moveList);
                                //     break;
                                // }
                                continue;
                            }
                            else
                            {
                                //Dock and conquer planet
                                if (ship.CanDock(planet))
                                {
                                    moveList.Add(new DockMove(ship, planet));
                                    break;
                                }

                                ThrustMove newThrustMove = Navigation.NavigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED);
                                if (newThrustMove != null)
                                {
                                    moveList.Add(newThrustMove);
                                }
                                break;
                            }
                        }

                        if (item.Value.GetType() == typeof(Ship))
                        {
                            Ship targetShip = (Ship)item.Value;
                            if (targetShip.GetOwner() == gameMap.GetMyPlayerId())
                            {
                                continue;
                            }
                            else
                            {
                                FuckShipUp(gameMap, ship, targetShip, moveList);
                                break;
                            }
                        }
                    }
                    // foreach (Planet planet in gameMap.GetAllPlanets().Values)
                    // {
                    //     if (planet.IsOwned())
                    //     {
                    //         continue;
                    //     }
                    //
                    //     if (ship.CanDock(planet))
                    //     {
                    //         moveList.Add(new DockMove(ship, planet));
                    //         break;
                    //     }
                    //
                    //     ThrustMove newThrustMove = Navigation.NavigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED / 2);
                    //     if (newThrustMove != null)
                    //     {
                    //         moveList.Add(newThrustMove);
                    //     }
                    //
                    //     break;
                    // }
                }
                Networking.SendMoves(moveList);
            }
        }
 public GameMapRender(GameMap gameMap)
     : this(gameMap, false)
 {
 }
Beispiel #58
0
 public static int GetNumberCharactersBlockingMovement(this GameMap gm, CharacterObservable character)
 {
     return(GetAvailableMoveActions(gm, character).Count(c => c.UseByCharacter));
 }
Beispiel #59
0
 public static bool CanMoveAway(this GameMap gm, CharacterObservable chObs)
 {
     return(GetAvailableMoveActions(gm, chObs).Count(c => c.UseByCharacter) < 4);
 }
 public GameMapRender(GameMap gameMap, bool minify)
 {
     GameMap     = gameMap;
     this.minify = minify;
 }