def move(session, stack_id, environ_id): # need to make sure stack_id and enviorn_id are in the same game # this can be checked by ensuring stack.game_id = environ.planet.game_id # See if new location can be grabbed try: newloc = session.query(Environ).filter_by(id=environ_id).one() except exc.NoResultFound: newloc = None # See if old location can be grabbed try: oldloc = session.query(Stack).filter_by(id=stack_id).one().environ except exc.NoResultFound: oldloc = None # Check if either are None if newloc is not None: # Check if they aren't adjacent if oldloc != None: if (oldloc.location != 0) or (newloc.location != 0): stack = session.query(Stack).filter_by(id=stack_id).one() if (stack.can_fly()): return False, "Invalid Move, Full Stack does not have space capabilities." if oldloc.planet != newloc.planet: if oldloc.location == newloc.location == 0: pass else: return False, "Invalid Move, must go through orbit box to travel between planets." # if (oldloc.location != 0) and (newloc.location != 0): # if (session.query(Stack).filter_by(id = stack_id).one().spaceship()): # return False, "Invalid Move, Stack does not have space capabilities." else: pass else: # One is None, exit return False, "Invalid Move" if (newloc.planet.pdb_state != 0): stack = (session.query(Stack).filter_by(id=stack_id).one()) if stack.spaceship(): detection_routine(session, stack_id, newloc.planet.pdb_level) try: moving_stack = session.query(Stack).filter_by(id=stack_id).one() except: success = False else: success = True moving_stack.environ = newloc session.add(moving_stack) if success: session.commit() return success, moving_stack.__dict__ else: return success, "FATAL: Unable to find stack!"
def move(session, stack_id, environ_id): # need to make sure stack_id and enviorn_id are in the same game # this can be checked by ensuring stack.game_id = environ.planet.game_id # See if new location can be grabbed try: newloc = session.query(Environ).filter_by(id = environ_id).one() except exc.NoResultFound: newloc = None # See if old location can be grabbed try: oldloc = session.query(Stack).filter_by(id = stack_id).one().environ except exc.NoResultFound: oldloc = None # Check if either are None if newloc is not None: # Check if they aren't adjacent if oldloc != None: if (oldloc.location != 0) or (newloc.location != 0): stack = session.query(Stack).filter_by(id = stack_id).one() if (stack.can_fly()): return False, "Invalid Move, Full Stack does not have space capabilities." if oldloc.planet != newloc.planet: if oldloc.location == newloc.location == 0: pass else: return False, "Invalid Move, must go through orbit box to travel between planets." # if (oldloc.location != 0) and (newloc.location != 0): # if (session.query(Stack).filter_by(id = stack_id).one().spaceship()): # return False, "Invalid Move, Stack does not have space capabilities." else: pass else: # One is None, exit return False, "Invalid Move" if (newloc.planet.pdb_state != 0): stack = (session.query(Stack).filter_by(id = stack_id).one()) if stack.spaceship(): detection_routine(session, stack_id, newloc.planet.pdb_level) try: moving_stack = session.query(Stack).filter_by(id = stack_id).one() except: success = False else: success = True moving_stack.environ = newloc session.add(moving_stack) if success: session.commit() return success, moving_stack.__dict__ else: return success, "FATAL: Unable to find stack!"
def move(session, stack_id, environ_id): # need to make sure stack_id and enviorn_id are in the same game # this can be checked by ensuring stack.game_id = environ.planet.game_id # See if new location can be grabbed try: newloc = session.query(Environ).filter_by(id = environ_id).one() except exc.NoResultFound: newloc = None # See if old location can be grabbed try: oldloc = session.query(Stack).filter_by(id = stack_id).one().environ except exc.NoResultFound: oldloc = None # Check if either are None if newloc is not None: # Check if they aren't adjacent if oldloc != None: if oldloc.planet != newloc.planet: return False, "Invalid Move" else: # One is None, exit return False, "Invalid Move" if (newloc.planet.pdb_state != 0) and (session.query(Stack).filter_by(id = stack_id).one().spaceship()): detection_routine(session, stack_id, newloc.planet.pdb_level) try: moving_stack = session.query(Stack).filter_by(id = stack_id).one() except: success = False else: success = True moving_stack.environ = newloc session.add(moving_stack) if success: session.commit() return success, moving_stack.__dict__ else: return success, "FATAL: Unable to find stack!"