-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.py
51 lines (42 loc) · 1.54 KB
/
ai.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import libtcodpy as tcod
import settings
from message import message
class BasicMonster:
# AI for a basic monster
def take_turn(self):
# a basic enemy takes its turn. if you can see it, it can see you
monster = self.owner
if tcod.map_is_in_fov(settings.fov_map, monster.x, monster.y):
if monster.distance_to(settings.player) >= 2:
monster.move_astar(settings.player)
elif settings.player.combatant.hp > 0:
monster.combatant.set_target(target=settings.player)
monster.combatant.attack(settings.player)
monster.combatant.set_direction(settings.player.x, settings.player.y)
class ConfusedMonster:
# AI for confused monster
def __init__(self, old_ai, num_turns=settings.CONFUSE_NUM_TURNS):
self.old_ai = old_ai
self.num_turns = num_turns
def take_turn(self):
if self.num_turns > 0:
# move in a random direction
self.owner.move(tcod.random_get_int(0, -1, 1), tcod.random_get_int(0, -1, 1))
self.num_turns -= 1
else:
self.owner.ai = self.old_ai
message("The " + self.owner.name + " is no longer confused!", tcod.red)
class HeldMonster:
def __init__(self, old_ai, num_turns=settings.HOLD_NUM_TURNS):
self.old_ai = old_ai
self.num_turns = num_turns
def take_turn(self):
if self.num_turns > 0:
monster = self.owner
if tcod.map_is_in_fov(settings.fov_map, monster.x, monster.y):
if monster.distance_to(settings.player) < 2:
monster.combatant.attack(settings.player)
self.num_turns -= 1
else:
self.owner.ai = self.old_ai
message("The " + self.owner.name + " is no longer held!", tcod.red)