コード例 #1
0
    def getPointsData(self):
        msg = ""
        for name,data in self.sides.items():
            msg += "  TEAM: "+name+"\n"
            total = 0
            for obj in data['team']['agents'].values():
                msg += "    "+obj.getBestDisplayName()+": "+str(obj.getData('points'))+"\n"
                total += obj.getData('points')
            msg += "    TOTAL: "+str(total)+"\n"

        m=msgs.Msg(str(self.tick),"CURRENT POINTS",msg)
        self.imsgr.addMsg(m)
コード例 #2
0
    def ACTN_Turn(self,obj,actn):

        cur_facing = obj.getData('facing')
        new_facing = cur_facing + actn.getData('turnrate')
        while new_facing < 0:
            new_facing += 360
        while new_facing >= 360:
            new_facing -= 360
        obj.setData('facing',new_facing)
コード例 #3
0
    def ACTN_BroadcastMessage(self,obj,actn):

        view = {}
        view['vtype']='message'
        view['tick']=self.tick
        view['message']=actn.getData('message')

        for uuid,other_obj in self.objs.items():
            if uuid != obj.getData('uuid'):

                distance = zmath.distance(
                    obj.getData('x'),obj.getData('y'),
                    other_obj.getData('x'),other_obj.getData('y')
                )
                
                # if the distance to the other obj is less than
                # the broadcast range, add the view.
                if distance <= actn.getData('range'):
                    self.addCompView(uuid,view)
コード例 #4
0
    def ACTN_DropItem(self,obj,actn):
        print('Dropping item')
        obj_x = obj.getData('x')
        obj_y = obj.getData('y')

        arm_comp = obj.getComp(actn.getData('slot_id'))
        if arm_comp == None:
            return

        if arm_comp.isHoldingItem():
            held_item_uuid = arm_comp.getData('item')
            held_item = self.items[held_item_uuid]

            drop_location = actn.getData('location')

            # Action must specify a valid drop location before
            # the item is dropped.
            if drop_location=='cell':
                print('Drop successful')
                self.map.addItem(obj_x,obj_y,held_item_uuid)
                arm_comp.setData('item',None)
                held_item.dropItem()
コード例 #5
0
    def ACTN_HighspeedProjectile(self,obj,actn):

        view = self.view_manager.getViewTemplate('projectile')
        view['compname']=actn.getData('compname')
        
        # Get list of cells through which the shell travels.
        cells_hit = zmath.getCellsAlongTrajectory(
            obj.getData('x'),
            obj.getData('y'),
            actn.getData('direction'),
            actn.getData('range')
        )

        # Get the list of cells through which the shell travels.
        damage = random.randint(actn.getData('min_damage'),actn.getData('max_damage'))

        # If there's something in a cell, damage the first thing
        # along the path and quit.
        for cell in cells_hit:
            id_in_cell = self.map.getCellOccupant(cell[0],cell[1])
            if id_in_cell == obj.getData('uuid'):
                continue
            elif id_in_cell != None:

                view['hit_x']=cell[0]
                view['hit_y']=cell[1]
                view['name']=self.objs[id_in_cell].getData('name')

                damage_str = obj.getBestDisplayName()+" shot "+self.objs[id_in_cell].getBestDisplayName() + \
                    " for "+str(damage)+" points of damage."
                self.logMsg("DAMAGE",damage_str)

                points = self.damageObj(id_in_cell,damage)

                obj.setData('points',points)

                break

        self.addCompView(obj.getData('uuid'),view)
コード例 #6
0
    def ACTN_TakeItem(self,obj,actn):

        take_location = actn.getData('location')

        # If we're taking from the cell,
        # or if a take location was not provided, take from cell.
        if take_location=='cell' or take_location is None:

            obj_x = obj.getData('x')
            obj_y = obj.getData('y')
            items_in_obj_cell = self.map.getItemsInCell(obj_x,obj_y)

            if len(items_in_obj_cell) > 0:
                item_name = actn.getData('item_name')
                item_index = actn.getData('item_index')
                item_uuid = actn.getData('item_uuid')
                

                matching_item = None

                # If the action provided a specific uuid,
                # look only for that and ignore the other info.
                if item_uuid is not None:
                    if item_uuid in items_in_obj_cell:
                        matching_item=item_uuid
                
                elif item_name is not None:
                    for item_id in items_in_obj_cell:
                        item = self.items[item_id]
                        if item.getData('name')==item_name:
                            matching_item=item_id
                            break
                elif item_index is not None:
                    if len(items_in_obj_cell) > item_index:
                        matching_item = items_in_obj_cell[item_index]

                else:
                    if len(items_in_obj_cell) > 0:
                        matching_item = items_in_obj_cell[0]

                if matching_item is not None:
                    item_to_take = self.items[matching_item]
                    
                    # Get the arm component and make sure it isn't None
                    arm_comp = obj.getComp(actn.getData('slot_id'))
                    if arm_comp == None:
                        print('ArmComp is None')
                        return

                    if not arm_comp.isHoldingItem():
                        if arm_comp.canTakeItem(item_to_take.getData('weight'),item_to_take.getData('bulk')):
                            arm_comp.setData('item',matching_item)
                            self.map.removeItem(obj_x,obj_y,matching_item)
                            item_to_take.takeItem(obj.getData('uuid'))
                            print('Take successful.')
                        else:
                            print('Item too heavy or bulky.')
                            pass
                    else:
                        print('Arm is already packing.')
                        pass
