fixed the rest of the functions that needed globalid capabilities
[gemrb.git] / gemrb / GUIScripts / bg2 / CharGenEnd.py
blob306f41a5be0cee6bc0f1cc6006bf9e5dae9d8d6e
1 # -*-python-*-
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.
19 # character generation end
20 import GemRB
21 import GUICommon
22 import CommonTables
23 import LUCommon
24 from GUIDefines import *
25 from ie_slots import *
26 from ie_stats import *
27 from ie_spells import *
28 from ie_restype import RES_2DA
30 def OnLoad():
31 # Lay on hands, turn undead and backstab multiplier get set by the core
32 # set my character up
33 MyChar = GemRB.GetVar ("Slot")
34 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
35 ClassIndex = CommonTables.Classes.FindValue (5, Class)
36 ClassName = CommonTables.Classes.GetRowName (ClassIndex)
37 IsMulti = GUICommon.IsMultiClassed (MyChar, 1)
38 Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
39 GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
41 # weapon proficiencies
42 # set the base number of attacks; effects will add the proficiency bonus
43 # 2 means 1 attack, because this is the number of attacks in 2 rounds
44 GemRB.SetPlayerStat (MyChar, IE_NUMBEROFATTACKS, 2)
46 #lore, thac0, hp, and saves
47 GemRB.SetPlayerStat (MyChar, IE_MAXHITPOINTS, 0)
48 GemRB.SetPlayerStat (MyChar, IE_HITPOINTS, 0)
49 LUCommon.SetupSavingThrows (MyChar)
50 LUCommon.SetupThaco (MyChar)
51 LUCommon.SetupLore (MyChar)
52 LUCommon.SetupHP (MyChar)
54 # mage spells
55 TableName = CommonTables.ClassSkills.GetValue (Class, 2, 0)
56 if TableName != "*":
57 index = 0
58 if IsMulti[0]>1:
59 #find out which class gets mage spells
60 for i in range (IsMulti[0]):
61 if CommonTables.ClassSkills.GetValue (IsMulti[i+1], 2, 0) != "*":
62 index = i
63 break
64 GUICommon.SetupSpellLevels(MyChar, TableName, IE_SPELL_TYPE_WIZARD, Levels[index])
66 # apply class/kit abilities
67 KitIndex = GUICommon.GetKitIndex (MyChar)
68 if IsMulti[0]>1:
69 #get the class abilites for each class
70 for i in range (IsMulti[0]):
71 TmpClassName = CommonTables.Classes.GetRowName (CommonTables.Classes.FindValue (5, IsMulti[i+1]) )
72 ABTable = CommonTables.ClassSkills.GetValue (TmpClassName, "ABILITIES")
73 if ABTable != "*" and GemRB.HasResource (ABTable, RES_2DA, 1):
74 GUICommon.AddClassAbilities (MyChar, ABTable, Levels[i], Levels[i])
75 else:
76 if KitIndex:
77 ABTable = CommonTables.KitList.GetValue (str(KitIndex), "ABILITIES")
78 else:
79 ABTable = CommonTables.ClassSkills.GetValue (ClassName, "ABILITIES")
80 if ABTable != "*" and GemRB.HasResource (ABTable, RES_2DA, 1):
81 GUICommon.AddClassAbilities (MyChar, ABTable, Levels[0], Levels[0])
83 # apply starting (alignment dictated) abilities
84 # pc, table, new level, level diff, alignment
85 AlignmentTable = GemRB.LoadTable ("aligns")
86 AlignmentAbbrev = AlignmentTable.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_ALIGNMENT))
87 GUICommon.AddClassAbilities (MyChar, "abstart", 6,6, AlignmentAbbrev)
89 # setup starting gold (uses a roll dictated by class
90 TmpTable = GemRB.LoadTable ("strtgold")
91 temp = GemRB.Roll (TmpTable.GetValue (Class, 1),TmpTable.GetValue (Class, 0), TmpTable.GetValue (Class, 2))
92 GemRB.SetPlayerStat (MyChar, IE_GOLD, temp * TmpTable.GetValue (Class, 3))
94 # save the appearance
95 GUICommon.SetColorStat (MyChar, IE_HAIR_COLOR, GemRB.GetVar ("HairColor") )
96 GUICommon.SetColorStat (MyChar, IE_SKIN_COLOR, GemRB.GetVar ("SkinColor") )
97 GUICommon.SetColorStat (MyChar, IE_MAJOR_COLOR, GemRB.GetVar ("MajorColor") )
98 GUICommon.SetColorStat (MyChar, IE_MINOR_COLOR, GemRB.GetVar ("MinorColor") )
99 #GUICommon.SetColorStat (MyChar, IE_METAL_COLOR, 0x1B )
100 #GUICommon.SetColorStat (MyChar, IE_LEATHER_COLOR, 0x16 )
101 #GUICommon.SetColorStat (MyChar, IE_ARMOR_COLOR, 0x17 )
102 GemRB.SetPlayerStat (MyChar, IE_EA, 2 )
104 # save the name and starting xp (can level right away in game)
105 GemRB.SetPlayerName (MyChar, GemRB.GetToken ("CHARNAME"), 0)
107 # does all the rest
108 LargePortrait = GemRB.GetToken ("LargePortrait")
109 SmallPortrait = GemRB.GetToken ("SmallPortrait")
110 GemRB.FillPlayerInfo (MyChar, LargePortrait, SmallPortrait)
112 playmode = GemRB.GetVar ("PlayMode")
113 if playmode >=0:
114 if GemRB.GetVar("GUIEnhancements"):
115 GemRB.SaveCharacter ( MyChar, "gembak" )
116 #LETS PLAY!!
117 GemRB.EnterGame()
118 GemRB.ExecuteString ("EquipMostDamagingMelee()", MyChar)
119 else:
120 #leaving multi player pregen
121 if CharGenWindow:
122 CharGenWindow.Unload ()
123 #when export is done, go to start
124 if GUICommon.HasTOB():
125 GemRB.SetToken ("NextScript","Start2")
126 else:
127 GemRB.SetToken ("NextScript","Start")
128 GemRB.SetNextScript ("ExportFile") #export
129 return
131 def GiveEquipment(MyChar, ClassName, KitIndex):
132 # get the kit (or use class if no kit) to load the start table
133 if KitIndex == 0:
134 EquipmentColName = ClassName
135 # sorcerers are missing from the table, use the mage equipment instead
136 if EquipmentColName == "SORCERER":
137 EquipmentColName = "MAGE"
138 else:
139 EquipmentColName = CommonTables.KitList.GetValue (KitIndex, 0)
141 EquipmentTable = GemRB.LoadTable ("25stweap")
143 # a map of slots in the table to the real slots
144 # SLOT_BAG is invalid, so use the inventory (first occurence)
145 # SLOT_INVENTORY: use -1 instead, that's what CreateItem expects
146 RealSlots = [ SLOT_ARMOUR, SLOT_SHIELD, SLOT_HELM, -1, SLOT_RING, \
147 SLOT_RING, SLOT_CLOAK, SLOT_BOOT, SLOT_AMULET, SLOT_GLOVE, \
148 SLOT_BELT, SLOT_QUIVER, SLOT_QUIVER, SLOT_QUIVER, \
149 SLOT_ITEM, SLOT_ITEM, SLOT_ITEM, SLOT_WEAPON, SLOT_WEAPON, SLOT_WEAPON ]
150 inventory_exclusion = 0
152 #loop over rows - item slots
153 for slot in range(0, EquipmentTable.GetRowCount ()):
154 slotname = EquipmentTable.GetRowName (slot)
155 item_resref = EquipmentTable.GetValue (slotname, EquipmentColName)
157 # no item - go to next
158 if item_resref == "*":
159 continue
161 # the table has typos for kitted bard's armor
162 if item_resref == "LEATH14":
163 item_resref = "LEAT14"
165 # get empty slots of the requested type
166 realslot = GemRB.GetSlots (MyChar, RealSlots[slot], -1)
167 if RealSlots[slot] == SLOT_WEAPON:
168 # exclude the shield slot, so the offhand stays empty
169 realslot = realslot[1:]
171 if realslot == (): # fallback to the inventory
172 realslot = GemRB.GetSlots (MyChar, -1, -1)
174 if realslot == (): # this shouldn't happen!
175 print "Eeek! No free slots for", item_resref
176 continue
178 # if an item contains a comma, the rest of the value is the stack
179 if "," in item_resref:
180 item_resref = item_resref.split(",")
181 count = int(item_resref[1])
182 item_resref = item_resref[0]
183 else:
184 count = 0
186 targetslot = realslot[0]
187 SlotType = GemRB.GetSlotType (targetslot, MyChar)
188 i = 1
189 item = GemRB.GetItem (item_resref)
191 if inventory_exclusion & item['Exclusion']:
192 # oops, too many magic items to equip, so just dump it to the inventory
193 targetslot = GemRB.GetSlots (MyChar, -1, -1)[0]
194 SlotType = -1
195 else:
196 # if there are no free slots, CreateItem will create the item on the ground
197 while not GemRB.CanUseItemType (SlotType["Type"], item_resref, MyChar) \
198 and i < len(realslot):
199 targetslot = realslot[i]
200 SlotType = GemRB.GetSlotType (targetslot, MyChar)
201 i = i + 1
203 GemRB.CreateItem(MyChar, item_resref, targetslot, count, 0, 0)
204 GemRB.ChangeItemFlag (MyChar, targetslot, IE_INV_ITEM_IDENTIFIED, OP_OR)
205 inventory_exclusion |= item['Exclusion']
207 # grant the slayer change ability to the protagonist
208 if MyChar == 1:
209 GemRB.LearnSpell (MyChar, "SPIN822", LS_MEMO)
210 return