public COrder(CEncodedObjectInputBufferI bin) { bin.nextTag(TAG); Dictionary <string, string> A = bin.getAttributes(); ordType_ = A[ORDTYPE]; value_ = EncodeUtil.parseInt(A[VALUE]); if (A.ContainsKey(UTYPE)) { utype_ = A[UTYPE]; } flag_ = EncodeUtil.fromBoolString(A[FLAG]); ugid_ = EncodeUtil.parseUInt(A[UGID]); useEmbark_ = EncodeUtil.fromBoolString(A[UGID]); bin.firstChild(); bin.nextTag(LOCS); if (bin.hasChildren()) { bin.firstChild(); locs_ = new List <CLoc>(); while (!bin.reachedEndTag(LOCS)) { CLoc l = CLoc.fromKey(bin.getObjectText(LOC)); locs_.Add(l); } } bin.endTag(LOCS); bin.endTag(TAG); }
public COrder(string ordType, CLoc loc, bool flag) { ordType_ = ordType; locs_ = new List <CLoc>(); locs_.Add(loc.copy()); flag_ = flag; }
public int resourceValue(CLoc loc) { if (resources_.ContainsKey(loc.getKey())) { return(resources_[loc.getKey()]); } return(0); }
public string getMapLocation(CLoc loc) { if (!mapUtil_.validLoc(loc.x, loc.y)) { return(null); } return(Convert.ToString(mapBytes_[getIndex(loc.x, loc.y)])); }
public CMapLocInfo(CLoc loc, string terrain, int icon, bool road, uint resources, bool mine, bool wasteland) { loc_ = loc; terrain_ = terrain; icon_ = icon; road_ = road; resources_ = resources; mine_ = mine; wasteland_ = wasteland; }
public List <CLoc> getLocsToCheck(CLoc loc, int range, bool includeOrigin) { List <CLoc> vec = mapUtil_.getSurroundingRng(loc, range); if (includeOrigin) { vec.Add(loc); } return(vec); }
public void setMine(CLoc loc, bool add) { if (!add && mines_.ContainsKey(loc.getKey())) { mines_.Remove(loc.getKey()); } if (add && !mines_.ContainsKey(loc.getKey())) { mines_.Add(loc.getKey(), true); } }
public List <CLoc> getEdgeLocsToCheck(CLoc loc, int range) { var locs = new List <CLoc>(); if (range == 0) { locs.Add(loc); } else { int orgx = loc.x - range; int orgy = loc.y - range; int endx = loc.x + range; int endy = loc.y + range; //top left to top right //bottom left to bottom, right int x = orgx; while (x <= endx) { var t = new CLoc(mapUtil_.hwash(x), mapUtil_.vwash(orgy)); var b = new CLoc(mapUtil_.hwash(x), mapUtil_.vwash(endy)); if (mapUtil_.validLoc(t.x, t.y)) { locs.Add(t); } if (mapUtil_.validLoc(b.x, b.y)) { locs.Add(b); } x++; } int y = orgy + 1; while (y < endy) { var l = new CLoc(mapUtil_.hwash(orgx), mapUtil_.vwash(y)); var r = new CLoc(mapUtil_.hwash(endx), mapUtil_.vwash(y)); if (mapUtil_.validLoc(l.x, l.y)) { locs.Add(l); } if (mapUtil_.validLoc(r.x, r.y)) { locs.Add(r); } y++; } } return(locs); }
public string getLocationFromDir(int x, int y, int dir, int dist) { CLoc loc = mapUtil_.getLocationFromDir(x, y, dir, dist); if (loc == null) { return(null); } return(getMapLocation(loc)); }
public void addRoad(CLoc loc, bool add) { if (!add && roads_.ContainsKey(loc.getKey())) { roads_.Remove(loc.getKey()); } else if (add && !roads_.ContainsKey(loc.getKey())) { roads_.Add(loc.getKey(), true); } }
public void setWasteland(CLoc loc, bool add) { if (!add && wasteland_.ContainsKey(loc.getKey())) { wasteland_.Remove(loc.getKey()); } if (add && !wasteland_.ContainsKey(loc.getKey())) { wasteland_.Add(loc.getKey(), true); } }
public CUnit( string utype, uint gid, CLoc loc, UnitQueryI entry ) { utype_ = utype; gid_ = gid; loc_ = loc; entry_ = entry; }
public List <CLoc> getSurrounding(CLoc loc) { var ret = new List <CLoc>(); for (int dir = CMapUtil.NORTH; dir <= CMapUtil.NORTHWEST; dir++) { CLoc L = getNextLocationFromDir(loc.x, loc.y, dir); if (L != null) { ret.Add(L); } } return(ret); }
public CSupplyRoute(CEncodedObjectInputBufferI bin) { bin.nextTag(TAG); Dictionary <string, string> A = bin.getAttributes(); rid_ = EncodeUtil.parseUInt(A[RID]); source_ = EncodeUtil.parseUInt(A[SOURCE]); sourceLoc_ = CLoc.fromKey(A[SOURCE_LOC]); dest_ = EncodeUtil.parseUInt(A[DEST]); destLoc_ = CLoc.fromKey(A[DEST_LOC]); inTransit_ = EncodeUtil.parseUInt(A[IN_TRANSIT]); nextArrival_ = EncodeUtil.parseUInt(A[NEXT_ARRIVAL]); bin.endTag(TAG); }
public CProductionReportData(CEncodedObjectInputBufferI bin) { bin.nextTag(TAG); Dictionary <string, string> A = bin.getAttributes(); value_ = EncodeUtil.parseInt(A[VALUE]); pkey_ = EncodeUtil.parseUInt(A[PKEY]); ckey_ = EncodeUtil.parseUInt(A[CKEY]); rtype_ = bin.getObjectText(RTYPE); if (bin.thisTag() == REPORT) { report_ = bin.getObjectText(REPORT); } else { report_ = null; } if (bin.thisTag() == PTYPE) { ptype_ = bin.getObjectText(PTYPE); } else { ptype_ = null; } if (bin.thisTag() == CTYPE) { ctype_ = bin.getObjectText(CTYPE); } else { ctype_ = null; } if (bin.thisTag() == LOC) { loc_ = CLoc.fromKey(bin.getObjectText(LOC)); } else { loc_ = null; } bin.endTag(TAG); }
public bool next2Sea(CLoc loc) { for (int dir = CMapUtil.NORTH; dir <= CMapUtil.NORTHWEST; dir++) { string ml = getLocationFromDir(loc.x, loc.y, dir, 1); if (ml == null) { continue; } if (ml == EmpireCC.CT_SEA || ml == EmpireCC.CT_SHALLOWSEA) { return(true); } } return(false); }
protected CUnit(Dictionary <string, string> A, CEncodedObjectInputBufferI bin, AIQueryI query) { utype_ = A[UTYPE]; loc_ = CLoc.fromKey(A[LOC]); gid_ = EncodeUtil.parseUInt(A[GID]); owner_ = EncodeUtil.parseInt(A[OWNER]); stackLayer_ = EncodeUtil.parseUInt(A[STACKLAYER]); level_ = A[LEVEL]; landed_ = EncodeUtil.fromBoolString(A[LANDED]); inReentry_ = EncodeUtil.fromBoolString(A[INREENTRY]); host_ = EncodeUtil.parseUInt(A[HOST]); turn_ = EncodeUtil.parseInt(A[TURN]); rmvr_ = EncodeUtil.parseInt(A[RMVR]); rmvs_ = EncodeUtil.parseInt(A[RMVS]); fired_ = EncodeUtil.fromBoolString(A[FIRED]); armed_ = EncodeUtil.fromBoolString(A[ARMED]); dmg_ = EncodeUtil.parseInt(A[DMG]); shortFuel_ = EncodeUtil.fromBoolString(A[SHORTFUEL]); sawEnemy_ = EncodeUtil.fromBoolString(A[SAWENEMY]); dugIn_ = EncodeUtil.fromBoolString(A[DUGIN]); experience_ = EncodeUtil.parseUInt(A[EXPERIENCE]); readiness_ = A[READINESS]; expType_ = A[EXPTYPE]; name_ = bin.getObjectText(NAME); bin.nextTag(CUNITS); if (bin.hasChildren()) { bin.firstChild(); while (!bin.reachedEndTag(CUNITS)) { bin.nextTag(CUNIT); Dictionary <string, string> D = bin.getAttributes(); uint u = EncodeUtil.parseUInt(D[CUNITID]); cunits_.Add(u); bin.endTag(CUNIT); } } bin.endTag(CUNITS); ord_ = new COrder(bin); entry_ = query.unitQuery(utype_); }
public CSupplyRoute( uint rid, uint source, CLoc sourceLoc, uint dest, CLoc destLoc, uint inTransit, uint nextArrival ) { rid_ = rid; source_ = source; sourceLoc_ = sourceLoc; dest_ = dest; destLoc_ = destLoc; inTransit_ = inTransit; nextArrival_ = nextArrival; }
public void setResource(CLoc loc, int rv) { if (rv == 0 && resources_.ContainsKey(loc.getKey())) { resources_.Remove(loc.getKey()); } else if (rv > 0) { if (resources_.ContainsKey(loc.getKey())) { resources_[loc.getKey()] = rv; } else { resources_.Add(loc.getKey(), rv); } } }
//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //Just get it off me - assumed stack level == 1 public void ejectFlyover() { pollAllEvents(); if (foUnit_ == null) { return; } //second send home var ord = new COrder(COrderConstants.ORD_GO_HOME); setAndExecuteUnitOrder(foUnit_.gid_, ord); pollAllEvents(); if (foUnit_ == null) { return; } //third. move in open space for (int i = CMapUtil.NORTH; i < CMapUtil.NODIR; i++) { CLoc uloc = foUnit_.getLoc(); CLoc loc = map_.getNextLocationFromDir(uloc.x, uloc.y, i); if (loc == null) { continue; } CUnit cu = getHostAtLoc(loc, CUnitConstants.LVL_GROUND, 0u); if (cu == null || (cu.owner_ != position_ && !foUnit_.entry_.isCity())) { ord = new COrder(COrderConstants.ORD_MOVE_DIR, i); setAndExecuteUnitOrder(foUnit_.gid_, ord); pollAllEvents(); } if (foUnit_ == null) { return; } } //finally disband disbandUnit(foUnit_.gid_); pollAllEvents(); }
//Get A Specific Unit in a specific loc at a specific layer public CUnit getHostAtLoc(CLoc l, string level, uint layer) { CUnit[] hosts = getHostsAtLoc(l); if (hosts == null) { return(null); } switch (level) { case CUnitConstants.LVL_ORB: return(hosts[CUnitConstants.ORB_LEVEL_INDEX]); case CUnitConstants.LVL_SUB: return(hosts[CUnitConstants.SUB_LEVEL_INDEX]); default: return(hosts[CUnitConstants.STACK_GROUND_INDEX + layer]); } }
public CProductionReportData( string rtype, string report, string ptype, int value, string ctype, CLoc loc, uint pkey, uint ckey ) { rtype_ = rtype; report_ = report; ptype_ = ptype; value_ = value; ctype_ = ctype; loc_ = loc; pkey_ = pkey; ckey_ = ckey; }
public List <CLoc> getAdjacentSeaLocs(CLoc loc) { var locs = new List <CLoc>(); for (int dir = CMapUtil.NORTH; dir <= CMapUtil.NORTHWEST; dir++) { string ml = getLocationFromDir(loc.x, loc.y, dir, 1); if (ml == null) { continue; } if (ml == EmpireCC.CT_SEA || ml == EmpireCC.CT_SHALLOWSEA) { CLoc L = getNextLocationFromDir(loc.x, loc.y, dir); if (L != null) { locs.Add(L); } } } return(locs); }
public void removeMineOrRoad(CLoc coord) { command_.removeMineOrRoad(position_, coord); pollAllEvents(); }
//buypoints commands - results gain via event poll public void placeBPUnit(string placeType, CLoc coord) { command_.placeBPUnit(position_, placeType, coord); pollAllEvents(); }
public bool isMine(CLoc loc) { return(mines_.ContainsKey(loc.getKey())); }
public CProducerUnit(string utype, uint gid, CLoc loc, UnitQueryI entry) : base(utype, gid, loc, entry) { }
public bool isWasteland(CLoc loc) { return(wasteland_.ContainsKey(loc.getKey())); }
public bool hasRoad(CLoc loc) { return(roads_.ContainsKey(loc.getKey())); }
public int move_dir_l(CLoc beg_loc, CLoc end_loc) { int dr = end_loc.y - beg_loc.y; int dc = end_loc.x - beg_loc.x; if (dr == 0 && dc == 0) { return(CMapUtil.NODIR); } if (mapUtil_.hwrap_) { if (dc * 2 > mapUtil_.width_) { dc = dc - mapUtil_.width_; } else if (dc * 2 < -mapUtil_.width_) { dc += mapUtil_.width_; } } if (mapUtil_.vwrap_) { if (dr * 2 > mapUtil_.height_) { dr = dr - mapUtil_.height_; } else if (dr * 2 < -mapUtil_.height_) { dr += mapUtil_.height_; } } if (Math.Abs(dc) > Math.Abs(dr)) { if (dc > 0) { return(CMapUtil.EAST); } else { return(CMapUtil.WEST); } } else if (dc == dr) { if (dc > 0) { return(CMapUtil.SOUTHEAST); } else { return(CMapUtil.NORTHWEST); } } else if (dc == -dr) { if (dc > 0) { return(CMapUtil.NORTHEAST); } else { return(CMapUtil.SOUTHWEST); } } else if (dr > 0) { return(CMapUtil.SOUTH); } else { return(CMapUtil.NORTH); } }