enemy pointers are now actually enemy clones. (3 rocs = 3 entirely separate rocs)
[asgard.git] / battle.py
blob8b51061cd0f9ce32091f1ad1d5cc3272be4915d7
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 = []
32 self.__monsters = []
34 def isOver(self):
35 """ Is battle over?"""
37 return not self.__party1.isAlive() or not self.__party2.isAlive()
39 def nextTurn(self):
40 """ Execute next iteration in gameloop."""
42 sleep(.1)
44 wereEvents = False
46 # execute all available events
47 while self.executeNextEvent():
48 # if there was at least one event
49 wereEvents = True
50 # generate per-iteration status transactions
51 for f in self.__party1.getFighters():
52 for s in f.getStatus():
53 s.genIteration()
54 for f in self.__party2.getFighters():
55 for s in f.getStatus():
56 s.genIteration()
57 continue
59 self.__currentTime += 1
61 return wereEvents
63 def executeNextEvent(self):
64 """ Execute next event in event queue. Return true if there were events. """
66 if self.isOver():
67 return False
69 # Try to get an event from party1
70 event = self.__party1.getNextEvent(self.__party2,self.__currentTime,self.__controller)
72 # If there was one, execute and return true
73 if event != None:
74 event.execute()
75 self.__view.printEvent(event)
76 return True
78 # Try to get an event from party2
79 event = self.__party2.getNextEvent(self.__party1,self.__currentTime,self.__controller)
81 # If there was one, execute and return true
82 if event != None:
83 event.execute()
84 self.__view.printEvent(event)
85 return True
87 # Otherwise, notify that there are no more events at this time.
88 return False
90 def getCurrentTime(self):
91 """ Retrieve current time."""
92 return self.__currentTime
94 def setCurrentTime(self,t):
95 """ Establish current time."""
96 self.__currentTime = t
98 def getParty1(self):
99 """ Retrieve party1."""
100 return self.__party1
102 def setParty1(self, p):
103 """ Set party1."""
104 self.__party1 = p
106 def getParty2(self):
107 """ Retrieve party2."""
108 return self.__party2
110 def setParty2(self, p):
111 """ Set party2."""
112 self.__party2 = p
114 def setView(self,v):
115 """ Establish view."""
116 self.__view = v
118 def setController(self,c):
119 """ Establish controller."""
120 self.__controller = c
122 def getEventTypeList(self):
123 """ Return list of loaded EventTypes"""
124 return self.__eventTypes
126 def setEventTypeList(self,evts):
127 """ Load a new list of EventTypes """
128 self.__eventTypes = evts
130 def getEventType(self,et_s):
131 for et in self.__eventTypes:
132 if et.getName() == et_s:
133 return et
135 def getMonsters(self):
136 return self.__monsters
138 def setMonsters(self,monsters):
139 self.__monsters = monsters