def post(self): req = self.request msg = ChatMessage() msg.text = req("text") msg.unitfrom = Unit.get_by_id(req("fromid")) msg.unitto = Unit.get_by_id(req("toid")) msg.put()
def get(self): #move the unit towards the x and y goto positions #xy = re.match('tile(\d+)', self.request.get("tile_id")).groups() x_goto = int(self.request.get("x-goto")) y_goto = int(self.request.get("y-goto")) unitID = int(re.match('unit(\d+)', self.request.get("unitid")).group(1)) destinationTile = Tile.gql("where x = :1 ans y = :2",x_goto, y_goto); if destinationTile.type.canTravel: # just select the unit with that id unit = Unit.get_by_id(unitID) if unit.x > x_goto: unit.x = unit.x - 1 elif unit.x < x_goto: unit.x = unit.x + 1 if unit.y > y_goto: unit.y = unit.y - 1 elif unit.y < y_goto: unit.y = unit.y + 1 unit.put() self.response.out.write("ok") else: self.response.out.write("obstructed")
def get(self): map = memcache.get("map") HeightMapData = FetchImage("http://humanitymmo.appspot.com/static/earthmini.png") w,h = HeightMapData[:2] # should get the tiles, within proximity of units. # foreach unit, get tiles within range of the unit # in this instance limit it to 1 unit only unit = Unit.get_by_id( int(self.request.get("id")) ) json = {"tiles":[],"enemyunits":[]} fov = 2 # fov is how many tiles a unit can see around it xleft = max(unit.x - fov, 0) xright = min(unit.x + fov + 1, w) ytop = max(unit.y - fov, 0) ybottom = min(unit.y + fov + 1, h) # get heightmap based tiles for x in range(xleft, xright): for y in range(ytop, ybottom): # is the tile in the datastore curTile = Tile.gql("where x = :1 and y = :2", x,y) if curTile.count() > 0: if curTile.type.canTravel: curAlt = 80 else: curAlt = 81 json["tiles"].append( {"x":curTile.x,"y":curTile.y,"alt":curAlt} ) else alt = GetHeightAt(x,y,HeightMapData) json["tiles"].append( {"x":x, "y":y, "alt":alt } ) # write to datastore t = Tile() t.x = x t.y = y t.height = alt if alt < 81: # get tile type where name = water, then reference it else: # get tile type for land t.put() self.response.out.write(demjson.encode(json))