Refactor Action into Action and ActionWithActor

The base class Actor doesn't declare a (optional) actor attribute.
The ActionWithActor has a non-optional actor attribute.

This makes the type checker happier, and means we can have some actions
that don't have actors.
This commit is contained in:
Eryn Wells 2023-02-12 16:34:37 -08:00
parent 8efd3ce207
commit 7e00f58a40
5 changed files with 72 additions and 39 deletions

View file

@ -7,7 +7,7 @@ import numpy as np
import tcod
from . import log
from .actions.action import Action
from .actions.action import ActionWithActor
from .actions.game import BumpAction, WaitAction
from .components import Component
from .geometry import Direction, Point
@ -26,7 +26,7 @@ class AI(Component):
super().__init__()
self.entity = entity
def act(self, engine: 'Engine') -> Optional[Action]:
def act(self, engine: 'Engine') -> Optional[ActionWithActor]:
'''Produce an action to perform'''
raise NotImplementedError()
@ -38,7 +38,7 @@ class HostileEnemy(AI):
beeline for her.
'''
def act(self, engine: 'Engine') -> Optional[Action]:
def act(self, engine: 'Engine') -> Optional[ActionWithActor]:
visible_tiles = tcod.map.compute_fov(
engine.map.tiles['transparent'],
pov=tuple(self.entity.position),