コード例 #1
0
ファイル: EntityManager2.py プロジェクト: Syrdni/AiBattle
    def craftsmanNeeded():
        if EntityManager.craftsmenCount > 0:
            return False

        for id in EntityManager.craftsmen:
            if EntityManager.craftsmen[id].building == None:
                return False

        return BuildingManager.findEmptyBuilding(
        ) or BuildingManager.getWorksite()
コード例 #2
0
    def execute(craftsman):
        # Check if an empty building exists
        craftsman.building = BuildingManager.findEmptyBuilding()

        if craftsman.building:
            craftsman.building.craftsmanId = craftsman.id
            craftsman.changeState(WorkInBuilding)
            return

        # Check if an empty worksite exists
        craftsman.building = BuildingManager.getWorksite()

        if craftsman.building:
            craftsman.changeState(BuildBuilding)
            return
コード例 #3
0
 def enter():
     # Charge-scatter on enemy base
     for id in EntityManager.explorers:
         explorer = EntityManager.explorers[id]
         explorer.target = BuildingManager.getEnemyCastle()
         explorer.charge = True
         explorer.changeState(Charge)
コード例 #4
0
	def execute(soldier):
		# Stop attacking
		if soldier.worker:
			if Pos.getDistance(soldier.getPosition(), soldier.worker.getPosition()) > Soldier.guardRange:
				soldier.changeState(LifeGuarding)
		elif Pos.getDistance(soldier.getPosition(), BuildingManager.getCastle()) > Soldier.guardRange:
			soldier.changeState(Guarding)
コード例 #5
0
    def detectAttacks():
        return False
        soldiers = 0
        castlePos = BuildingManager.getCastle()

        for id in EntityManager.enemySoldiers:
            if Pos.getDistance(castlePos, EntityManager.enemySoldiers[id].
                               getPosition()) < StrategyManager.defendRadius:
                soldiers += 1

        return soldiers >= StrategyManager.defendCount
コード例 #6
0
    def onMessage(self, message):
        if message['type'] == 'buildComplete':
            newBuilding = Building(self.building.id, self.building.pos)
            buildingType = self.building.type
            BuildingManager.removeBuilding(self.building.id,
                                           StrategyManager.team, 'built')
            BuildingManager.addBuilding(newBuilding, buildingType)
            self.changeState(Idle)
        elif message['type'] == 'craftComplete':
            if self.building.type == 'kiln':
                ResourceManager.addItem('charCoal')
            elif self.building.type == 'smelter':
                ResourceManager.addItem('iron')
            elif self.building.type == 'smithy':
                ResourceManager.addItem('sword')

            self.crafting = False
            self.changeState(WorkInBuilding)

        if self.charge and message['type'] == 'tasksComplete':
            self.changeState(Scatter)
コード例 #7
0
	def enter(worker):
		if len(ResourceManager.ironOre) > 0:
			resource = ResourceManager.findOre()
			
			if resource:
				worker.harvestResource(resource)
			else:
				worker.changeState(ChopTree)
		else:
			if len(EntityManager.soldiers) >= 3:
				worker.target = BuildingManager.getEnemyCastle()
				
				if worker.target:
					worker.changeState(Charge)
				return
				
			worker.changeState(FindWork)
コード例 #8
0
    def attackIntruders():
        return
        castlePos = BuildingManager.getCastle()

        # Attack with guarding soldiers when enemy soldiers near base
        for id in EntityManager.enemySoldiers:
            enemySoldier = EntityManager.enemySoldiers[id]

            if Pos.getDistance(
                    castlePos,
                    enemySoldier.getPosition()) < Soldier.guardRange:
                for soldierId in EntityManager.soldiers:
                    soldier = EntityManager.soldiers[soldierID]

                    if soldier.state == Guarding:
                        soldier.enemy = enemySoldier
                        soldier.changeState(Attack)
コード例 #9
0
	def enter(worker):
		worker.setTarget(BuildingManager.getCastle())
コード例 #10
0
ファイル: EntityManager2.py プロジェクト: Syrdni/AiBattle
    def setExploreArea(explorer):
        if explorer.side != 0:
            side = explorer.side
        else:
            side = EntityManager.exploreSide

        explorer.side = side

        if side == 0:
            charge = False

            if EntityManager.deltaExploreX > 0 and EntityManager.currentExploreX < 3:
                charge = True
            elif EntityManager.deltaExploreX < 0 and EntityManager.currentExploreX > EntityManager.mapSize - 3:
                charge = True
            elif EntityManager.deltaExploreZ > 0 and EntityManager.currentExploreZ < 3:
                charge = True
            elif EntityManager.deltaExploreZ < 0 and EntityManager.currentExploreZ > EntityManager.mapSize - 3:
                charge = True

            if charge:
                explorer.target = BuildingManager.getEnemyCastle()

                if explorer.target:
                    explorer.changeState(Explorer2.Charge)
                    return False
                return True

            explorer.x = EntityManager.currentExploreX
            explorer.z = EntityManager.currentExploreZ
            EntityManager.exploreSide = 1
        elif side == 1:
            EntityManager.currentExploreX -= EntityManager.deltaExploreX

            charge = False

            if EntityManager.deltaExploreX > 0 and EntityManager.currentExploreX < 3:
                charge = True
            elif EntityManager.deltaExploreX < 0 and EntityManager.currentExploreX > EntityManager.mapSize - 3:
                charge = True
            elif EntityManager.deltaExploreZ > 0 and EntityManager.currentExploreZ < 3:
                charge = True
            elif EntityManager.deltaExploreZ < 0 and EntityManager.currentExploreZ > EntityManager.mapSize - 3:
                charge = True

            if charge:
                explorer.target = BuildingManager.getEnemyCastle()

                if explorer.target:
                    explorer.changeState(Explorer2.Charge)
                    return False
                return True

            explorer.x = EntityManager.currentExploreX
            explorer.z = EntityManager.exploreMaxZ
            EntityManager.exploreSide = 2
        else:
            EntityManager.currentExploreZ -= EntityManager.deltaExploreZ

            charge = False

            if EntityManager.deltaExploreX > 0 and EntityManager.currentExploreX < 3:
                charge = True
            elif EntityManager.deltaExploreX < 0 and EntityManager.currentExploreX > EntityManager.mapSize - 3:
                charge = True
            elif EntityManager.deltaExploreZ > 0 and EntityManager.currentExploreZ < 3:
                charge = True
            elif EntityManager.deltaExploreZ < 0 and EntityManager.currentExploreZ > EntityManager.mapSize - 3:
                charge = True

            if charge:
                explorer.target = BuildingManager.getEnemyCastle()

                if explorer.target:
                    explorer.changeState(Explorer2.Charge)
                    return False
                return True

            explorer.x = EntityManager.exploreMaxX
            explorer.z = EntityManager.currentExploreZ
            EntityManager.exploreSide = 1

        return True