1# -*-python-*- 2# GemRB - Infinity Engine Emulator 3# Copyright (C) 2003 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 20# NewLife.py - Character generation screen 21 22################################################### 23 24import GemRB 25from GUIDefines import * 26from ie_stats import * 27import CommonTables 28 29CommonTables.Load() 30 31NewLifeWindow = 0 32TextArea = 0 33 34TotLabel = 0 35AcLabel = 0 36HpLabel = 0 37 38StatTable = 0 39# maintain this order in all lists! 40#Stats = [ Str, Int, Wis, Dex, Con, Cha ] 41Stats = [ 0, 0, 0, 0, 0, 0 ] 42StatLimit = [ 23, 18, 18, 18, 18, 18 ] 43StatLabels = [ None ] * 6 44StatLowerLimit = [ 9 ] * 6 45 46LevelUp = 0 47TotPoints = 0 48AcPoints = 0 49HpPoints = 0 50strings = ("30","60","90","99","00") 51extras = (30,60,90,99,100) 52 53def OnLoad(): 54 OpenLUStatsWindow (0) 55 return 56 57def OpenLUStatsWindow(Type = 1): 58 global NewLifeWindow, StatTable 59 global TotPoints, AcPoints, HpPoints 60 global TotLabel, AcLabel, HpLabel 61 global TextArea, Stats, StatLabels, StatLowerLimit, StatLimit, LevelUp 62 63 LevelUp = Type 64 if LevelUp: 65 # only TNO gets the main stat boosts 66 pc = GemRB.GameGetSelectedPCSingle () 67 Specific = GemRB.GetPlayerStat (pc, IE_SPECIFIC) 68 if Specific != 2: 69 return 70 else: 71 GemRB.LoadGame(None) #loading the base game 72 73 StatTable = GemRB.LoadTable("abcomm") 74 75 #setting up CG window 76 NewLifeWindow = GemRB.LoadWindow(0, "GUICG") 77 78 if LevelUp: 79 Str = GemRB.GetPlayerStat(1, IE_STR, 1) 80 Dex = GemRB.GetPlayerStat(1, IE_DEX, 1) 81 Con = GemRB.GetPlayerStat(1, IE_CON, 1) 82 Wis = GemRB.GetPlayerStat(1, IE_WIS, 1) 83 Int = GemRB.GetPlayerStat(1, IE_INT, 1) 84 Cha = GemRB.GetPlayerStat(1, IE_CHR, 1) 85 TotPoints = 1 # FIXME: actually LevelDiff 86 Stats = [ Str, Int, Wis, Dex, Con, Cha ] 87 StatLowerLimit = list(Stats) # so we copy the values or the lower limit would increase with them 88 StatLimit = [ 25 ] * 6 89 else: 90 Str = Dex = Con = Wis = Int = Cha = 9 91 TotPoints = 21 92 Stats = [ Str, Int, Wis, Dex, Con, Cha ] 93 94 # stat label controls 95 for i in range(len(Stats)): 96 StatLabels[i] = NewLifeWindow.GetControl(0x10000018 + i) 97 98 # individual stat buttons 99 for i in range(len(Stats)): 100 Button = NewLifeWindow.GetControl (i+2) 101 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET) 102 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, StatPress[i]) 103 104 Button = NewLifeWindow.GetControl(8) 105 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET) 106 Button.SetState(IE_GUI_BUTTON_LOCKED) 107 Button.SetSprites("", 0, 0, 0, 0, 0) 108 Button.SetText(5025) 109 Button.SetEvent(IE_GUI_MOUSE_ENTER_BUTTON, AcPress) 110 111 Button = NewLifeWindow.GetControl(9) 112 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET) 113 Button.SetState(IE_GUI_BUTTON_LOCKED) 114 Button.SetSprites("", 0, 0, 0, 0, 0) 115 Button.SetText(5026) 116 Button.SetEvent(IE_GUI_MOUSE_ENTER_BUTTON, HpPress) 117 118 Button = NewLifeWindow.GetControl(10) 119 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET) 120 Button.SetState(IE_GUI_BUTTON_LOCKED) 121 Button.SetSprites("", 0, 0, 0, 0, 0) 122 Button.SetText(5027) 123 Button.SetEvent(IE_GUI_MOUSE_ENTER_BUTTON, PointPress) 124 125 # stat +/- buttons 126 for i in range(len(StatPress)): 127 Button = NewLifeWindow.GetControl (11+2*i) 128 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, IncreasePress) 129 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, StatPress[i]) 130 Button.SetVarAssoc ("Pressed", i) 131 Button.SetActionInterval (200) 132 133 Button = NewLifeWindow.GetControl (12+2*i) 134 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DecreasePress) 135 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, StatPress[i]) 136 Button.SetVarAssoc ("Pressed", i) 137 Button.SetActionInterval (200) 138 139 NewLifeLabel = NewLifeWindow.GetControl(0x10000023) 140 if LevelUp: 141 NewLifeLabel.SetText(19356) 142 else: 143 NewLifeLabel.SetText(1899) 144 145 TextArea = NewLifeWindow.GetControl(23) 146 TextArea.SetText(18495) 147 148 TotLabel = NewLifeWindow.GetControl(0x10000020) 149 AcLabel = NewLifeWindow.GetControl(0x1000001E) 150 HpLabel = NewLifeWindow.GetControl(0x1000001F) 151 152 Label = NewLifeWindow.GetControl(0x10000021) 153 Label.SetText(254) 154 155 PhotoButton = NewLifeWindow.GetControl(35) 156 PhotoButton.SetState(IE_GUI_BUTTON_LOCKED) 157 PhotoButton.SetFlags(IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET) 158 PhotoButton.SetEvent(IE_GUI_MOUSE_ENTER_BUTTON, OverPhoto) 159 PhotoButton.SetPicture("STPNOC") 160 161 AcceptButton = NewLifeWindow.GetControl(0) 162 AcceptButton.SetText(4192) 163 AcceptButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, AcceptPress) 164 AcceptButton.MakeDefault() 165 166 CancelButton = NewLifeWindow.GetControl(1) 167 CancelButton.SetText(4196) 168 CancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CancelPress) 169 if LevelUp: 170 CancelButton.SetState(IE_GUI_BUTTON_DISABLED) 171 172 UpdateLabels() 173 174 NewLifeWindow.Focus() 175 return 176 177def UpdateLabels(): 178 global AcPoints, HpPoints 179 180 Str = Stats[0] 181 if Str<=18: 182 StatLabels[0].SetText(str(Str)) 183 else: 184 StatLabels[0].SetText("18/"+strings[Str-19]) 185 for i in range(1, len(Stats)): 186 StatLabels[i].SetText(str(Stats[i])) 187 188 TotLabel.SetText(str(TotPoints)) 189 if LevelUp: 190 AcPoints = GemRB.GetPlayerStat(1, IE_ARMORCLASS, 1) 191 else: 192 AcPoints = 10 193 Dex = Stats[3] 194 if Dex > 14: 195 AcPoints = AcPoints - (Dex-14) 196 197 if LevelUp: 198 HpPoints = GemRB.GetPlayerStat(1, IE_HITPOINTS, 1) 199 else: 200 HpPoints = 20 201 Con = Stats[4] 202 if Con > 14: 203 HpPoints = HpPoints + (Con-9)*2 + (Con-14) 204 else: 205 HpPoints = HpPoints + (Con-9)*2 206 207 AcLabel.SetText(str(AcPoints)) 208 HpLabel.SetText(str(HpPoints)) 209 return 210 211def AcceptPress(): 212 if TotPoints: 213 QuitWindow = GemRB.LoadWindow(1, "GUICG") 214 TextArea = QuitWindow.GetControl(0) 215 TextArea.SetText(46782) 216 217 Button = QuitWindow.GetControl(1) 218 Button.SetText("") 219 Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE,OP_SET) 220 Button.SetState(IE_GUI_BUTTON_DISABLED) 221 Button = QuitWindow.GetControl(2) 222 Button.SetText(46783) 223 Button.MakeDefault() 224 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, lambda: QuitWindow.Close()) 225 QuitWindow.ShowModal (MODAL_SHADOW_GRAY) 226 return 227 228 #set my character up 229 if not LevelUp: 230 GemRB.CreatePlayer ("charbase", 1) 231 232 Str = Stats[0] 233 if Str<=18: 234 GemRB.SetPlayerStat(1, IE_STR, Str) 235 GemRB.SetPlayerStat(1, IE_STREXTRA,0) 236 else: 237 GemRB.SetPlayerStat(1, IE_STR, 18) 238 GemRB.SetPlayerStat(1, IE_STREXTRA,extras[Str-19]) 239 240 GemRB.SetPlayerStat(1, IE_INT, Stats[1]) 241 GemRB.SetPlayerStat(1, IE_WIS, Stats[2]) 242 GemRB.SetPlayerStat(1, IE_DEX, Stats[3]) 243 GemRB.SetPlayerStat(1, IE_CON, Stats[4]) 244 GemRB.SetPlayerStat(1, IE_CHR, Stats[5]) 245 246 if LevelUp: 247 # Return to the RecordsWindow 248 NewLifeWindow.Close() 249 return 250 251 #don't add con bonus, it will be calculated by the game 252 #interestingly enough, the game adds only one level's con bonus 253 Con = Stats[4] 254 if Con > 14: 255 x = 30 256 else: 257 x = 20 + (Con-9)*2 258 259 print("Setting max hp to: ", x) 260 GemRB.SetPlayerStat(1, IE_MAXHITPOINTS, x) 261 #adding the remaining constitution bonus to the current hp 262 #if Con>14: 263 # x = x+(Con-14)*3 264 print("Setting current hp to: ", x) 265 GemRB.SetPlayerStat(1, IE_HITPOINTS, x) 266 267 GemRB.FillPlayerInfo(1) #does all the rest 268 #LETS PLAY!! 269 GemRB.EnterGame() 270 return 271 272def CancelPress(): 273 QuitWindow = GemRB.LoadWindow(1, "GUICG") 274 275 TextArea = QuitWindow.GetControl(0) 276 TextArea.SetText(19406) 277 278 def confirm(): 279 QuitWindow.Close() 280 NewLifeWindow.Close() 281 282 Button = QuitWindow.GetControl(1) 283 Button.SetText(23787) 284 Button.MakeDefault() 285 Button.SetState(IE_GUI_BUTTON_ENABLED) 286 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, confirm) 287 288 Button = QuitWindow.GetControl(2) 289 Button.SetText(23789) 290 Button.MakeDefault() 291 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, lambda: QuitWindow.Close()) 292 293 QuitWindow.ShowModal (MODAL_SHADOW_GRAY) 294 return 295 296def StrPress(): 297 TextArea.SetText(18489) 298 s = Stats[0] 299 if s>18: 300 e=extras[s-19] 301 s=18 302 else: 303 e=0 304 305 x = CommonTables.StrMod.GetValue(s,0) + CommonTables.StrModEx.GetValue(e,0) 306 y = CommonTables.StrMod.GetValue(s,1) + CommonTables.StrModEx.GetValue(e,1) 307 if x==0: 308 x=y 309 y=0 310 311 if e>60: 312 s=19 313 TextArea.Append("\n\n"+GemRB.StatComment(StatTable.GetValue(s,0),x,y) ) 314 return 315 316def IntPress(): 317 TextArea.SetText(18488) 318 TextArea.Append("\n\n"+GemRB.StatComment(StatTable.GetValue(Stats[1],1),0,0) ) 319 return 320 321def WisPress(): 322 TextArea.SetText(18490) 323 TextArea.Append("\n\n"+GemRB.StatComment(StatTable.GetValue(Stats[2],2),0,0) ) 324 return 325 326def DexPress(): 327 Table = GemRB.LoadTable("dexmod") 328 x = -Table.GetValue (Stats[3], 2) 329 TextArea.SetText(18487) 330 TextArea.Append("\n\n"+GemRB.StatComment(StatTable.GetValue(Stats[3],3),x,0) ) 331 return 332 333def ConPress(): 334 Table = GemRB.LoadTable("hpconbon") 335 x = Table.GetValue (Stats[4]-1, 1) 336 TextArea.SetText(18491) 337 TextArea.Append("\n\n"+GemRB.StatComment(StatTable.GetValue(Stats[4],4),x,0) ) 338 return 339 340def ChaPress(): 341 TextArea.SetText(1903) 342 TextArea.Append("\n\n"+GemRB.StatComment(StatTable.GetValue(Stats[5],5),0,0) ) 343 return 344 345StatPress = [ StrPress, IntPress, WisPress, DexPress, ConPress, ChaPress ] 346 347def PointPress(): 348 TextArea.SetText(18492) 349 return 350 351def AcPress(): 352 TextArea.SetText(18493) 353 return 354 355def HpPress(): 356 TextArea.SetText(18494) 357 return 358 359def DecreasePress(): 360 global TotPoints 361 global Sum, Stats 362 363 Pressed = GemRB.GetVar("Pressed") 364 Sum = Stats[Pressed] 365 if Sum <= StatLowerLimit[Pressed]: 366 return 367 TotPoints = TotPoints+1 368 Sum = Sum-1 369 Stats[Pressed] = Sum 370 StatPress[Pressed]() 371 UpdateLabels() 372 return 373 374def IncreasePress(): 375 global TotPoints 376 global Sum, Stats 377 378 if TotPoints<=0: 379 return 380 Pressed = GemRB.GetVar("Pressed") 381 Sum = Stats[Pressed] 382 if Sum >= StatLimit[Pressed]: 383 return 384 385 TotPoints = TotPoints-1 386 Sum = Sum+1 387 388 Stats[Pressed] = Sum 389 StatPress[Pressed]() 390 UpdateLabels() 391 return 392 393def OverPhoto(): 394 global TextArea 395 TextArea.SetText(18495) 396