public Tilemap(int w, int h, Tilemap ft) { cmap = new CityMap(w, h); map = new Tile[w, h]; fog = new Fog(w, h); name = ft.name; startpos = new Point(ft.startpos.X, ft.startpos.Y); for (int i = 0; i < w; i++) for (int e = 0; e < h; e++) { if (i < ft.NumX && e < ft.NumY) { map[i, e] = ft.get(i, e); fog.set(i, e, ft.Fog.get(i, e)); cmap.set(i, e, ft.CityMap.get(i, e)); } else if (i < w && e < h) { map[i, e] = new Tile(); fog.set(i, e, false); } } }
public Misc(Main fmain, Tilemap ftm) { InitializeComponent(); tm = ftm; main = fmain; }
public UnitMap(Tilemap tm) { umap = new List<Unit>[tm.NumX, tm.NumY]; for (int i = 0; i < umap.GetLength(0); i++) for (int e = 0; e < umap.GetLength(1); e++) umap[i, e] = new List<Unit>(); }
public Main() { InitializeComponent(); tm = new Tilemap(NX, NY); map = new Map(NX, NY); map.Location = new Point(10, 20); grp_main.Controls.Add(map); }
public CityForm(Tilemap ftm, int fx, int fy) { tm = ftm; x = fx; y = fy; InitializeComponent(); updateOwnerList(); selTile(x, y); }
public Main(Tilemap ftm) { InitializeComponent(); if (tm.NumX >= NX && tm.NumY >= NY) tm = ftm; else tm = new Tilemap(NX, NY); map = new Map(NX, NY); map.Location = new Point(10, 20); grp_main.Controls.Add(map); }
public Tilemap() { int w = 30; int h = 20; map = new Tile[w, h]; Random r = new Random(); Tilemap g = new Tilemap("green"); Tilemap b = new Tilemap("blue"); for (int e = 0; e < h; e++) for (int i = 0; i < w; i++) { map[i, e] = new Tile((Tile.TileType)r.Next(6)); if (map[i, e].Type == Tile.TileType.FOREST) map[i, e].Region = g; else if (map[i, e].Type == Tile.TileType.WATER) map[i, e].Region = b; } }
public void load(String path) { path = "./map/" + path; if (!VersionSys.match(path, uid, type, ver)) throw new Exception("File is not a Forgotten Schism Map file v1.0"); List<String> refls=new List<String>(); FileStream fin = new FileStream(path, FileMode.Open); fin.Seek(12, SeekOrigin.Begin); int rn = fin.ReadByte(); int sl; char[] sb; int e; for (int i = 0; i < rn; i++) { sl = fin.ReadByte(); sb=new char[sl]; for (e = 0; e < sl; e++) sb[e] = (char)fin.ReadByte(); refls.Add(new String(sb)); } //map width and height int w = fin.ReadByte(); int h = fin.ReadByte(); map=new Tile[w,h]; //map data int tt; Tilemap tm; for (e = 0; e < h ; e++) for (int i = 0; i < w; i++) { tt = fin.ReadByte(); rn = fin.ReadByte(); if (rn != 0) { tm = new Tilemap(refls[rn-1]); } else tm = null; map[i, e] = new Tile((Tile.TileType)tt, tm); } fin.Close(); }
/// <summary> /// Setup map info /// </summary> public void set(Map fmap, Tilemap ftm, CharMap fcmap) { set(fmap, ftm); cmap = fcmap; }
/// <summary> /// Setup map info /// </summary> public void set(Map fmap, Tilemap ftm, UnitMap fumap) { set(fmap, ftm); umap = fumap; }
/// <summary> /// Setup map info /// </summary> public void set(Map fmap, Tilemap ftm) { map = fmap; tm = ftm; }
private void cmd_openref_Click(object sender, EventArgs e) { Tile t = tm.get((int)num_selx.Value, (int)num_sely.Value); if (!tm.CityMap.isCity((int)num_selx.Value, (int)num_sely.Value)) return; Tilemap rtm = new Tilemap(tm.CityMap.get((int)num_selx.Value, (int)num_sely.Value).Name); Main f = new Main(rtm); f.Show(); }
private static bool canMove(UnitMap umap, Tilemap tm, Point dest, String org) { if (tm.get(dest.X, dest.Y).Type == Tile.TileType.MOUNTAIN || tm.get(dest.X, dest.Y).Type == Tile.TileType.WATER) return false; return umap.canMove(dest.X, dest.Y, org); }
private void dialog_ret_battle(bool b) { if (b) { GameState.CurrentState.att = 0; lp = GameState.CurrentState.mainCharPos; if (map.CharLs.ContainsKey(dnp)) map.CharLs.Remove(dnp); map.CharLs.Remove(GameState.CurrentState.mainCharPos); map.CharLs.Add(dnp, Graphic.getSprite(GameState.CurrentState.mainChar)); System.Console.Out.WriteLine(GameState.CurrentState.mainCharPos+" "+dnp); City.CitySide atts=City.opposed(City.move2side(GameState.CurrentState.mainCharPos, dnp)); GameState.CurrentState.mainCharPos = dnp; changeCurp(this, new EventArgObject(new Point(dnp.X, dnp.Y))); clearFog(dnp); map.focus(dnp.X, dnp.Y); Tilemap tm = new Tilemap(GameState.CurrentState.citymap["gen"].get(dnp.X, dnp.Y).Name); Objective goal = new Objective(); goal.setDefeatAll(); StateManager.Instance.goForward(new Region(tm, atts, true, GameState.CurrentState.citymap["gen"].get(dnp.X, dnp.Y).EnnemyFactor, goal)); } yn_battle.InputEnabled = false; }
private static bool inMap(Tilemap tm, Point p) { return p.X >= 0 && p.Y >= 0 && p.X < tm.NumX && p.Y < tm.NumY; }
private static bool canMove(CharMap cmap, Tilemap tm, Point dest) { if (tm.get(dest.X, dest.Y).Type == Tile.TileType.MOUNTAIN || tm.get(dest.X, dest.Y).Type == Tile.TileType.WATER) return false; return cmap.canMove(dest.X, dest.Y); }
private static bool canMove(Tilemap tm, Point dest, String org) { return !(tm.get(dest.X, dest.Y).Type == Tile.TileType.MOUNTAIN || tm.get(dest.X, dest.Y).Type == Tile.TileType.WATER); }
public static Boolean battle(CharMap cmap, Tilemap tm, String org, Map map, Unit ally, Unit enemy, Label dmg, Label action, ref Boolean gameOver, ref Boolean defeat, GameTime gameTime) { Character c = cmap.get(map.CursorPosition.X, map.CursorPosition.Y); Character m; Point p; Point ne; if (c != null && c.Organization == org && c.stats.movement != 0) { if(c is Healer) ne = nearest(cmap, map.CursorPosition, "ennemy"); else ne = nearest(cmap, map.CursorPosition, "main"); if (isAdj(map.CursorPosition, ne)) { c.stats.movement = 0; p = map.CursorPosition; } else { //finds path to nearest ennemy p = pathFind(cmap, tm, map.CursorPosition, nearest(cmap, map.CursorPosition, "main"), org); if (c.stats.movement > 0) { cmap.move(map.CursorPosition.X, map.CursorPosition.Y, p.X, p.Y); map.changeCursor(new Point(p.X, p.Y)); } c.stats.movement--; } if (c.stats.movement == 0) { Point tar = targetCharacter(c, p, cmap); if (tar != new Point(-1, -1)) { m = cmap.get(tar.X, tar.Y); map.CurLs.Add(tar, Content.Graphics.Instance.Images.gui.cursorRed); if (c is Fighter) dmg.Text = ((Fighter)c).attack(m); else if (c is Archer) dmg.Text = ((Archer)c).attack(m); else if (c is Scout) dmg.Text = ((Scout)c).attack(m); else if (c is Healer) { dmg.Text = ((Healer)c).heal(m).ToString(); action.Text = "Heal"; } else if (c is Caster) { dmg.Text = ((Caster)c).attack(m, new Spell("DerpCast", 1, 5, 1, 5)); action.Text = "DerpCast"; } else dmg.Text = "Cant"; if (action.Text == "") action.Text = "Attack"; dmg.Position = new Vector2(tar.X * 64 - map.getTlc.X * 64, tar.Y * 64 - map.getTlc.Y * 64 + 20); dmg.visibleTemp(500); action.visibleTemp(500); if (dmg.Text != "miss" || dmg.Text != "Cant") { enemy.set(c.Position.X, c.Position.Y, c); ally.set(m.Position.X, m.Position.Y, m); if (m.stats.hp <= 0) { if (m.isMainChar()) gameOver = true; ally.delete(m.Position.X, m.Position.Y); cmap.set(tar.X, tar.Y, null); cmap.update(map); if (ally.Characters.Count <= 0) defeat = true; } } } } return false; } else { for (int e = cmap.NumY - 1; e >= 0; e--) for (int i = cmap.NumX - 1; i >= 0; i--) if (cmap.isChar(i, e) && cmap.get(i, e).stats.movement != 0 && cmap.get(i, e).Organization == org) { if (map.CursorPosition != new Point(i, e)) { map.CurLs.Clear(); dmg.Visible = false; action.Visible = false; action.Text = ""; map.changeCursor(new Point(i, e)); return false; } } } cmap.resetAllMovement(org); return true; }
private void loadContent() { Graphics.instantiate(); gen = new Tilemap("gen"); cinfo=cinfo_load(".\\xml\\class_info.xml"); spellList = spellList_load(".\\xml\\spell_list.xml"); recruitLs = recruits_Load(".\\xml\\recruitment_info.xml"); gen_load(".\\xml\\gen.xml"); audio = new Audio(); audio.songs.test = Game1.Instance.Content.Load<Song>(@"audio\\song\\test"); audio.songs.worldMap = Game1.Instance.Content.Load<Song>(@"audio\\song\\WorldMap"); shop_load(".\\xml\\item_list.xml"); emap_load(".\\xml\\emap.xml"); text_load(".\\xml\\text.xml"); }
private void updateDim() { if (num_numx.Value < NX || num_numy.Value < NY) return; grp_info.Enabled = false; grp_main.Enabled = false; grp_sel.Enabled = false; map.setCur(0, 0); tm = new Tilemap((int)num_numx.Value, (int)num_numy.Value, tm); map.setTilemap(tm); selChange(this, new EventArgObject(new Point(0, 0))); grp_info.Enabled = true; grp_main.Enabled = true; grp_sel.Enabled = true; map.Refresh(); }
private static Point pathFindFallBack(CharMap cmap, Tilemap tm, Point src, Point dest, String org) { Dictionary<Point, int> map = new Dictionary<Point, int>(); Queue<PointCounter> main = new Queue<PointCounter>(); Queue<PointCounter> temp = new Queue<PointCounter>(); PointCounter cur; PointCounter tcur; main.Enqueue(new PointCounter(dest, 0)); map[dest] = 0; int cc; bool f = false; while (main.Count > 0) { cur = main.Dequeue(); temp.Clear(); if (cur.p == src) { f = true; break; } cc = cur.c + 1; temp.Enqueue(new PointCounter(cur.p.X, cur.p.Y - 1, cc)); temp.Enqueue(new PointCounter(cur.p.X + 1, cur.p.Y, cc)); temp.Enqueue(new PointCounter(cur.p.X, cur.p.Y + 1, cc)); temp.Enqueue(new PointCounter(cur.p.X - 1, cur.p.Y, cc)); while (temp.Count > 0) { tcur = temp.Dequeue(); if (tcur.p != src) { if (!inMap(tm, tcur.p) || !canMove(tm, tcur.p, org)) continue; if (map.ContainsKey(tcur.p) && map[tcur.p] <= tcur.c) continue; } map[tcur.p] = tcur.c; main.Enqueue(tcur); } } if (!f) return src; Point ret = src; cc = map[src]; temp.Clear(); temp.Enqueue(new PointCounter(src.X, src.Y - 1, 0)); temp.Enqueue(new PointCounter(src.X + 1, src.Y, 0)); temp.Enqueue(new PointCounter(src.X, src.Y + 1, 0)); temp.Enqueue(new PointCounter(src.X - 1, src.Y, 0)); while (temp.Count > 0) { tcur = temp.Dequeue(); if (map.ContainsKey(tcur.p) && map[tcur.p] < cc) { cc = map[tcur.p]; ret = tcur.p; } } if (!canMove(cmap, tm, ret)) return src; return ret; }
public static Unit[] region(UnitMap umap, Tilemap tm, String org, Map map, ref Boolean dun) { Unit u; Point ne; Point d; for (int i = 0; i < umap.NumX; i++) for (int e = 0; e < umap.NumY; e++) if (umap.isUnit(i, e) && umap.get(i, e).movement > 0 && umap.get(i, e).Organization == org) { if (map.CursorPosition != new Point(i, e)) { map.changeCursor(new Point(i, e)); return null; } u = umap.get(i, e); if (u.hasLeader()) { ne = nearest(umap, new Point(i, e), "main"); if (isAdj(new Point(i, e), ne)) { u.movement = 0; return new Unit[] { umap.get(ne.X, ne.Y), u }; } //finds path to nearest ennemy d = pathFind(umap, tm, new Point(i, e), nearest(umap, new Point(i, e), "main"), org); umap.move(i, e, d.X, d.Y); map.changeCursor(new Point(d.X, d.Y)); u.movement--; } return null; } dun = true; return null; }
/// <summary> /// Battle Constructor, created once a unit engages an enemy in battle /// </summary> /// <param name="m">The player's unit</param> /// <param name="e">The enemy's unit</param> /// <param name="fregion">The region where the battle was engaged</param> /// <param name="fgoal">The region's condition for victory</param> public Battle(Unit m, Unit e, Region fregion, Objective fgoal) { MainWindow.BackgroundImage = Content.Graphics.Instance.Images.background.bg_smallMenu; orgls = new List<String>(); region = fregion; goal = fgoal; ally = m; enemy = e; tm=new Tilemap("battle"); cmap = new CharMap(tm); cmap.ShowMisc = true; map = new Map(tm); map.ArrowEnabled = true; map.SelectionEnabled = false; map.changeCurp = changeCurp; map.curSelection = sel; map.focus(5, 6); MainWindow.add(map); lbl_actions = new Label("Actions"); lbl_actions.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_actions.Position = new Vector2(280, 390); lbl_actions.Visible = false; MainWindow.add(lbl_actions); menu_actions = new Menu(5); menu_actions.Position = new Vector2(280, 390); menu_actions.Visible = false; MainWindow.add(menu_actions); menu_actions.Enabled = false; menu_actions.ArrowEnabled = false; lbl_moved = new Label("MOVED"); lbl_moved.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.SPECIAL; lbl_moved.Position = new Vector2(520, 414); lbl_moved.Visible = false; MainWindow.add(lbl_moved); lbl_enemyTurn = new Label("DAMAGE"); lbl_enemyTurn.Color = Color.Red; lbl_enemyTurn.Position = new Vector2(50, 50/*420*/); lbl_enemyTurn.Visible = false; MainWindow.add(lbl_enemyTurn); lbl_name = new Label("Name"); lbl_name.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_name.Position = new Vector2(50, 390); MainWindow.add(lbl_name); lbl_charName = new Label("Derp"); lbl_charName.Position = new Vector2(110, 390); MainWindow.add(lbl_charName); lbl_lvl = new Label("Level"); lbl_lvl.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_lvl.Position = new Vector2(50, 420); MainWindow.add(lbl_lvl); lbl_charLvl = new Label("20"); lbl_charLvl.Position = new Vector2(110, 420); MainWindow.add(lbl_charLvl); lbl_exp = new Label("Exp"); lbl_exp.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_exp.Position = new Vector2(150, 420); MainWindow.add(lbl_exp); lbl_charExp = new Label("42"); lbl_charExp.Position = new Vector2(200, 420); MainWindow.add(lbl_charExp); lbl_hp = new Label("HP"); lbl_hp.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_hp.Position = new Vector2(50, 450); MainWindow.add(lbl_hp); lbl_curHp = new Label("100"); lbl_curHp.Position = new Vector2(90, 450); MainWindow.add(lbl_curHp); lbl_hpSlash = new Label("/"); lbl_hpSlash.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_hpSlash.Position = new Vector2(140, 450); MainWindow.add(lbl_hpSlash); lbl_maxHp = new Label("100"); lbl_maxHp.Position = new Vector2(160, 450); MainWindow.add(lbl_maxHp); lbl_mp = new Label("MP"); lbl_mp.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_mp.Position = new Vector2(50, 480); MainWindow.add(lbl_mp); lbl_curMp = new Label("50"); lbl_curMp.Position = new Vector2(90, 480); MainWindow.add(lbl_curMp); lbl_mpSlash = new Label("/"); lbl_mpSlash.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_mpSlash.Position = new Vector2(140, 480); MainWindow.add(lbl_mpSlash); lbl_maxMp = new Label("50"); lbl_maxMp.Position = new Vector2(160, 480); MainWindow.add(lbl_maxMp); lbl_moveLeft = new Label("Move Left"); lbl_moveLeft.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_moveLeft.Position = new Vector2(50, 510); MainWindow.add(lbl_moveLeft); lbl_move = new Label(""); lbl_move.Position = new Vector2(150, 510); MainWindow.add(lbl_move); lbl_enter = new Label("ENTER"); lbl_enter.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.CONTROL; lbl_enter.Position = new Vector2(520, 462); MainWindow.add(lbl_enter); lbl_enterAction = new Label("Select Unit"); lbl_enterAction.Position = new Vector2(600, 462); MainWindow.add(lbl_enterAction); lbl_v = new Label("V"); lbl_v.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.CONTROL; lbl_v.Position = new Vector2(520, 438); MainWindow.add(lbl_v); lbl_vAction = new Label("View Character"); lbl_vAction.Position = new Vector2(550, 438); MainWindow.add(lbl_vAction); lbl_esc = new Label("ESC"); lbl_esc.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.CONTROL; lbl_esc.Position = new Vector2(520, 486); lbl_esc.Visible = false; MainWindow.add(lbl_esc); lbl_escAction = new Label("Cancel Movement"); lbl_escAction.Position = new Vector2(570, 486); lbl_escAction.Visible = false; MainWindow.add(lbl_escAction); lbl_e = new Label("E"); lbl_e.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.CONTROL; lbl_e.Position = new Vector2(520, 510); MainWindow.add(lbl_e); lbl_eAction = new Label("End Turn"); lbl_eAction.Position = new Vector2(550, 510); MainWindow.add(lbl_eAction); lbl_turnCount = new Label("Turn: " + turnCount + " / 10"); lbl_turnCount.LabelFun = ColorTheme.LabelColorTheme.LabelFunction.BOLD; lbl_turnCount.Position = new Vector2(520, 390); MainWindow.add(lbl_turnCount); lbl_dmg = new Label(""); lbl_dmg.Color = Color.Red; lbl_dmg.Position = new Vector2(0, 0); lbl_dmg.Visible = false; MainWindow.add(lbl_dmg); lbl_actionTaken = new Label(""); lbl_actionTaken.Color = Color.Black; lbl_actionTaken.Position = new Vector2(250, 30); lbl_actionTaken.Font = Content.Graphics.Instance.ActionFont; lbl_actionTaken.Visible = false; MainWindow.add(lbl_actionTaken); lbl_armyTurn = new Label("TO BATTLE, COMRADES!"); lbl_armyTurn.Font = Content.Graphics.Instance.TurnFont; lbl_armyTurn.center(50); lbl_armyTurn.doneShowing = armyTurnDone; lbl_armyTurn.visibleTemp(2000); MainWindow.add(lbl_armyTurn); lbl_battleOutcome = new Label("VICTORY!"); lbl_battleOutcome.Font = Content.Graphics.Instance.TurnFont; lbl_battleOutcome.center(50); lbl_battleOutcome.doneShowing = endOfBattle; lbl_battleOutcome.Visible = false; MainWindow.add(lbl_battleOutcome); deploy(m, true); deploy(e, false); cmap.update(map); freemode = true; actionMode = false; targetMode = false; spellMode = false; itemMode = false; changeCurp(null, new EventArgObject(new Point(5, 6))); scp = new Point(5, 6); endTurnP = new Point(5, 6); setAllNotMoved(); ai = new AI(); ai.set(map, tm, cmap); ai.done = ai_done; MainWindow.InputEnabled = false; }
public Tile(TileType t, Tilemap fr) { type = t; region = fr; }
public CityMap(Tilemap tm) { cmap=new City[tm.NumX, tm.NumY]; }
/// <summary> /// Generates a TileMap with the given UnitMap and Unit (and Tilemap and Organization) /// </summary> /// <param name="umap">The UnitMap to use</param> /// <param name="unit">The Unit to be based on</param> /// <param name="tm">Tilemap (not the pathfind one)</param> /// <param name="org">Organization to base the map from (determins who is ally and who is enemy)</param> /// <returns>a PathFind.TileMap</returns> public static TileMap gen(UnitMap umap, Tilemap tm, Unit unit) { TileMap ptm = new TileMap(tm.NumX, tm.NumY); for(int i=0; i<tm.NumX; i++) for(int e=0; e<tm.NumY; e++) if(!unit.canMove(tm.get(i, e).Type)) ptm.set(i, e, Tile_Type.BLOCK_TERRAIN); else if(!umap.canMove(i, e, unit.Organization)) ptm.set(i, e, Tile_Type.BLOCK_UNIT); else ptm.set(i, e, Tile_Type.NOTHING); return ptm; }
/// <summary> /// Generates a TileMap with the given CharMap and Character (and Tilemap and Organization) /// </summary> /// <param name="cmap">The CharMap to use</param> /// <param name="c">The Character to base the map on</param> /// <param name="tm">Tilemap (not the pathfind one)</param> /// <param name="org">Organization to base the map from (determins who is ally and who is enemy)</param> /// <returns>a PathFind.TileMap</returns> public static TileMap gen(CharMap cmap, Tilemap tm, String org, Character c) { TileMap ptm = new TileMap(tm.NumX, tm.NumY); for (int i = 0; i < tm.NumX; i++) for (int e = 0; e < tm.NumY; e++) if (!c.canMove(tm.get(i, e).Type)) ptm.set(i, e, Tile_Type.BLOCK_TERRAIN); else if (!cmap.canMove(i, e)) ptm.set(i, e, Tile_Type.BLOCK_UNIT); else ptm.set(i, e, Tile_Type.NOTHING); return ptm; }
private void cmd_load_Click(object sender, EventArgs e) { grp_info.Enabled = false; grp_main.Enabled = false; grp_sel.Enabled = false; Tilemap tmp = new Tilemap(NX, NY); String[] refls; map.setCur(0, 0); try { tmp.load(txt_file.Text); if (tmp.NumX < NX || tmp.NumY < NY) throw new Exception(); if(cf!=null) cf.Close(); map.setTilemap(tmp); refls = Tilemap.reflist(txt_file.Text); num_startx.Value = tmp.StartingPosition.X; num_starty.Value = tmp.StartingPosition.Y; } catch(Exception ex) { MessageBox.Show("Error loading file", "Error Loading File", MessageBoxButtons.OK, MessageBoxIcon.Error); grp_info.Enabled = true; grp_main.Enabled = true; grp_sel.Enabled = true; return; } tm = tmp; pch = true; num_numx.Value = tm.NumX; num_numy.Value = tm.NumY; pch = false; selChange(this, new EventArgObject(new Point(0,0))); System.Console.Out.WriteLine("EN 2"); grp_info.Enabled = true; grp_main.Enabled = true; grp_sel.Enabled = true; map.Refresh(); }