Ejemplo n.º 1
0
        public ActorDoActionAction(BasicActor actor, HexGrid.HexGrid hexGrid, string actionName, Dictionary <ActionArgs, string> actionArgs)
        {
            ElementName = actionName;
            //make some custom one :TODO
            #region choose texture

            string assetPath = "";
            switch (actionName)
            {
            case "rotateC":
                assetPath = @"Content\UIElements\rotateClockWise.png";
                break;

            case "rotateCC":
                assetPath = @"Content\UIElements\rotateCounterClockWise.png";
                break;

            case "move":
                assetPath = @"Content\UIElements\move.png";
                break;

            default:
                assetPath = @"Modules\" + actionArgs[Actors.ActionArgs.ModuleName] + @"\" + actionArgs[Actors.ActionArgs.Texture];
                break;
            }

            #endregion
            FileStream fs = new FileStream(assetPath, FileMode.Open);
            Texture = Texture2D.FromStream(GraphicsDevice, fs);
            fs.Close();
            HexGrid    = hexGrid;
            Actor      = actor;
            ActionArgs = actionArgs;
        }
Ejemplo n.º 2
0
        public static void CreateActiveActorUIElements(HexGrid.HexGrid hexMap, BasicActor actionableActor)
        {
            if (hexMap.ActiveActor == actionableActor)
            {
                //:TODO dynamically choose formatting, maybe how many other elements a UI element will let share a line with it
                UIGridBag actorActionsUIBag = new UIGridBag(UIGridBagLocationCordinates.Left, new List <int>()
                {
                    1, 2, 1
                });
                ActiveHexUIElements.AvailibleUIElements.Remove(UIGridBagLocations.Left);
                //maybe just loop through, remove all actor related ones, get list first, remove second :TODO

                var placedElementCount = 0;
                hexMap.ActiveActor.DefaultActions.ForEach(a =>
                {
                    UIDrawable actionElement = (ActionHandler.ActionsList.ContainsKey(a)) ?
                                               new ActorDoActionAction(hexMap.ActiveActor, hexMap, a, ActionHandler.ActionsList[a]) :
                                               new ActorDoActionAction(hexMap.ActiveActor, hexMap, a, new Dictionary <ActionArgs, string> {
                        { ActionArgs.Type, a }
                    });
                    actorActionsUIBag.GridElements.Add(actionElement);
                    //:TODO dubious
                    if (actorActionsUIBag.PerRow.Sum() <= placedElementCount)
                    {
                        actorActionsUIBag.PerRow.Add(1);
                    }
                    placedElementCount++;
                });
                ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left] = actorActionsUIBag;
            }
        }
Ejemplo n.º 3
0
        public static void Init(HexGrid.HexGrid hexGrid)
        {
            initialized = true;
            grid        = hexGrid;

            buildings = new List <Building>();

            ressources = new List <Ressource>();

            carts = new List <Cart>();

            foreach (HexCell cell in grid.cells)
            {
                if (cell.Structure != null)
                {
                    AddStructureToList(cell.Structure);
                }
            }
            ComputeConnectedStorages();

            foreach (Building building in buildings)
            {
                if (building is Headquarter)
                {
                    AddTribe(building.Tribe, (Headquarter)building);
                }
            }

            foreach (Building building in buildings)
            {
                Tribe tribe = GetTribe(building.Tribe);
                tribe.AddBuilding(building.GetType());
            }
        }
Ejemplo n.º 4
0
 //any? specific for if selecting non active actor?
 //should also have textures around them
 //also harcoding, bad :TODO
 public static void CreateTextUIElements(HexGrid.HexGrid hexMap, BasicActor actionableActor)
 {
     if (ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left] == null)
     {
         UIGridBag actorActionsUIBag = new UIGridBag(UIGridBagLocationCordinates.Left, new List <int>());
         ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left] = actorActionsUIBag;
     }
     ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left].GridElements.Add(new TextUIElement(hexMap.ActiveActor, TextUIStatics.ActorStats.CurrentHP));
     ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left].PerRow.Add(1);
 }
Ejemplo n.º 5
0
 public BasicActor(HexPoint location, string name, Dictionary <string, string> actorData, int rotation, bool PC, string moduleName, HexGrid.HexGrid hexGrid)
 {
     Name         = name;
     Location     = location;
     Controllable = PC;
     Rotation     = rotation;
     ModuleName   = moduleName;
     ActorHexGrid = hexGrid;
     AsignActorData(actorData);
 }
