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
27 """ Model: Battle Class """
30 """ The number of iterations of the gameLoop since the battle began. """
33 """ The hero party. """
36 """ The villain party. """
39 """ List of static EventType objects. """
42 """ List of static monsters Fighter objects. """
45 """ Constructs a Battle object. Current Time set to 0, both
46 parties nullified and eventtype/monster static data defaults to
49 self
.__currentTime
= 0
53 self
.__eventTypes
= []
57 """ Is one of the parties dead? """
58 return not self
.__party
1.isAlive() or not self
.__party
2.isAlive()
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. """
71 # execute all available events
72 while self
.executeNextEvent():
73 # if there was at least one event
75 # generate per-iteration status transactions
76 for f
in self
.__party
1.getFighters():
77 for s
in f
.getStatus():
79 for f
in self
.__party
2.getFighters():
80 for s
in f
.getStatus():
84 self
.__currentTime
+= 1
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
99 # Try to get an event from party1
100 event
= self
.__party
1.getNextEvent(self
.__party
2,self
.__currentTime
,self
.__controller
)
102 # If there was one, execute and return true
105 self
.__view
.printEvent(event
)
108 # Try to get an event from party2
109 event
= self
.__party
2.getNextEvent(self
.__party
1,self
.__currentTime
,self
.__controller
)
111 # If there was one, execute and return true
114 self
.__view
.printEvent(event
)
117 # Otherwise, notify that there are no more events at this time.
120 def getCurrentTime(self
):
121 return self
.__currentTime
123 def setCurrentTime(self
,t
):
124 self
.__currentTime
= t
129 def setParty1(self
, p
):
135 def setParty2(self
, p
):
139 """ Sets the view object link. Used by ConsoleController. """
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
:
157 def getMonsters(self
):
158 return self
.__monsters
160 def setMonsters(self
,monsters
):
161 self
.__monsters
= monsters