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
26 """ Model: Battle Class """
29 """ The number of iterations of the gameLoop since the battle began. """
32 """ The hero party. """
35 """ The villain party. """
38 """ List of static EventType objects. """
41 """ List of static monsters Fighter objects. """
44 """ Link to the viewer object. Currently BattleScreen. """
47 """ Link to the cont object. Currently Asgard. """
50 """ Constructs a Battle object. Current Time set to 0, both
51 parties nullified and eventtype/monster static data defaults to
54 self
.__currentTime
= 0
58 self
.__eventTypes
= []
62 """ Is one of the parties dead? """
63 if self
.__party
1 == None or self
.__party
2 == None:
66 return not self
.__party
1.isAlive() or not self
.__party
2.isAlive()
69 """ Executes the next iteration of the game loop: After a pause
70 of some duration, increment the current time of the battle.
71 Then, execute all the events that are available for execution
72 this iteration. Also, calls Status.genIteration(). Returns true
73 if an event was executed. """
79 # execute all available events
80 while self
.executeNextEvent():
81 # if there was at least one event
83 # generate per-iteration status transactions
84 for f
in self
.__party
1.getFighters():
85 for s
in f
.getStatus():
87 for f
in self
.__party
2.getFighters():
88 for s
in f
.getStatus():
92 self
.__currentTime
+= 1
96 def executeNextEvent(self
):
97 """ Query the two parties to see if there are any events that
98 can be generated this iteration of the game loop. If there are
99 events, execute the event from the party whose fighter has the
100 highest dexterity. Return whether or not the event was executed
107 # Try to get an event from party1
108 event
= self
.__party
1.getNextEvent(self
.__party
2,self
.__currentTime
,self
.cont
)
110 # If there was one, execute and return true
116 # Try to get an event from party2
117 event
= self
.__party
2.getNextEvent(self
.__party
1,self
.__currentTime
,self
.cont
)
119 # If there was one, execute and return true
125 # Otherwise, notify that there are no more events at this time.
128 def getCurrentTime(self
):
129 return self
.__currentTime
131 def setCurrentTime(self
,t
):
132 self
.__currentTime
= t
137 def setParty1(self
, p
):
143 def setParty2(self
, p
):
147 def getEventTypeList(self
):
148 return self
.__eventTypes
150 def setEventTypeList(self
,evts
):
151 self
.__eventTypes
= evts
153 def getEventType(self
,et_s
):
154 for et
in self
.__eventTypes
:
155 if et
.getName() == et_s
:
158 def getMonsters(self
):
159 return self
.__monsters
161 def setMonsters(self
,monsters
):
162 self
.__monsters
= monsters