2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2004 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program 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 this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 from GUIDefines
import *
23 from ie_stats
import *
28 HLAWindow
= 0 # << HLA selection window
29 HLAAbilities
= [] # << all learnable HLA abilities
30 HLANewAbilities
= [] # << selected HLA abilites
31 HLADoneButton
= 0 # << done button
32 HLATextArea
= 0 # << HLA ability description area
33 HLACount
= 0 # << number of HLA selections left
35 NumClasses
= 0 # << number of classes
36 Classes
= [] # << classes (ids)
37 Level
= [] # << levels for each class
38 EnhanceGUI
= 0 # << toggle for scrollbar and 25th hla slot
40 def OpenHLAWindow (actor
, numclasses
, classes
, levels
):
41 """Opens the HLA selection window."""
43 global HLAWindow
, HLADoneButton
, HLATextArea
, HLACount
, NumClasses
, pc
, Classes
, Level
47 if (GemRB
.GetVar("GUIEnhancements")):
52 NumClasses
= numclasses
55 HLACount
= GemRB
.GetVar ("HLACount")
57 # we use the same window as sorcerer spell selection
58 HLAWindow
= GemRB
.LoadWindow (8)
60 # get all our HLAs (stored in HLAAbilities)
63 # change the title to ABILITIES
64 TitleLabel
= HLAWindow
.GetControl (0x10000017)
65 TitleLabel
.SetText (63818)
67 # create the done button
68 HLADoneButton
= HLAWindow
.GetControl (28)
69 HLADoneButton
.SetState(IE_GUI_BUTTON_DISABLED
)
70 HLADoneButton
.SetEvent(IE_GUI_BUTTON_ON_PRESS
, HLADonePress
)
71 HLADoneButton
.SetText(11973)
72 HLADoneButton
.SetFlags(IE_GUI_BUTTON_DEFAULT
, OP_OR
)
75 HLATextArea
= HLAWindow
.GetControl(26)
77 print "Number of HLAs:",len (HLAAbilities
)
79 # create a scrollbar if need-be
80 if ( len (HLAAbilities
) >= 25 ) and EnhanceGUI
:
81 # setup extra 25th HLA slot:
82 HLAWindow
.CreateButton (24, 231, 345, 42, 42)
83 if ( len (HLAAbilities
) > 25):
84 # setup our scroll index
85 GemRB
.SetVar("HLATopIndex", 0)
87 HLAWindow
.CreateScrollBar (1000, 290,142, 16,252)
88 ScrollBar
= HLAWindow
.GetControl (1000)
89 ScrollBar
.SetSprites ("GUISCRCW", 0, 0,1,2,3,5,4)
90 ScrollBar
.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE
, HLAShowAbilities
)
91 #with enhanced GUI we have 5 rows of 5 abilities (the last one is 'the extra slot')
92 ScrollBar
.SetVarAssoc ("HLATopIndex", int ( ceil ( ( len (HLAAbilities
)-25 ) / 5.0 ) ) + 1 )
93 ScrollBar
.SetDefaultScrollBar ()
95 # draw our HLAs and show the window
97 HLAWindow
.ShowModal (MODAL_SHADOW_GRAY
)
102 """Saves the new HLAs and closes the HLA selection window."""
104 # save all of our HLAs
105 for i
in range (len (HLANewAbilities
)):
106 # see if we're going to learn this ability
107 if HLANewAbilities
[i
] == 0:
110 # figure out the ability type
111 HLARef
= HLAAbilities
[i
][0]
112 HLAType
= HLARef
[5:7]
114 HLAType
= IE_SPELL_TYPE_PRIEST
115 HLALevel
= int(HLARef
[7])-1
116 elif HLAType
== "WI":
117 HLAType
= IE_SPELL_TYPE_WIZARD
118 HLALevel
= int(HLARef
[7])-1
120 HLAType
= IE_SPELL_TYPE_INNATE
123 # do we need to apply or learn it?
124 if HLARef
[:2] == "AP":
125 GemRB
.ApplySpell(pc
, HLARef
[3:])
126 elif HLARef
[:2] == "GA":
127 # make sure it isn't already learned
128 SpellIndex
= GUICommon
.HasSpell (pc
, HLAType
, HLALevel
, HLARef
[3:])
129 if SpellIndex
< 0: # gotta learn it
130 GemRB
.LearnSpell (pc
, HLARef
[3:], 8)
131 else: # memorize it again
132 GemRB
.MemorizeSpell (pc
, HLAType
, HLALevel
, SpellIndex
)
134 #save the number of this HLA memorized
135 #TODO: check param2 (0 seems to work ok)
136 GemRB
.ApplyEffect(pc
, "HLA", HLAAbilities
[i
][2], 0, HLARef
[3:])
142 # so redraw skills knows we're done
143 GemRB
.SetVar ("HLACount", 0)
147 def HLAShowAbilities ():
148 """Updates the HLA selections window.
150 Called whenever an HLA is pressed."""
152 j
= ( GemRB
.GetVar("HLATopIndex") + 1 ) * 5 - 5
154 # we have a grid of 24 abilites
155 for i
in range (24+EnhanceGUI
):
156 # ensure we can learn this many abilites
157 if len (HLAAbilities
) < 25 and i
== 24: #break if we don't need extra 25th button
159 SpellButton
= HLAWindow
.GetControl (i
)
160 if i
+ j
>= len (HLAAbilities
):
161 SpellButton
.SetState (IE_GUI_BUTTON_DISABLED
)
162 SpellButton
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
165 SpellButton
.SetState(IE_GUI_BUTTON_ENABLED
)
166 SpellButton
.SetFlags(IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
168 # fill in the button with the spell data
169 HLARef
= HLAAbilities
[i
+j
][0][3:]
172 Spell
= GemRB
.GetSpell (HLARef
)
173 SpellButton
.SetTooltip(Spell
['SpellName'])
174 SpellButton
.SetSpellIcon(HLARef
, 1)
175 SpellButton
.SetVarAssoc("ButtonPressed", i
)
176 SpellButton
.SetEvent(IE_GUI_BUTTON_ON_PRESS
, HLASelectPress
)
177 SpellButton
.SetSprites("GUIBTBUT", 0,0,1,2,3)
178 SpellButton
.SetFlags(IE_GUI_BUTTON_PICTURE
, OP_OR
)
180 # don't allow the selection of an un-learnable ability
181 if HLAAbilities
[i
+j
][1] == 0:
182 SpellButton
.SetState(IE_GUI_BUTTON_LOCKED
)
184 SpellButton
.SetBorder (0, 0,0, 0,0, 200,0,0,100, 1,1)
186 SpellButton
.SetState (IE_GUI_BUTTON_ENABLED
)
187 # unset any borders on this button or an un-learnable from last level
188 # will still shade red even though it is clickable
189 SpellButton
.SetBorder (0, 0,0, 0,0, 0,0,0,0, 0,0)
191 # show which spells are selected
192 HLAShowSelectedAbilities ()
194 GemRB
.SetToken("number", str(HLACount
))
195 HLATextArea
.SetText(63817)
197 # show the points left
198 PointsLeftLabel
= HLAWindow
.GetControl (0x10000018)
199 PointsLeftLabel
.SetText (str (HLACount
))
203 def HLASelectPress ():
204 """Toggles the HLA and displays a description string."""
206 global HLACount
, HLAAbilities
, HLANewAbilities
209 j
= ( GemRB
.GetVar("HLATopIndex") + 1 ) * 5 - 5
210 i
= GemRB
.GetVar ("ButtonPressed") + j
212 # get the spell that's been pushed
213 Spell
= GemRB
.GetSpell (HLAAbilities
[i
][0][3:])
214 HLATextArea
.SetText (Spell
["SpellDesc"])
216 # make sure we can learn the spell
217 if HLAAbilities
[i
][1]:
218 if HLANewAbilities
[i
]: # already picked -- unselecting
219 # make we aren't the pre-req to another spell that is selected
220 for j
in range (len (HLAAbilities
)):
221 if (HLAAbilities
[j
][3] == HLAAbilities
[i
][0]) and (HLANewAbilities
[j
]):
222 HLAShowSelectedAbilities () # so our pre-req is still highlighted
226 HLANewAbilities
[i
] = 0
227 HLAAbilities
[i
][2] -= 1 # internal counter
228 HLADoneButton
.SetState (IE_GUI_BUTTON_DISABLED
)
230 # we don't have any picks left
235 # select the spell and change the done state if need be
237 HLANewAbilities
[i
] = 1
238 HLAAbilities
[i
][2] += 1 # increment internal counter
240 HLADoneButton
.SetState (IE_GUI_BUTTON_ENABLED
)
242 # recheck internal exclusions and prereqs
243 HLARecheckPrereqs (i
)
245 # show selected spells
247 HLAShowSelectedAbilities ()
248 HLATextArea
.SetText (Spell
["SpellDesc"])
250 # show the points left
251 PointsLeftLabel
= HLAWindow
.GetControl (0x10000018)
252 PointsLeftLabel
.SetText (str (HLACount
))
255 def HLAShowSelectedAbilities ():
256 """Marks all of the selected abilities."""
258 j
= ( GemRB
.GetVar("HLATopIndex") + 1 ) * 5 - 5
260 # mark all of the abilities picked thus far
261 for i
in range (24+EnhanceGUI
):
262 if i
+ j
>= len (HLANewAbilities
): # make sure we don't call unavailable indexes
264 if HLANewAbilities
[i
+j
]:
265 HLAMarkButton (i
+j
, 1)
267 HLAMarkButton (i
+j
, 0)
271 def HLAMarkButton (i
, select
):
272 """Enables, disables, or highlights the given button.
274 If select is true, the button is highlighted."""
276 j
= ( GemRB
.GetVar("HLATopIndex") + 1 ) * 5 - 5
279 type = IE_GUI_BUTTON_SELECTED
281 if HLAAbilities
[i
][1]:
282 type = IE_GUI_BUTTON_ENABLED
284 type = IE_GUI_BUTTON_LOCKED
286 # we have to use the index on the actual grid
287 SpellButton
= HLAWindow
.GetControl(i
-j
)
288 SpellButton
.SetState(type)
292 """Updates HLAAbilites with all the choosable class HLAs.
294 HLAAbilities[x][0] is the given HLAs spell reference.
295 HLAAbilities[x][1] is true if the HLAs prerequisites have been met."""
297 global HLAAbilities
, HLANewAbilities
, HLACount
299 # get some needed values
300 Kit
= GUICommon
.GetKitIndex (pc
)
301 IsDual
= GUICommon
.IsDualClassed (pc
, 0)
302 IsDual
= IsDual
[0] > 0
305 # reset the abilities
309 # the HLA table lookup table
310 HLAAbbrTable
= GemRB
.LoadTable ("luabbr")
312 # get all the HLAs for each class
313 for i
in range (NumClasses
):
314 ClassIndex
= CommonTables
.Classes
.FindValue (5, Classes
[i
])
315 ClassName
= CommonTables
.Classes
.GetRowName (ClassIndex
)
316 CurrentLevel
= Level
[i
]
318 if Kit
!= 0 and NumClasses
== 1 and not IsDual
: # kitted single-class
319 KitName
= CommonTables
.KitList
.GetValue (Kit
, 0)
320 HLAClassTable
= "lu" + HLAAbbrTable
.GetValue (KitName
, "ABBREV")
322 else: # everyone else
323 HLAClassTable
= "lu" + HLAAbbrTable
.GetValue (ClassName
, "ABBREV")
325 # actually load the table
326 HLAClassTable
= GemRB
.LoadTable (HLAClassTable
)
327 print "HLA Class/Kit:",ClassName
329 # save all our HLAs from this class
330 for j
in range (HLAClassTable
.GetRowCount ()):
331 HLARef
= HLAClassTable
.GetValue (j
, 0, 0)
332 print "\tHLA",j
,":",HLARef
334 # make sure we have an ability here
336 print "\t\tEnd of HLAs"
339 # [ref to hla, memorizable?, num memorized, pre-req ref, excluded ref]
343 GemRB
.CountEffects (pc
, "HLA", -1, -1, HLARef
[3:]),\
344 HLAClassTable
.GetValue (j
, 6, 0),\
345 HLAClassTable
.GetValue (j
, 7, 0)]
347 # make sure we fall within the min and max paramaters
348 if HLAClassTable
.GetValue (j
, 3) > CurrentLevel
or HLAClassTable
.GetValue (j
, 4) < CurrentLevel
:
349 print "\t\tNot within parameters"
350 HLAAbilities
.append(SaveArray
)
353 # see if we're alignment restricted (we never get them)
354 HLAAlign
= HLAClassTable
.GetValue (j
, 8, 0)
355 if HLAAlign
== "ALL_EVIL" and GemRB
.GetPlayerStat (pc
, IE_ALIGNMENT
) < 6:
356 # don't even save this one because we can never get it
357 print "\t\tNeeds ALL_EVIL"
359 elif HLAAlign
== "ALL_GOOD" and GemRB
.GetPlayerStat (pc
, IE_ALIGNMENT
) > 2:
361 print "\t\tNeeds ALL_GOOD"
364 # make sure we haven't already surpassed the number of time memorizable
365 HLANumAllowed
= HLAClassTable
.GetValue (j
, 5)
366 print "\t\tHLA count:",SaveArray
[2]
367 if SaveArray
[2] >= HLANumAllowed
:
368 print "\t\tOnly allowed to learn",HLANumAllowed
,"times"
369 HLAAbilities
.append(SaveArray
)
372 # make sure we haven't learned an HLA that excludes this one
373 HLAMemorized
= GemRB
.CountEffects (pc
, "HLA", -1, -1, SaveArray
[4][3:])
374 print "\t\tHLAExcluded count:",HLAMemorized
375 if (SaveArray
[4] != "*") and (HLAMemorized
> 0):
376 print "\t\tExcluded by:",SaveArray
[4]
377 HLAAbilities
.append(SaveArray
)
380 # we meet the prereqs so we can learn the HLA
381 HLAMemorized
= GemRB
.CountEffects (pc
, "HLA", -1, -1, SaveArray
[3][3:])
382 print "\t\tHLAPre count:",HLAMemorized
383 if (SaveArray
[3] == "*") or (HLAMemorized
> 0):
384 print "\t\tWe can learn it!"
387 HLAAbilities
.append (SaveArray
)
390 # we didn't meet prereqs :(
391 print "\t\tNeed pre-req:",SaveArray
[3]
392 HLAAbilities
.append (SaveArray
)
394 # create an array to store our abilities as they are selected
395 HLANewAbilities
= [0]*len (HLAAbilities
)
397 #make sure we don't get stuck with HLAs we can't apply
398 if MaxHLACount
< HLACount
:
399 HLACount
= MaxHLACount
400 GemRB
.SetVar ("HLACount", HLACount
)
404 def HLARecheckPrereqs (index
):
405 """Rechecks the HLA prequisites on the index on the fly."""
407 # the numer of times memorized
408 Ref
= HLAAbilities
[index
][0]
409 Memorized
= HLAAbilities
[index
][2]
411 # check for new exclusions and pre-reqs
412 for i
in range (len (HLAAbilities
)):
413 # we don't need to check the index
414 # this also fixes the assassination bug (it is excluded by itself)
417 # check for exclusions first
418 if HLAAbilities
[i
][4] == Ref
:
419 if Memorized
> 0: # can't learn it
420 HLAAbilities
[i
][1] = 0
421 else: # can, if it meets pre-reqs
422 if HLAAbilities
[i
][3] != "*": # check prereqs
423 for j
in range (len (HLAAblities
)): # search for the prereq ref
424 if (HLAAbilities
[j
][0] == HLAAbilities
[i
][3]) and (HLAAbilities
[j
][2] > 0): # can learn
425 HLAAbilities
[i
][1] = 1
428 HLAAbilities
[i
][1] = 1
431 if HLAAbilities
[i
][3] == Ref
:
432 if Memorized
> 0: # can learn if not excluded
433 if HLAAbilities
[i
][4] != "*": # check for exclusions
434 for j
in range (len (HLAAbilities
)): # search for the exclusion ref
435 if (HLAAbilities
[j
][0] == HLAAbilities
[i
][4]) and (HLAAbilities
[j
][2] <= 0): # can learn
436 HLAAbilities
[i
][1] = 1
439 HLAAbilities
[i
][1] = 1
440 else: # prereqs not met
441 HLAAbilities
[i
][1] = 0