Example #1
0
 def buildObjectCancel(self, oldobj, user):
     """Cancel a partially built object do it being destroyed or maually cancelled during
     construction"""
     u =  User.all().filter('FacebookID =', user.FacebookID).get()
     
     # Proximity fetch
     milesToMeters = 1609.4
     distance = Constants.getBaseDistance() * Constants.latToMiles() * milesToMeters
     
     # Find the build object
     cls = oldobj.getClass()
     query = cls.all().filter('isComplete =', False).filter('user =', u)
     obj = cls.proximity_fetch(query, oldobj.getPosition()[0], max_results = 1, max_distance = distance)
     if obj is None:
         logging.error("Unknown objects" + str(oldobj) + ":" + str(user))
         return
     if len(obj) == 0:
         for val in query.fetch(1000):
             logging.error(val.toXML())
             logging.error(val.location)
             logging.error(val.location_geocells)
         # Find out where the error is
         logging.error(str(distance))
         pt = oldobj.getPosition()
         pos = pt[0]
         logging.error(pt)
         logging.error(pos)
         return
         
     obj = obj[0]                # Get the first value of the fetch
     # Delete the built object
     obj.delete()            
Example #2
0
 def buildObjectComplete(self, oldobj, user, broadcast):
     """Finish the object building"""
     logging.error("buildObjectComplete")
     u =  User.all().filter('FacebookID =', user.FacebookID).get()
     
     # Proximity fetch
     milesToMeters = 1609.4
     distance = Constants.getBaseDistance() * Constants.latToMiles() * milesToMeters
     
     # Find the build object
     cls = oldobj.getClass()
     query = cls.all().filter('isComplete =', False).filter('user ='******'user !=', u)
         for key in u.neighbors:
             neighbor = db.get(key)
             whichObject.filter('user !=', neighbor)
         
       
         for pos in obj.getPosition():
             valueList = gameObject.proximity_fetch(whichObject, pos, max_results = 1000, max_distance = distance)
             if valueList is not None:
                 # Iterate over the results
                 for obj in valueList:
                     otherUser = obj.user
                     if not otherUser in u.neighbors:
                         # Add to both neighbors
                         u.neighbors.append(otherUser.key())
                         otherUser.neighbors.append(u.key())
                         otherUser.put()
     # Put the current user
     u.put()
     
     # Instantiate the game manager, and build the object        
     if broadcast:            
         manager = GameManager(u)
         manager.build(obj)
     return None