Ejemplo n.º 6
0
 public ActorDoActionActionEvent(string action, HexGrid.HexGrid hexGrid, Dictionary <ActionArgs, string> actionArgs)
 {
     Action     = action;
     HexGrid    = hexGrid;
     ActionArgs = actionArgs;
 }
Ejemplo n.º 7
0
        public static void TacticalViewMouseHandle(HexGrid.HexGrid hexMap, Camera camera, BasicActor actionableActor)
        {
            //Probably in whatever houses the ActorActions instantiation
            //var actorUi = new ActorActions(new );
            //actorUi.DrawActorActions();

            var conv = Vector2.Transform(MouseCords, Matrix.Invert(camera.Transform));

            var selHex = hexMap.SelectedHex(conv);

            hexMap.HexStorage.ToList().ForEach(h => h.Value.Hovered = false);
            //:TODO also annoying
            if (selHex != null)
            {
                Debugger.Log("Hover Hex " + selHex.R + ", " + selHex.Q);

                // :TODO this is annoying to do
                hexMap.HexStorage.Where(h => h.Key.Equals(selHex)).First().Value.Hovered = true;
            }
            if (CompletedClick /*mouseInfo.MouseState.LeftButton == ButtonState.Pressed*/)
            {
                //Debug.Log("Clicked ScreenCords " + MouseCords.X + ", " + MouseCords.Y);
                //Debug.Log("Clicked MouseCords " + conv.X + ", " + conv.Y);

                foreach (var bag in ActiveHexUIElements.AvailibleUIElements)
                {
                    foreach (var visibleElement in bag.Value.GridElements)
                    {
                        Vector2 elementLoc = Vector2.Transform(visibleElement.StartV,
                                                               Matrix.Invert(camera.Transform));
                        Vector2 elementSize = visibleElement.Size;
                        if (conv.X >= elementLoc.X && conv.Y >= elementLoc.Y && conv.X <= elementLoc.X + elementSize.X &&
                            conv.Y <= elementLoc.Y + elementSize.Y)
                        {
                            visibleElement.OnClick();
                            return;
                        }
                    }
                }

                if (selHex != null)
                {
                    var hexKey =
                        hexMap.HexStorage.FirstOrDefault(h => h.Key.Equals(selHex));
                    var actorKey =
                        hexMap.ActorStorage.FirstOrDefault(actor => actor.Location.Equals(selHex));
                    //probably should be moved somewhere
                    hexMap.UnHighlightAll();
                    if (hexKey.Key != null)
                    {
                        hexMap.ActiveHex = hexKey;
                    }

                    if (hexMap.ActiveActor != null && hexMap.ActiveActor.Controllable)
                    {
                        hexKey.Value.Highlighted = true;
                        var seeable = hexMap.ActiveActor.CanSee();
                        hexMap.HighlightHexes(seeable);
                        #region create actor UI elements


                        //UIGridBag -> where do we put it
                        //show some text ui stats if not actionable :TODO
                        CreateActiveActorUIElements(hexMap, actionableActor);
                        CreateTextUIElements(hexMap, actionableActor);

                        #endregion
                    }
                    if (hexMap.ActiveActor == null)
                    {
                        hexMap.ActiveActor = actorKey;
                    }
                }
            }
            //temp, not all conditions for UI in, remove :TODO
            if (MouseState.RightButton == ButtonState.Pressed)
            {
                hexMap.ActiveHex   = new KeyValuePair <HexPoint, Hex>();
                hexMap.ActiveActor = null;
                ActiveHexUIElements.AvailibleUIElements.Remove(UIGridBagLocations.Left);
                hexMap.UnHighlightAll();
            }
        }
Ejemplo n.º 8
0
 public AIController(HexGrid.HexGrid hexgrid)
 {
     HexGrid = hexgrid;
 }
