Stubbed out Drawable and MenuDrawable, added commenting for epydoc.
[asgard.git] / battle.py
blob389fc6c53d0dcc4002a87fd50c9df0c1bc1ca113
1 ########################################################
2 #Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors
3 #This file is part of Asgard.
5 #Asgard is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Asgard is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Asgard; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 ########################################################
19 from os import listdir
20 from time import *
21 from fighter import *
22 from party import *
23 from event import *
24 from job import *
26 class Battle:
27 """ Model: Battle Class """
29 currentTime = 0
30 """ The number of iterations of the gameLoop since the battle began. """
32 party1 = None
33 """ The hero party. """
35 party2 = None
36 """ The villain party. """
38 eventTypes = []
39 """ List of static EventType objects. """
41 monsters = []
42 """ List of static monsters Fighter objects. """
44 def __init__(self):
45 """ Constructs a Battle object. Current Time set to 0, both
46 parties nullified and eventtype/monster static data defaults to
47 empty. """
49 self.__currentTime = 0
51 self.__party1 = None
52 self.__party2 = None
53 self.__eventTypes = []
54 self.__monsters = []
56 def isOver(self):
57 """ Is one of the parties dead? """
58 return not self.__party1.isAlive() or not self.__party2.isAlive()
60 def nextTurn(self):
61 """ Executes the next iteration of the game loop: After a pause
62 of some duration, increment the current time of the battle.
63 Then, execute all the events that are available for execution
64 this iteration. Also, calls Status.genIteration(). Returns true
65 if an event was executed. """
67 sleep(.1)
69 wereEvents = False
71 # execute all available events
72 while self.executeNextEvent():
73 # if there was at least one event
74 wereEvents = True
75 # generate per-iteration status transactions
76 for f in self.__party1.getFighters():
77 for s in f.getStatus():
78 s.genIteration()
79 for f in self.__party2.getFighters():
80 for s in f.getStatus():
81 s.genIteration()
82 continue
84 self.__currentTime += 1
86 return wereEvents
88 def executeNextEvent(self):
89 """ Query the two parties to see if there are any events that
90 can be generated this iteration of the game loop. If there are
91 events, execute the event from the party whose fighter has the
92 highest dexterity. Return whether or not the event was executed
93 or not. """
96 if self.isOver():
97 return False
99 # Try to get an event from party1
100 event = self.__party1.getNextEvent(self.__party2,self.__currentTime,self.__controller)
102 # If there was one, execute and return true
103 if event != None:
104 event.execute()
105 self.__view.printEvent(event)
106 return True
108 # Try to get an event from party2
109 event = self.__party2.getNextEvent(self.__party1,self.__currentTime,self.__controller)
111 # If there was one, execute and return true
112 if event != None:
113 event.execute()
114 self.__view.printEvent(event)
115 return True
117 # Otherwise, notify that there are no more events at this time.
118 return False
120 def getCurrentTime(self):
121 return self.__currentTime
123 def setCurrentTime(self,t):
124 self.__currentTime = t
126 def getParty1(self):
127 return self.__party1
129 def setParty1(self, p):
130 self.__party1 = p
132 def getParty2(self):
133 return self.__party2
135 def setParty2(self, p):
136 self.__party2 = p
138 def setView(self,v):
139 """ Sets the view object link. Used by ConsoleController. """
140 self.__view = v
142 def setController(self,c):
143 """ Sets the controller object link. Used by ConsoleController. """
144 self.__controller = c
146 def getEventTypeList(self):
147 return self.__eventTypes
149 def setEventTypeList(self,evts):
150 self.__eventTypes = evts
152 def getEventType(self,et_s):
153 for et in self.__eventTypes:
154 if et.getName() == et_s:
155 return et
157 def getMonsters(self):
158 return self.__monsters
160 def setMonsters(self,monsters):
161 self.__monsters = monsters