1# -*-python-*-
2# GemRB - Infinity Engine Emulator
3# Copyright (C) 2003-2004 The GemRB Project
4#
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.
9#
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.
14#
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.
18#
19# character generation - ability; next skills/profs/spells (CharGen6)
20import GemRB
21import GUICommon
22import Spellbook
23import CommonTables
24import CharGenCommon
25import LUSkillsSelection
26import LUProfsSelection
27from GUIDefines import IE_SPELL_TYPE_PRIEST, IE_SPELL_TYPE_WIZARD, GTV_STR
28from ie_stats import *
29
30def OnLoad():
31	MyChar = GemRB.GetVar ("Slot")
32
33	# nullify our thieving skills
34	LUSkillsSelection.SkillsNullify (MyChar)
35
36	# nullify our proficiencies
37	LUProfsSelection.ProfsNullify ()
38
39	# nully other variables
40	GemRB.SetVar ("HatedRace", 0)
41
42	#remove all known spells and nullify the memorizable counts
43	Spellbook.RemoveKnownSpells (MyChar, IE_SPELL_TYPE_WIZARD, 1,9, 1)
44	Spellbook.RemoveKnownSpells (MyChar, IE_SPELL_TYPE_PRIEST, 1,7, 1)
45
46	# learn divine spells if appropriate
47	ClassName = GUICommon.GetClassRowName (MyChar)
48	TableName = CommonTables.ClassSkills.GetValue (ClassName, "CLERICSPELL", GTV_STR) # cleric spells
49
50	if TableName == "*": # only druid spells or no spells at all
51		TableName = CommonTables.ClassSkills.GetValue (ClassName, "DRUIDSPELL", GTV_STR)
52		ClassFlag = 0x8000
53	elif CommonTables.ClassSkills.GetValue (ClassName, "DRUIDSPELL", GTV_STR) != "*": # cleric and druid spells
54		ClassFlag = 0
55	else: # only cleric spells
56		ClassFlag = 0x4000
57
58	if TableName != "*":
59		#figure out which class casts spells and use the level of the class
60		#to setup the priest spells
61		Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), \
62				GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
63				GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
64		index = 0
65		IsMulti = GUICommon.IsMultiClassed (MyChar, 1)
66		if IsMulti[0]>1:
67			#loop through each multiclass until we come across the class that gives
68			#divine spells; because clerics have a lower id than rangers, they should
69			#be looked at first in Cleric/Ranger multi's, which is correct
70			foundindex = 0
71			for i in range (IsMulti[0]):
72				ClassName = GUICommon.GetClassRowName (IsMulti[i+1], "class")
73				for table in "CLERICSPELL", "DRUIDSPELL":
74					if CommonTables.ClassSkills.GetValue (ClassName, table) != "*":
75						index = i
76						foundindex = 1
77						break
78				if foundindex:
79					break
80
81		#set our memorizable counts
82		Spellbook.SetupSpellLevels (MyChar, TableName, IE_SPELL_TYPE_PRIEST, Levels[index])
83
84		#learn all our priest spells up to the level we can learn
85		for level in range (8):
86			if GemRB.GetMemorizableSpellsCount (MyChar, IE_SPELL_TYPE_PRIEST, level, 0) <= 0:
87				Spellbook.LearnPriestSpells (MyChar, level, ClassFlag)
88				break
89	CharGenCommon.DisplayOverview (6)
90	return
91