Ejemplo n.º 9
0
        public MapGenerator(float lat, float lon, int size)
        {
            LONGITUDE = lon;
            LATITUDE  = lat;

            TILE_COUNT_X = size;
            TILE_COUNT_Z = size;

            IMAGE_WIDTH  = size * SINGLE_IMAGE_WIDTH;
            IMAGE_HEIGHT = size * SINGLE_IMAGE_HEIGHT;

            CHUNK_COUNT_X = TILE_COUNT_X * CHUNKS_PER_TILE_X;
            CHUNK_COUNT_Z = TILE_COUNT_Z * CHUNKS_PER_TILE_Z;

            CELL_COUNT_X = CHUNK_COUNT_X * HexMetrics.chunkSizeX;
            CELL_COUNT_Z = CHUNK_COUNT_Z * HexMetrics.chunkSizeZ;

            CELL_COUNT = CELL_COUNT_X * CELL_COUNT_Z;

            HEX_WIDTH  = HexMetrics.innerRadius + 2f * HexMetrics.innerRadius * (float)CELL_COUNT_X;
            HEX_HEIGHT = 0.5f * HexMetrics.outerRadius + 1.5f * HexMetrics.outerRadius * (float)CELL_COUNT_Z;


            float cornerLon = (float)Slippy.tilex2long((Slippy.long2tilex(LONGITUDE, MapboxHandler.ZOOM) - TILE_COUNT_X / 2), MapboxHandler.ZOOM);
            float deltaLon  = TILE_COUNT_X * Math.Abs((float)Slippy.tilex2long(Slippy.long2tilex(LONGITUDE, MapboxHandler.ZOOM), MapboxHandler.ZOOM) - (float)Slippy.tilex2long((Slippy.long2tilex(LONGITUDE, MapboxHandler.ZOOM) + 1), MapboxHandler.ZOOM));

            float deltaLat  = TILE_COUNT_Z * Math.Abs((float)Slippy.tiley2lat(Slippy.lat2tiley(LATITUDE, MapboxHandler.ZOOM), MapboxHandler.ZOOM) - (float)Slippy.tiley2lat((Slippy.lat2tiley(LATITUDE, MapboxHandler.ZOOM) + 1), MapboxHandler.ZOOM));
            float cornerLat = (float)Slippy.tiley2lat((Slippy.lat2tiley(LATITUDE, MapboxHandler.ZOOM) + TILE_COUNT_Z / 2 + 1), MapboxHandler.ZOOM) + 0.5f * ((HEX_WIDTH - HEX_HEIGHT) / HEX_WIDTH) * deltaLat;

            /*
             * Console.WriteLine(cornerLon);
             * Console.WriteLine(cornerLat);
             *
             * Console.WriteLine(cornerLon + deltaLon);
             * Console.WriteLine(cornerLat + deltaLat);
             *
             * Console.WriteLine(0.5f * ((HEX_WIDTH - HEX_HEIGHT) / HEX_WIDTH) * deltaLat);
             */
            hexGrid = new HexGrid.HexGrid(CHUNK_COUNT_X, CHUNK_COUNT_Z, cornerLon, cornerLat, deltaLon, (HEX_HEIGHT / HEX_WIDTH) * deltaLat);

            waterAreas = new List <List <HexCell> >();

            random = new Random();

            cellQueryThresholds = new Dictionary <HexCellBiome, int>();
            foreach (HexCellBiome biome in Enum.GetValues(typeof(HexCellBiome)))
            {
                cellQueryThresholds.Add(biome, 4);
            }

            biomeThresholds = new Dictionary <HexCellBiome, Tuple <int, int> >
            {
                { HexCellBiome.FOREST, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.SCRUB, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.GRASS, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.CROP, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.COAL, new Tuple <int, int>((int)(0.02f * CELL_COUNT), (int)(0.1f * CELL_COUNT)) },
                { HexCellBiome.ROCK, new Tuple <int, int>((int)(0.04f * CELL_COUNT), (int)(0.4f * CELL_COUNT)) },
                { HexCellBiome.CITY, new Tuple <int, int>((int)(0.1f * CELL_COUNT), (int)(0.2f * CELL_COUNT)) },
                { HexCellBiome.BUILDINGS, new Tuple <int, int>((int)(0.05f * CELL_COUNT), (int)(0.2f * CELL_COUNT)) },
                { HexCellBiome.WATER, new Tuple <int, int>((int)(0.005f * CELL_COUNT), (int)(0.1f * CELL_COUNT)) }
            };

            /*
             * parsedRessources = new int[Enum.GetValues(RessourceType).Length];
             * ressourceThresholds = new Dictionary<Type, int>{
             *  { RessourceType.COAL, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.WOOD, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.WHEAT, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.FISH, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.IRON_ORE, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             *  { RessourceType.COAL, new Tuple<int, int>((int)(0.005f * CELL_COUNT), (int)(0.01f * CELL_COUNT)) },
             * }
             */
        }