def toNextTargetableSpace(): targets = logic.globalDict['spaceTarget'] if targets != []: # Cycle list until first entry is a valid target for command validTargetExists = cycleUntilValidTarget(targets) if not validTargetExists: return # Position that cursor will move to position = getPosition.onGround(targets[0]['space']) # Cursor moved (Wasn't already in position) cursorMoved = moveToPosition(position) # NOTE(kgeffen) If cursor is already at position (Didn't move), # cycle targets at least once, then get new first target's position if cursorMoved == False: # Cycle once so fresh entry is chosen cycleList(targets) # Cycle until valid target is found cycleUntilValidTarget(targets) # Move to newly cycled first entry in list of spaces position = getPosition.onGround(targets[0]['space']) moveToPosition(position)
def createGameObject(unit): battlefield = sceneControl.get('battlefield') # Add game object obj = battlefield.addObject('unit', 'ground') # Adjust objects position to match data obj.worldPosition = getPosition.onGround(unit['position']) return obj
def toSpace(unit, space): # Move object # NOTE(kgeffen) This has to happen first because objects gotten based on position obj = unitObject.get(unit) obj.worldPosition = getPosition.onGround(space) # Adjust position stored in unit's data x = round(space[0]) y = round(space[1]) unit['position'] = [x,y]
def add(space, markerName): # If space is in bounds if not check.outOfBounds(space): position = getPosition.onGround(space) # Get battlefield scene battlefield = sceneControl.get('battlefield') # NOTE(kgeffen) Ground is arbitrarily the object adding the marker obj = battlefield.addObject(markerName, 'ground') obj.worldPosition = position
def free(rng): actor = logic.globalDict["actor"] actorPosition = getPosition.onGround(actor["position"]) # targetOffset - Offset from actor in form [x,y] for targetOffset in rng["range"]: targetX = actorPosition[0] + targetOffset[0] targetY = actorPosition[1] + targetOffset[1] targetSpace = [targetX, targetY] storeValidSpace.attempt(actorPosition, targetSpace, rng)
def toNextActor(strict): # Units that act this turn (First turn, first group in turn) # NOTE(kgeffen) This relies on current turn always having actors actors = logic.globalDict['time'][0][0] # Cycle the list of actors until the first actor in list can move/act # If strict is True, first actor must have remaining act, not just mv # If no units are valid, return validUnitExists = cycleUntilFirstUnitActs(actors, strict) if not validUnitExists: return # Position that cursor will move to position = getPosition.onGround(actors[0]['position']) # cursorMoves == True if cursor didn't start at _position_ cursorMoved = moveToPosition(position) # NOTE(kgeffen) If cursor didn't move (was already at position), # cycle units once, then get new first unit's position if not cursorMoved: # Cycle once so fresh entry is chosen cycleList(actors) # NOTE(kgeffen) If code has gotten this far, valid unit must exist # because last cycle would have returned if not cycleUntilFirstUnitActs(actors, strict) # This is the position of the first unit in newly cycled list of actors position = getPosition.onGround(actors[0]['position']) moveToPosition(position) # NOTE(kgeffen) Necessarily cycle each time to ensure that # if cursor moves to unit A, then I act with it, move cursor, # next time I toNext, the cursor moves to unit B not A cycleList(actors)
def spaceValid(actorPosition, targetSpace, rng): # Invalid if space out of bounds if check.outOfBounds(targetSpace): return False targetPosition = getPosition.onGround(targetSpace) # Invalid if target space has height 0 if targetPosition[2] == 0: return False # Invalid if height difference outside acceptable bounds dz = targetPosition[2] - actorPosition[2] if dz > rng['okDz']['max'] or dz < rng['okDz']['min']: return False return True
def rigid(rng): actor = logic.globalDict["actor"] actorPosition = getPosition.onGround(actor["position"]) # Point in each of 4 cardinal directions # NOTE(kgeffen) Start with space rotated by quarter circle from front, # go to space rotated by half circle, etc. # Order matters! for dv in ([1, 0], [0, -1], [-1, 0], [0, 1]): # Rotate range by 90 degrees # Ex: special space [2,0] becomes [0,-2] rotateRange(rng) # targetOffset - Offset from space on given side of actor (space = actorPosition + dv) for targetOffset in rng["range"]: targetX = actorPosition[0] + targetOffset[0] + dv[0] targetY = actorPosition[1] + targetOffset[1] + dv[1] targetSpace = [targetX, targetY] storeValidSpace.attempt(actorPosition, targetSpace, rng)
def storeTargetableSpace(actorPosition, targetSpace, rng): targetPosition = getPosition.onGround(targetSpace) # Get a list of all spaces within area of effect effectedSpaces = getEffectedSpaces(actorPosition, targetSpace, rng) # List of all units effected by command effectedUnits = getEffectedUnits(effectedSpaces) # Record all spaces that have special meaning for command # Ex: Space that actor moves to, spaces that must be empty, etc. specialSpaces = attemptGetSpecialSpaces(actorPosition, targetSpace, rng) if specialSpaces == False: # If any of the special spaces are invalid return # Add given space to list of all spaces that command can target formattedEntry = {'space' : targetSpace, 'effectedSpaces' : effectedSpaces, 'units' : effectedUnits, 'specialSpaces' : specialSpaces} logic.globalDict['spaceTarget'].append(formattedEntry)
def displayResult(result): textObj = objectControl.getFromScene('commandResult', 'battlefield') # Reset alpha to 1.0 textObj.color = (1, 1, 1, 1) # Set text textObj['Text'] = result['text'].capitalize() # Set postion position = getPosition.onGround(result['space']) position[2] += HEIGHT_ABOVE textObj.worldPosition = position # Adjust rotation to face camera adjustRotation(textObj) # The number of characters in the text numChars = len(result['text']) # Center the text object over the unit it describes centerText(textObj, numChars)
def moveCursorToActor(): cursor = objectControl.getFromScene('cursor', 'battlefield') actor = logic.globalDict['actor'] cursor.worldPosition = getPosition.onGround(actor['position'])
def toActor(): actor = logic.globalDict['actor'] position = getPosition.onGround(actor['position']) moveToPosition(position)
def do(): cursor = objectControl.getFromScene('cursor', 'battlefield') # Raise/lower cursor to be directly on top of ground cursor.worldPosition = getPosition.onGround(cursor.worldPosition)