More Cursor work.
[asgard.git] / battle.py
blob5fa8befc8e930b04c837be2761873b35a4db3a50
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 *
25 class Battle:
26 """ Model: Battle Class """
28 __currentTime = 0
29 """ The number of iterations of the gameLoop since the battle began. """
31 __party1 = None
32 """ The hero party. """
34 __party2 = None
35 """ The villain party. """
37 __eventTypes = []
38 """ List of static EventType objects. """
40 __monsters = []
41 """ List of static monsters Fighter objects. """
43 view = None
44 """ Link to the viewer object. Currently BattleScreen. """
46 cont = None
47 """ Link to the cont object. Currently Asgard. """
49 def __init__(self):
50 """ Constructs a Battle object. Current Time set to 0, both
51 parties nullified and eventtype/monster static data defaults to
52 empty. """
54 self.__currentTime = 0
56 self.__party1 = None
57 self.__party2 = None
58 self.__eventTypes = []
59 self.__monsters = []
61 def isOver(self):
62 """ Is one of the parties dead? """
63 if self.__party1 == None or self.__party2 == None:
64 return True
66 return not self.__party1.isAlive() or not self.__party2.isAlive()
68 def nextTurn(self):
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. """
75 sleep(.1)
77 wereEvents = False
79 # execute all available events
80 while self.executeNextEvent():
81 # if there was at least one event
82 wereEvents = True
83 # generate per-iteration status transactions
84 for f in self.__party1.getFighters():
85 for s in f.getStatus():
86 s.genIteration()
87 for f in self.__party2.getFighters():
88 for s in f.getStatus():
89 s.genIteration()
90 continue
92 self.__currentTime += 1
94 return wereEvents
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
101 or not. """
104 if self.isOver():
105 return False
107 # Try to get an event from party1
108 event = self.__party1.getNextEvent(self.__party2,self.__currentTime,self.cont)
110 # If there was one, execute and return true
111 if event != None:
112 event.execute()
113 #drawTransactions...
114 return True
116 # Try to get an event from party2
117 event = self.__party2.getNextEvent(self.__party1,self.__currentTime,self.cont)
119 # If there was one, execute and return true
120 if event != None:
121 event.execute()
122 #drawTransactions...
123 return True
125 # Otherwise, notify that there are no more events at this time.
126 return False
128 def getCurrentTime(self):
129 return self.__currentTime
131 def setCurrentTime(self,t):
132 self.__currentTime = t
134 def getParty1(self):
135 return self.__party1
137 def setParty1(self, p):
138 self.__party1 = p
140 def getParty2(self):
141 return self.__party2
143 def setParty2(self, p):
144 self.__party2 = 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:
156 return et
158 def getMonsters(self):
159 return self.__monsters
161 def setMonsters(self,monsters):
162 self.__monsters = monsters