コード例 #7
0
    def ACTN_TransmitRadar(self,obj,actn):

        view = self.view_manager.getViewTemplate('radar')
        view['tick']=self.tick
        view['ctype']=actn.getData('ctype')
        view['compname']=actn.getData('compname')
        view['slot_id']=actn.getData('slot_id')

        # Set up the necessary data for easy access
        radar_facing = obj.getData('facing')+actn.getData('offset_angle')
        start = radar_facing-actn.getData('visarc')
        end = radar_facing+actn.getData('visarc')
        angle = start
        jump = actn.getData('resolution')
        x = obj.getData('x')
        y = obj.getData('y')
        _range = actn.getData('range')

    

        temp_view = []

        # While we're in our arc of visibility
        while angle <= end:
            # Get all object/item pings along this angle
            pings = self.map.getAllObjUUIDAlongTrajectory(
                x,y,angle,_range
            )
            # Pings should be in order. Start adding if they're not there.
            # If the radar's level is less than the obj's density, stop. We can't see through.
            # Else keep going.
            obj_pings = pings['objects']
            item_pings = pings['items']
            
            for ping in obj_pings:

                # Pinged ourself
                if ping['x']==obj.getData('x') and ping['y']==obj.getData('y'):
                    pass
                else:
                    # For now all we're giving the transmitting player
                    # the object name. Up to the player to figure out
                    # if this is a teammate.
                    ping['name']=self.objs[ping['uuid']].getData('name')
                    
                    # Make sure the reported direction is 0-360
                    direction = angle
                    if direction < 0:
                        direction += 360
                    if direction >= 360:
                        direction -= 360

                    ping['direction']=direction
                    ping['cell_x']=self.objs[ping['uuid']].getData('cell_x')
                    ping['cell_y']=self.objs[ping['uuid']].getData('cell_y')
                    ping['alive']=self.objs[ping['uuid']].isAlive()
                    temp_view.append(ping)
                    
                    # If our radar level can't penetrate the object, stop.
                    if actn.getData('level') < self.objs[ping['uuid']].getData('density'):
                        break

            for ping in item_pings:

                item = self.items[ping['uuid']]

                # Make sure the reported direction is 0-360
                direction = angle
                if direction < 0:
                    direction += 360
                if direction >= 360:
                    direction -= 360

                ping['direction']=direction
                ping['name']=item.getData('name')
                ping['weight']=item.getData('weight')
                ping['bulk']=item.getData('bulk')
                ping['owner']=item.getData('owner')
                temp_view.append(ping)

            if jump == 0:
                break
            else:
                angle += jump



        for ping in temp_view:
            del ping['uuid']
            view['pings'].append(ping)

        self.addCompView(obj.getData('uuid'),view)
コード例 #8
0
    def ACTN_Move(self,obj,actn):
        # Get current data
        facing = obj.getData('facing')
        cur_speed = actn.getData('speed')
        old_x = obj.getData('x')
        old_y = obj.getData('y')
        old_cell_x = obj.getData('cell_x')
        old_cell_y = obj.getData('cell_y')
        x = old_x + old_cell_x
        y = old_y + old_cell_y
        # translate and new data
        new_position = zmath.translatePoint(x,y,facing,cur_speed)
        new_x = int(new_position[0])
        new_y = int(new_position[1])
        new_cell_x = abs(new_position[0]-abs(new_x))
        new_cell_y = abs(new_position[1]-abs(new_y))

        # see if move is possible.
        if new_x != old_x or new_y != old_y:

            # Might be moving more than 1 cell. Get trajectory.
            cell_path = zmath.getCellsAlongTrajectory(x,y,facing,cur_speed)

            cur_cell = (old_x,old_y)
            collision = False

            # for all cells in the path, update if empty.
            for cell in cell_path:
                if cell == (old_x,old_y):
                    continue
                else:
                    if self.map.isCellEmpty(cell[0],cell[1]):
                        cur_cell = cell
                    else:
                        collision=True
                        break
            
            new_x = cur_cell[0]
            new_y = cur_cell[1]

            # Move the object
            self.map.moveObjFromTo(obj.getData('uuid'),old_x,old_y,new_x, new_y)
            obj.setData('x',new_x)
            obj.setData('y',new_y)
            obj.setData('cell_x',new_cell_x)
            obj.setData('cell_y',new_cell_y)

            # Update held item's locations
            item_uuids = obj.getAllHeldStoredItems()
            for _uuid in item_uuids:
                i = self.items[_uuid]
                i.setData('x',new_x)
                i.setData('y',new_y)

            if collision:
                # CRASH INTO SOMETHING
                
                # We need to move the obj to the edge
                # of the old cell to simulate that they reached the edge of it before
                # crashing.
                if new_x != old_x:
                    if new_x > old_x:
                        obj.setData('cell_x',0.99)
                    else:
                        obj.setData('cell_x',0.0)
                if new_y != old_y:
                    if new_y > old_y:
                        obj.setData('cell_y',0.99)
                    else:
                        obj.setData('cell_y',0.0)

        # Didn't leave the cell, update in-cell coords.      
        else:
            obj.setData('cell_x',new_cell_x)
            obj.setData('cell_y',new_cell_y)
            pass