removed protection elemental
[asgard.git] / battle.py
blob7305ceea82c50534f657c60b1e563c64fdc36cbe
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 *
25 class Battle:
27 def __init__(self):
28 self.__currentTime = 0
29 self.__party1 = None
30 self.__party2 = None
31 self.__eventTypes = []
33 def isOver(self):
34 """ Is battle over?"""
36 return not self.__party1.isAlive() or not self.__party2.isAlive()
38 def nextTurn(self):
39 """ Execute next iteration in gameloop."""
41 sleep(.1)
43 wereEvents = False
45 # execute all available events
46 while self.executeNextEvent():
47 # if there was at least one event
48 wereEvents = True
49 # generate per-iteration status transactions
50 for f in self.__party1.getFighters():
51 for s in f.getStatus():
52 s.genIteration()
53 for f in self.__party2.getFighters():
54 for s in f.getStatus():
55 s.genIteration()
56 continue
58 self.__currentTime += 1
60 return wereEvents
62 def executeNextEvent(self):
63 """ Execute next event in event queue. Return true if there were events. """
65 if self.isOver():
66 return False
68 # Try to get an event from party1
69 event = self.__party1.getNextEvent(self.__party2,self.__currentTime,self.__controller)
71 # If there was one, execute and return true
72 if event != None:
73 event.execute()
74 self.__view.printEvent(event)
75 return True
77 # Try to get an event from party2
78 event = self.__party2.getNextEvent(self.__party1,self.__currentTime,self.__controller)
80 # If there was one, execute and return true
81 if event != None:
82 event.execute()
83 self.__view.printEvent(event)
84 return True
86 # Otherwise, notify that there are no more events at this time.
87 return False
89 def getCurrentTime(self):
90 """ Retrieve current time."""
91 return self.__currentTime
93 def setCurrentTime(self,t):
94 """ Establish current time."""
95 self.__currentTime = t
97 def getParty1(self):
98 """ Retrieve party1."""
99 return self.__party1
101 def setParty1(self, p):
102 """ Set party1."""
103 self.__party1 = p
105 def getParty2(self):
106 """ Retrieve party2."""
107 return self.__party2
109 def setParty2(self, p):
110 """ Set party2."""
111 self.__party2 = p
113 def setView(self,v):
114 """ Establish view."""
115 self.__view = v
117 def setController(self,c):
118 """ Establish controller."""
119 self.__controller = c
121 def getEventTypeList(self):
122 """ Return list of loaded EventTypes"""
123 return self.__eventTypes
125 def setEventTypeList(self,evts):
126 """ Load a new list of EventTypes """
127 self.__eventTypes = evts
129 def getEventType(self,et_s):
130 for et in self.__eventTypes:
131 if et.getName() == et_s:
132 return et