public void ShowRes(PanelBuilder panel, Player player, NVector pos) { //addHeader if (pos != null && GameMgmt.Get().data.map.levels[pos.level].ResGenKey(pos.x, pos.y) != null && player != null && player.overlay.Get("res", pos) == 1) { panel.AddHeaderLabelT("res"); foreach (string key in GameMgmt.Get().data.map.levels[pos.level].ResGenKey(pos.x, pos.y)) { if (S.Debug()) { panel.AddHeaderLabel(key); panel.AddInput(key, GameMgmt.Get().data.map.ResGen(pos, key), val => GameMgmt.Get().data.map.ResGenAdd(pos, key, val - GameMgmt.Get().data.map.ResGen(pos, key))); continue; } L.b.res[key].AddImageLabel(panel, L.b.terrains.GenDesc(GameMgmt.Get().data.map.ResGen(pos, key))); } return; } if (res.Count > 0) { panel.AddHeaderLabelT("resInclude"); foreach (KeyValuePair <string, string> r in res) { int chance = ResChance(r.Key); var c = ResRange(r.Key); string txt = S.T("resCountRange", L.b.terrains.GenDesc(c.min), L.b.terrains.GenDesc(c.max)); L.b.res[r.Key].AddImageLabel(panel, chance >= 1 ? S.T("resCountChance", chance, txt) : txt); } } }
/// <summary> /// Get a start position or an exception /// </summary> /// <param name="nation"></param> /// <returns></returns> /// <exception cref="System.MissingMemberException"></exception> public NVector GetStartPos(string nation) { GameMapData gmap = GameMgmt.Get().data.map; Nation n = L.b.nations[nation]; int i = 0; while (i < 1000) { int x = Random.Range(0, gmap.width); int y = Random.Range(0, gmap.height); DataTerrain t = _map.Terrain(new NVector(x, y, gmap.standard)); //right terrain? //TODO && t.visible > 0 if (t.id == n.Terrain || (t.MoveCost("walk") > 0 && t.MoveCost("walk") <= 10)) { //has a unit? if (S.Unit().Free(new NVector(x, y, gmap.standard))) { //TODO find right spot with level support return(new NVector(x, y, gmap.standard)); } } i++; } Debug.Log($"{gmap.standard}/{gmap.levels.Count}"); NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard); Debug.LogError($"Can not find a start position for {nation} using {pos}"); return(pos); }
public override bool Check(string data, Player player, NVector pos) { string[] d = data.Split(';'); DataTerrain terr = GameMgmt.Get().newMap.Terrain(pos); return(terr.id == d[2]); }
protected override void ClickFirst() { string moveTyp = ((UnitInfo)mapElementInfo).dataUnit.movement; int cost = GameMgmt.Get().newMap.PathFinding(mapElementInfo.Pos().level).Cost(player, moveTyp, mapElementInfo.Pos(), new NVector(LastClickPos.x, LastClickPos.y, mapElementInfo.Pos().level)); OnMapUI.Get().unitUI.ShowPanelMessage($"You want to move to this field for {cost} AP? Click again!"); }
public static AnimationObject Create(NVector pos) { var ani = Instantiate(UIElements.Get().animationHelper, GameMgmt.Get().newMap[pos.level].effects.transform).GetComponent <AnimationObject>(); ani.transform.position = new Vector3(pos.x + 0.5f, pos.y + 0.5f); return(ani); }
public void UpdatePanel() { //remove actions UIHelper.ClearChild(infoButtons); bool found = false; //add new foreach (Info info in S.ActPlayer().info.infos) { if (info.round != GameMgmt.Get().gameRound.Round) { break; } if (info.read) { continue; } AddInfoButton(info); found = true; } // if (!found) { ShowTown(); } }
public UnitInfo Create(int player, string type, NVector pos, Dictionary <string, int> cost = null) { //exist? if (!L.b.units.ContainsKey(type)) { throw new MissingComponentException("Unit " + type + " not exist"); } if (!pos.Valid()) { throw new MissingComponentException("not a valid position"); } if (At(pos) != null) { throw new MissingComponentException($"field {pos} is blocked"); } UnitInfo ui = Instantiate(unitPrefab, GameMgmt.Get().newMap.levels[pos.level].units.transform); ui.Init(type, player, pos, cost ?? new Dictionary <string, int>(L.b.units[type].cost)); ui.NextRound(); units.Add(ui); GameMgmt.Get().data.units.Add(ui.data); return(ui); }
public double CalcModi(double standard, Player player, NVector pos) { int proc = 0; int val = 0; Check(S.Game().data.modi, player, pos, ref val, ref proc); Check(player.Modi, player, pos, ref val, ref proc); Check(player.Nation().Modi, player, pos, ref val, ref proc); Check(GameMgmt.Get().newMap.Terrain(pos).modi, player, pos, ref val, ref proc); Check(GameMgmt.Get().gameRound.Modi(), player, ref val, ref proc); if (L.b.improvements.Has(pos)) { Check(L.b.improvements.At(pos).modi, player, pos, ref val, ref proc); } if (S.Building(pos) != null) { Check(S.Building(pos).dataBuilding.modi, player, pos, ref val, ref proc); } //calc standard += (standard * proc) / 100; standard += val; return(Math.Max(0, standard)); }
private bool FindPos(Player player, UnitInfo unit, NVector pos, ActionHolder holder) { if (holder.data.ContainsKey("pos")) { return(true); } DataUnit dUnit = unit.dataUnit; //find next field foreach (var p in CircleGenerator.Gen(pos, unit.data.apMax / 5 * 2)) { if (AddGoal(unit, holder, p)) { return(true); } } //has nothing? //search the whole map for (int x = 0; x < GameMgmt.Get().data.map.width; x++) { for (int y = 0; y < GameMgmt.Get().data.map.height; y++) { if (AddGoal(unit, holder, new NVector(x, y, pos.level))) { return(true); } } } //has a field? unit.SetLastInfo(S.T("actionRepeatErrorDestination", holder.DataAction().Name())); unit.SetWaitingAction(null); return(false); }
protected override NVector CreateNewSpot() { int level = Math.Max(GameMgmt.Get().data.map.standard - 1, 0); //underground GameMapData gmap = GameMgmt.Get().data.map; GameMapDataLevel gmdl = GameMgmt.Get().data.map.levels[level]; int i = 0; while (i < 1000) { i++; int x = Random.Range(0, gmap.width); int y = Random.Range(0, gmap.height); DataTerrain t = gmdl.Terrain(x, y); if (t.MoveCost("float") == 0 || t.MoveCost("float") > 10) { continue; // can walk? } if (!S.Unit().Free(new NVector(x, y, gmap.standard))) { continue; //near water? } return(new NVector(x, y, level)); } Debug.Log($"{level}/{gmap.levels.Count}"); NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard); Debug.LogError($"Can not find a start position using {pos}"); return(pos); }
public (int maxInhabitants, int buildingWorker) MaxInhabitantsAndWorker() { int maxInhabitants = 0; int buildWorker = 0; //calculate inhabitants foreach (BuildingInfo buildingInfo in GameMgmt.Get().building.GetByTown(id)) { if (buildingInfo.IsUnderConstruction()) { continue; } int w = buildingInfo.dataBuilding.worker; if (w > 0) { maxInhabitants += w; } else { buildWorker -= w; } } return(maxInhabitants, buildWorker); }
public override bool NextRound() { data.ap = data.apMax; data.BuildingUpdate(); Town t = Town(); if (!base.NextRound()) { return(false); } //need to change icon? //todo change dyn bool winter = GameMgmt.Get().gameRound.IsSeason("winter"); //is no change if (isWinter == winter) { } //change to summer? else if (isWinter && !winter) { isWinter = false; FinishInit(); } //change to winter? else if (!isWinter && winter) { isWinter = true; FinishInit(); } return(true); }
public void MoveTo(NVector pos, bool moveCamera = true) { //change level? if (data.pos.level != pos.level) { transform.SetParent(GameMgmt.Get().newMap[pos.level].units.transform); } if (moveCamera) { //new level? if (data.pos.level != pos.level) { S.CameraMove().MoveTo(pos); } else { MoveBy(pos.x - Pos().x, pos.y - Pos().y); return; } } data.pos = pos; transform.position = new Vector2(Pos().x + 0.5f, Pos().y); Clear(pos); }
public virtual WindowBuilderSplit ShowInfoWindow() { WindowBuilderSplit win = WindowBuilderSplit.Create(gameObject.name, null); win.Add(new ActionDisplaySplitElement(this)); win.Add(new TerrainSplitElement(GameMgmt.Get().newMap.Terrain(Pos()), Pos())); if (data.townId != -1) { win.Add(new CameraTownSplitElement(win, Town())); } if (S.Debug()) { win.Add(new DebugMapElementSplitElement(this)); win.Add(new DebugSpellSplitElement(this)); } if (L.b.improvements.Has(Pos())) { win.Add(new LexiconSplitElement(L.b.improvements.At(Pos()))); } win.Add(new InfosSplitElement(data.info)); return(win); }
public IEnumerator LoadMap() { yield return(GameMgmt.Get().load.ShowSubMessage($"Loading Map data")); //load Map yield return(CreateLayers()); }
public string Passable(NVector pos) { DataTerrain land = GameMgmt.Get().newMap.Terrain(pos); //check terrain int cost = GameMgmt.Get().newMap.PathFinding(Pos().level).Cost(Player(), dataUnit.movement, Pos(), pos); if (cost == 0) { return(S.T("unitMoveErrorPassable", land.Name())); } //visible? if (!Player().fog.Visible(pos)) { return(S.T("unitMoveErrorExplored", land.Name())); } //another unit? if (!S.Unit().Free(pos)) { return(S.T("unitMoveErrorUnit", land.Name(), S.Unit().At(pos).name)); } //can walk if (cost > data.ap) { return(S.T("unitMoveErrorAp", land.Name(), cost - data.ap)); } return(null); }
/// <summary> /// Destroy this unit /// </summary> public override void Kill() { GameMgmt.Get().data.units.Remove(data); GameMgmt.Get().unit.units.Remove(this); Destroy(gameObject); Debug.Log($"Kill unit {name} at {Pos()}"); }
protected virtual void CreateTile(GameMapDataLevel std, int x, int y, int layer, int[][] layerData, int height, DataTerrain invisible) { int oTerrain = std.At(new Vector3Int(x, y, layer)); if (oTerrain == -1) { layerData[height - y - 1][x] = -1; return; } DataTerrain org = L.b.terrains[oTerrain]; //has element? try { if (mapGeneration.terrains.ContainsKey(org.id)) { layerData[height - y - 1][x] = L.b.terrains[mapGeneration.terrains[org.id]].defaultTile; } else if (layer == 0) { layerData[height - y - 1][x] = invisible.defaultTile; } else { layerData[height - y - 1][x] = -1; } } catch (Exception e) { Debug.Log($"{y}/{height - y - 1}/{height},{x}/{GameMgmt.Get().data.map.width}"); throw e; } }
protected virtual NVector CreateNewSpot() { GameMapData gmap = GameMgmt.Get().data.map; GameMapDataLevel gmdl = GameMgmt.Get().data.map.levels[gmap.standard]; int i = 0; while (i < 1000) { i++; int x = Random.Range(0, gmap.width); int y = Random.Range(0, gmap.height); DataTerrain t = gmdl.Terrain(x, y); if (t.MoveCost("walk") == 0 || t.MoveCost("walk") > 10) { continue; // can walk? } if (!gmdl.TerrainNear(x, y, "water", 2)) { continue; //near water? } if (!S.Unit().Free(new NVector(x, y, gmap.standard))) { continue; //near water? } return(new NVector(x, y, gmap.standard)); } NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard); Debug.LogError($"Can not find a start position using {pos}"); return(pos); }
public void NextRound() { //todo change dyn bool winter = GameMgmt.Get().gameRound.IsSeason("winter"); //is no change if (dataLevel.isWinter == winter) { return; } //change to summer? if (dataLevel.isWinter && !winter) { layersWinter.ForEach(w => w.gameObject.SetActive(false)); layers.ForEach(w => w.gameObject.SetActive(true)); dataLevel.isWinter = false; return; } //change to winter? if (!dataLevel.isWinter && winter) { layersWinter.ForEach(w => w.gameObject.SetActive(true)); layers.ForEach(w => w.gameObject.SetActive(false)); dataLevel.isWinter = true; } }
public Tile Tile(int id, Color color) { var t = GameMgmt.Get().newMap.tools.GetTile(Icon.Replace("4", id.ToString()), color.ToString()); t.color = color; return(t); }
public BuildingInfo Create(int town, string type, NVector pos, Dictionary <string, int> cost = null) { //exist? if (!L.b.buildings.ContainsKey(type)) { throw new MissingComponentException($"Building {type} not exist"); } if (!pos.Valid()) { throw new MissingComponentException("not a valid position"); } if (At(pos) != null) { throw new MissingComponentException($"field {pos} is blocked"); } BuildingInfo bi = Instantiate(buildPrefab, GameMgmt.Get().newMap.levels[pos.level].buildings.transform); bi.Init(town, type, pos, cost ?? new Dictionary <string, int>(L.b.buildings[type].cost)); bi.NextRound(); GameMgmt.Get().data.buildings.Add(bi.data); buildings.Add(bi); return(bi); }
private UnitInfo Unit(int pid, string id, NVector pos) { GameMgmt.Get().newMap.levels[pos.level].SetTile(new Vector3Int(pos.x, pos.y, 1), null); var b = S.Unit().Create(pid, id, pos); b.FinishConstruct(); return(b); }
private void ShowHideUnits() { //hide / show all objects foreach (UnitInfo u in GameMgmt.Get().unit.GetAll()) { u.gameObject.SetActive(Visible(u.Pos())); } }
private void ShowHideBuilding() { //hide / show all objects foreach (BuildingInfo b in GameMgmt.Get().building.GetAll()) { b.gameObject.SetActive(Visible(b.Pos())); } }
/// <summary> /// /// </summary> /// <param name="pos"></param> /// <returns>Improvement or null</returns> public Improvement At(NVector pos) { if (GameMgmt.Get().data.map.levels[pos.level].improvement[pos.x, pos.y] == null) { return(null); } return(data[GameMgmt.Get().data.map.levels[pos.level].improvement[pos.x, pos.y]]); }
public void Init(int level) { this.level = level; dataLevel = GameMgmt.Get().data.map.levels[level]; mapData = GameMgmt.Get().data.map; _pathFinding = new MapPathFinding(level); _winterPathFinding = new MapPathFinding(level); }
public void Init() { _activeLevel = GameMgmt.Get().data.map.standard; //which is the standard layer? for (int i = 0; i < _map.levels.Count; i++) { _map[i].gameObject.SetActive(_activeLevel == i); } }
public override void Perform() { UpdatePref("lastBuild"); ism.Close(); MaterialWindow.ShowBuildMaterialWindow(build, pos, cost => { GameMgmt.Get().building.Create(S.Towns().NearestTown(S.ActPlayer(), pos, false).id, build.id, pos, cost); OnMapUI.Get().UpdatePanel(pos); }); }
public override void Upgrade(string type, Dictionary <string, int> cost) { var oldCost = data.constructionOrg; GameMgmt.Get().data.buildings.Remove(data); Init(data.townId, type, Pos(), cost); GameMgmt.Get().data.buildings.Add(data); CalcUpgradeCost(cost, oldCost); }