| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include <assert.h> |
| 35 |
#include <limits.h> |
| 36 |
#include <setjmp.h> |
| 37 |
#include <stdio.h> |
| 38 |
#include <stdlib.h> |
| 39 |
#include <string.h> |
| 40 |
|
| 41 |
#include "scare.h" |
| 42 |
#include "scprotos.h" |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static const sc_char NUL = '\0'; |
| 47 |
enum |
| 48 |
{ PARSE_TEMP_LENGTH = 256, |
| 49 |
PARSE_MAX_DEPTH = 32 |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
enum { SEPARATOR_SIZE = 3 }; |
| 54 |
static const sc_byte V400_SEPARATOR[SEPARATOR_SIZE] = {0xbd, 0xd0, 0x00}; |
| 55 |
static const sc_byte V390_SEPARATOR[SEPARATOR_SIZE] = {0x2a, 0x2a, 0x00}; |
| 56 |
static const sc_byte V380_SEPARATOR[SEPARATOR_SIZE] = {0x2a, 0x2a, 0x00}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
typedef struct |
| 77 |
{ |
| 78 |
const sc_char *const class_name; |
| 79 |
const sc_char *const descriptor; |
| 80 |
} sc_parse_schema_t; |
| 81 |
|
| 82 |
|
| 83 |
static const sc_parse_schema_t V400_PARSE_SCHEMA[] = { |
| 84 |
{"_GAME_", |
| 85 |
"<HEADER>Header <GLOBAL>Globals V<ROOM>Rooms V<OBJECT>Objects V<TASK>Tasks" |
| 86 |
" V<EVENT>Events V<NPC>NPCs V<ROOM_GROUP>RoomGroups V<SYNONYM>Synonyms" |
| 87 |
" V<VARIABLE>Variables V<ALR>ALRs BCustomFont ?BCustomFont:$FontNameSize" |
| 88 |
" $CompileDate"}, |
| 89 |
{"HEADER", |
| 90 |
"MStartupText #StartRoom MWinText"}, |
| 91 |
{"GLOBAL", |
| 92 |
"$GameName $GameAuthor $DontUnderstand #Perspective BShowExits #WaitTurns" |
| 93 |
" BDispFirstRoom BBattleSystem #MaxScore $PlayerName BPromptName $PlayerDesc" |
| 94 |
" #Task ?!#Task=0:$AltDesc #Position #ParentObject #PlayerGender" |
| 95 |
" #MaxSize #MaxWt ?GBattleSystem:<BATTLE>Battle BEightPointCompass bNoDebug" |
| 96 |
" BNoScoreNotify BNoMap bNoAutoComplete bNoControlPanel bNoMouse BSound" |
| 97 |
" BGraphics <RESOURCE>IntroRes <RESOURCE>WinRes BStatusBox $StatusBoxText" |
| 98 |
" iUnk1 iUnk2 BEmbedded"}, |
| 99 |
{"BATTLE", |
| 100 |
"iStaminaLo iStaminaHi iStrengthLo iStrengthHi iAccuracyLo iAccuracyHi" |
| 101 |
" iDefenseLo iDefenseHi iAgilityLo iAgilityHi iRecovery"}, |
| 102 |
{"ROOM", |
| 103 |
"$Short $Long ?GEightPointCompass:[12]<ROOM_EXIT>Exits" |
| 104 |
" ?!GEightPointCompass:[8]<ROOM_EXIT>Exits <RESOURCE>Res V<ROOM_ALT>Alts" |
| 105 |
" ?!GNoMap:bHideOnMap"}, |
| 106 |
{"ROOM_EXIT", |
| 107 |
"{V400_ROOM_EXIT:#Dest_#Var1_#Var2_#Var3}"}, |
| 108 |
{"ROOM_ALT", |
| 109 |
"$M1 #Type <RESOURCE>Res1 $M2 #Var2 <RESOURCE>Res2 #HideObjects $Changed" |
| 110 |
" #Var3 #DisplayRoom"}, |
| 111 |
{"RESOURCE", |
| 112 |
"?GSound:$SoundFile,#SoundLen,ZSoundOffset" |
| 113 |
" ?GGraphics:$GraphicFile,#GraphicLen,ZGraphicOffset {V400_RESOURCE}"}, |
| 114 |
{"OBJECT", |
| 115 |
"$Prefix $Short V$Alias BStatic $Description #InitialPosition #Task" |
| 116 |
" BTaskNotDone $AltDesc ?BStatic:<ROOM_LIST1>Where BContainer BSurface" |
| 117 |
" #Capacity ?!BStatic:BWearable,#SizeWeight,#Parent" |
| 118 |
" ?BStatic:{OBJECT:#Parent} #Openable ?#Openable=5:#Key ?#Openable=6:#Key" |
| 119 |
" ?#Openable=7:#Key #SitLie ?!BStatic:BEdible BReadable ?BReadable:$ReadText" |
| 120 |
" ?!BStatic:BWeapon #CurrentState ?!#CurrentState=0:$States,BStateListed" |
| 121 |
" BListFlag <RESOURCE>Res1 <RESOURCE>Res2 ?GBattleSystem:<OBJ_BATTLE>Battle" |
| 122 |
" $InRoomDesc #OnlyWhenNotMoved"}, |
| 123 |
{"OBJ_BATTLE", |
| 124 |
"iProtectionValue iHitValue iMethod iAccuracy"}, |
| 125 |
{"ROOM_LIST1", |
| 126 |
"#Type {ROOM_LIST1}"}, |
| 127 |
{"TASK", |
| 128 |
"V$Command $CompleteText $ReverseMessage $RepeatText $AdditionalMessage" |
| 129 |
" #ShowRoomDesc BRepeatable BReversible V$ReverseCommand <ROOM_LIST0>Where" |
| 130 |
" $Question ?$Question:$Hint1,$Hint2 V<TASK_RESTR>Restrictions" |
| 131 |
" V<TASK_ACTION>Actions $RestrMask <RESOURCE>Res"}, |
| 132 |
{"TASK_RESTR", |
| 133 |
"#Type ?#Type=0:#Var1,#Var2,#Var3 ?#Type=1:#Var1,#Var2 ?#Type=2:#Var1,#Var2" |
| 134 |
" ?#Type=3:#Var1,#Var2,#Var3 ?#Type=4:#Var1,#Var2,#Var3,$Var4 $FailMessage"}, |
| 135 |
{"TASK_ACTION", |
| 136 |
"#Type ?#Type=0:#Var1,#Var2,#Var3 ?#Type=1:#Var1,#Var2,#Var3" |
| 137 |
" ?#Type=2:#Var1,#Var2 ?#Type=3:#Var1,#Var2,#Var3,$Expr,#Var5" |
| 138 |
" ?#Type=4:#Var1 ?#Type=5:#Var1,#Var2 ?#Type=6:#Var1,#Var2,#Var3" |
| 139 |
" ?#Type=7:iVar1,iVar2,iVar3"}, |
| 140 |
{"ROOM_LIST0", |
| 141 |
"#Type {ROOM_LIST0}"}, |
| 142 |
{"EVENT", |
| 143 |
"$Short #StarterType ?#StarterType=2:#StartTime,#EndTime" |
| 144 |
" ?#StarterType=3:#TaskNum #RestartType BTaskFinished #Time1 #Time2" |
| 145 |
" $StartText $LookText $FinishText <ROOM_LIST0>Where #PauseTask" |
| 146 |
" BPauserCompleted #PrefTime1 $PrefText1 #ResumeTask BResumerCompleted" |
| 147 |
" #PrefTime2 $PrefText2 #Obj2 #Obj2Dest #Obj3 #Obj3Dest #Obj1 #Obj1Dest" |
| 148 |
" #TaskAffected [5]<RESOURCE>Res"}, |
| 149 |
{"NPC", |
| 150 |
"$Name $Prefix V$Alias $Descr #StartRoom $AltText #Task V<TOPIC>Topics" |
| 151 |
" V<WALK>Walks BShowEnterExit ?BShowEnterExit:$EnterText,$ExitText" |
| 152 |
" $InRoomText #Gender [4]<RESOURCE>Res ?GBattleSystem:<NPC_BATTLE>Battle"}, |
| 153 |
{"NPC_BATTLE", |
| 154 |
"iAttitude iStaminaLo iStaminaHi iStrengthLo iStrengthHi iAccuracyLo" |
| 155 |
" iAccuracyHi iDefenseLo iDefenseHi iAgilityLo iAgilityHi iSpeed" |
| 156 |
" iKilledTask iRecovery iStaminaTask"}, |
| 157 |
{"TOPIC", |
| 158 |
"$Subject $Reply #Task $AltReply"}, |
| 159 |
{"WALK", |
| 160 |
"#NumStops BLoop #StartTask #CharTask #MeetObject #ObjectTask #StoppingTask" |
| 161 |
" #MeetChar $ChangedDesc {WALK:#Rooms_#Times}"}, |
| 162 |
{"ROOM_GROUP", |
| 163 |
"$Name {ROOM_GROUP:[]BList}"}, |
| 164 |
{"SYNONYM", |
| 165 |
"$Replacement $Original"}, |
| 166 |
{"VARIABLE", |
| 167 |
"$Name #Type $Value"}, |
| 168 |
{"ALR", |
| 169 |
"$Original $Replacement"}, |
| 170 |
{NULL, NULL} |
| 171 |
}; |
| 172 |
|
| 173 |
|
| 174 |
static const sc_parse_schema_t V390_PARSE_SCHEMA[] = { |
| 175 |
{"_GAME_", |
| 176 |
"<HEADER>Header <GLOBAL>Globals V<ROOM>Rooms V<OBJECT>Objects V<TASK>Tasks" |
| 177 |
" V<EVENT>Events V<NPC>NPCs V<ROOM_GROUP>RoomGroups V<SYNONYM>Synonyms" |
| 178 |
" V<VARIABLE>Variables V<ALR>ALRs BCustomFont ?BCustomFont:$FontNameSize" |
| 179 |
" $CompileDate sPassword"}, |
| 180 |
{"HEADER", |
| 181 |
"MStartupText #StartRoom MWinText"}, |
| 182 |
{"GLOBAL", |
| 183 |
"$GameName $GameAuthor $DontUnderstand #Perspective BShowExits #WaitTurns" |
| 184 |
" BDispFirstRoom BBattleSystem #MaxScore $PlayerName BPromptName $PlayerDesc" |
| 185 |
" #Task ?!#Task=0:$AltDesc #Position #ParentObject #PlayerGender" |
| 186 |
" #MaxSize #MaxWt ?GBattleSystem:<BATTLE>Battle BEightPointCompass bNoDebug" |
| 187 |
" BNoScoreNotify BNoMap bNoAutoComplete bNoControlPanel bNoMouse" |
| 188 |
" BSound BGraphics <RESOURCE>IntroRes <RESOURCE>WinRes FStatusBox" |
| 189 |
" EStatusBoxText iUnk1 iUnk2 FEmbedded"}, |
| 190 |
{"BATTLE", |
| 191 |
"iStamina iStrength iDefense"}, |
| 192 |
{"ROOM", |
| 193 |
"$Short $Long $LastDesc ?GEightPointCompass:[12]<ROOM_EXIT>Exits" |
| 194 |
" ?!GEightPointCompass:[8]<ROOM_EXIT>Exits $AddDesc1 #Task1 $AddDesc2 #Task2" |
| 195 |
" #Obj $AltDesc #TypeHideObjects <RESOURCE>Res <RESOURCE>LastRes" |
| 196 |
" <RESOURCE>Task1Res <RESOURCE>Task2Res <RESOURCE>AltRes" |
| 197 |
" ?!GNoMap:bHideOnMap |V390_ROOM:_Alts_|"}, |
| 198 |
{"ROOM_EXIT", |
| 199 |
"{V390_V380_ROOM_EXIT:#Dest_#Var1_#Var2_ZVar3}"}, |
| 200 |
{"RESOURCE", |
| 201 |
"?GSound:$SoundFile,ZSoundLen,ZSoundOffset" |
| 202 |
" ?GGraphics:$GraphicFile,ZGraphicLen,ZGraphicOffset"}, |
| 203 |
{"OBJECT", |
| 204 |
"$Prefix $Short" |
| 205 |
" [1]$Alias BStatic $Description #InitialPosition #Task BTaskNotDone" |
| 206 |
" $AltDesc ?BStatic:<ROOM_LIST1>Where BContainer BSurface #Capacity" |
| 207 |
" ?!BStatic:BWearable,#SizeWeight,#Parent ?BStatic:{OBJECT:#Parent}" |
| 208 |
" #Openable |V390_OBJECT:_Openable_,Key| #SitLie ?!BStatic:BEdible BReadable" |
| 209 |
" ?BReadable:$ReadText ?!BStatic:BWeapon ZCurrentState FListFlag" |
| 210 |
" <RESOURCE>Res1 <RESOURCE>Res2 ?GBattleSystem:<OBJ_BATTLE>Battle" |
| 211 |
" EInRoomDesc ZOnlyWhenNotMoved"}, |
| 212 |
{"OBJ_BATTLE", |
| 213 |
"iProtectionValue iHitValue iMethod"}, |
| 214 |
{"ROOM_LIST1", |
| 215 |
"#Type {ROOM_LIST1}"}, |
| 216 |
{"TASK", |
| 217 |
"W$Command $CompleteText $ReverseMessage $RepeatText $AdditionalMessage" |
| 218 |
" #ShowRoomDesc BRepeatable BReversible W$ReverseCommand <ROOM_LIST0>Where" |
| 219 |
" $Question ?$Question:$Hint1,$Hint2 V<TASK_RESTR>Restrictions" |
| 220 |
" V<TASK_ACTION>Actions |V390_TASK:$RestrMask| <RESOURCE>Res"}, |
| 221 |
{"TASK_RESTR", |
| 222 |
"#Type ?#Type=0:#Var1,#Var2,#Var3 ?#Type=1:#Var1,#Var2 ?#Type=2:#Var1,#Var2" |
| 223 |
" ?#Type=3:#Var1,#Var2,#Var3 ?#Type=4:#Var1,#Var2,#Var3,EVar4" |
| 224 |
",|V390_TASK_RESTR:Var1>0?#Var1++| $FailMessage"}, |
| 225 |
{"TASK_ACTION", |
| 226 |
"#Type |V390_TASK_ACTION:Type>4?#Type++| ?#Type=0:#Var1,#Var2,#Var3" |
| 227 |
" ?#Type=1:#Var1,#Var2,#Var3 ?#Type=2:#Var1,#Var2" |
| 228 |
" ?#Type=3:#Var1,#Var2,#Var3,|V390_TASK_ACTION:$Expr_#Var5|" |
| 229 |
" ?#Type=4:#Var1 ?#Type=6:#Var1,ZVar2,ZVar3 ?#Type=7:iVar1,iVar2,iVar3"}, |
| 230 |
{"ROOM_LIST0", |
| 231 |
"#Type {ROOM_LIST0}"}, |
| 232 |
{"EVENT", |
| 233 |
"$Short #StarterType ?#StarterType=2:#StartTime,#EndTime" |
| 234 |
" ?#StarterType=3:#TaskNum #RestartType BTaskFinished #Time1 #Time2" |
| 235 |
" $StartText $LookText $FinishText <ROOM_LIST0>Where #PauseTask" |
| 236 |
" BPauserCompleted #PrefTime1 $PrefText1 #ResumeTask BResumerCompleted" |
| 237 |
" #PrefTime2 $PrefText2 #Obj2 #Obj2Dest #Obj3 #Obj3Dest #Obj1 #Obj1Dest" |
| 238 |
" #TaskAffected [5]<RESOURCE>Res"}, |
| 239 |
{"NPC", |
| 240 |
"$Name $Prefix [1]$Alias $Descr #StartRoom $AltText #Task V<TOPIC>Topics" |
| 241 |
" V<WALK>Walks BShowEnterExit ?BShowEnterExit:$EnterText,$ExitText" |
| 242 |
" $InRoomText #Gender [4]<RESOURCE>Res ?GBattleSystem:<NPC_BATTLE>Battle"}, |
| 243 |
{"NPC_BATTLE", |
| 244 |
"iAttitude iStamina iStrength iDefense iSpeed iKilledTask"}, |
| 245 |
{"TOPIC", |
| 246 |
"$Subject $Reply #Task $AltReply"}, |
| 247 |
{"WALK", |
| 248 |
"#NumStops BLoop #StartTask #CharTask #MeetObject #ObjectTask #StoppingTask" |
| 249 |
" ZMeetChar $ChangedDesc {WALK:#Rooms_#Times}"}, |
| 250 |
{"ROOM_GROUP", |
| 251 |
"$Name {ROOM_GROUP:[]BList}"}, |
| 252 |
{"SYNONYM", |
| 253 |
"$Replacement $Original"}, |
| 254 |
{"VARIABLE", |
| 255 |
"$Name ZType $Value"}, |
| 256 |
{"ALR", |
| 257 |
"$Original $Replacement"}, |
| 258 |
{NULL, NULL} |
| 259 |
}; |
| 260 |
|
| 261 |
|
| 262 |
static const sc_parse_schema_t V380_PARSE_SCHEMA[] = { |
| 263 |
{"_GAME_", |
| 264 |
"<HEADER>Header <GLOBAL>Globals V<ROOM>Rooms V<OBJECT>Objects V<TASK>Tasks" |
| 265 |
" V<EVENT>Events V<NPC>NPCs V<ROOM_GROUP>RoomGroups V<SYNONYM>Synonyms" |
| 266 |
" FCustomFont $CompileDate sPassword |V380_GLOBAL:_MaxScore_|" |
| 267 |
" |V380_OBJECT:_InitialPositions_|"}, |
| 268 |
{"HEADER", |
| 269 |
"MStartupText #StartRoom MWinText"}, |
| 270 |
{"GLOBAL", |
| 271 |
"$GameName $GameAuthor #MaxCarried |V380_MaxSize_MaxWt_| $DontUnderstand" |
| 272 |
" #Perspective BShowExits #WaitTurns FDispFirstRoom FBattleSystem" |
| 273 |
" EPlayerName FPromptName EPlayerDesc ZTask ZPosition ZParentObject" |
| 274 |
" ZPlayerGender FEightPointCompass TNoScoreNotify FSound FGraphics" |
| 275 |
" FStatusBox EStatusBoxText FEmbedded"}, |
| 276 |
{"ROOM", |
| 277 |
"$Short $Long $LastDesc [8]<ROOM_EXIT>Exits $AddDesc1 #Task1 $AddDesc2" |
| 278 |
" #Task2 #Obj $AltDesc #TypeHideObjects |V380_ROOM:_Alts_|"}, |
| 279 |
{"ROOM_EXIT", |
| 280 |
"{V390_V380_ROOM_EXIT:#Dest_#Var1_#Var2_ZVar3}"}, |
| 281 |
{"OBJECT", |
| 282 |
"$Prefix $Short [1]$Alias BStatic $Description #InitialPosition #Task" |
| 283 |
" BTaskNotDone $AltDesc ?BStatic:<ROOM_LIST1>Where #SurfaceContainer" |
| 284 |
" FSurface ?#SurfaceContainer=2:TSurface FContainer" |
| 285 |
" ?#SurfaceContainer=1:TContainer #Capacity |V380_OBJECT:#Capacity*10+2|" |
| 286 |
" ?!BStatic:BWearable,#SizeWeight,#Parent ?BStatic:{OBJECT:#Parent}" |
| 287 |
" #Openable |V380_OBJECT:_Openable_,Key| #SitLie ?!BStatic:BEdible BReadable" |
| 288 |
" ?BReadable:$ReadText ?!BStatic:BWeapon ZCurrentState FListFlag" |
| 289 |
" EInRoomDesc ZOnlyWhenNotMoved"}, |
| 290 |
{"ROOM_LIST1", |
| 291 |
"#Type {ROOM_LIST1}"}, |
| 292 |
{"TASK", |
| 293 |
"W$Command $CompleteText $ReverseMessage $RepeatText $AdditionalMessage" |
| 294 |
" #ShowRoomDesc BRepeatable #Score BSingleScore [6]<TASK_MOVE>Movements" |
| 295 |
" BReversible W$ReverseCommand #WearObj1 #WearObj2 #HoldObj1 #HoldObj2" |
| 296 |
" #HoldObj3 #Obj1 #Task BTaskNotDone $TaskMsg $HoldMsg $WearMsg $CompanyMsg" |
| 297 |
" BNotInSameRoom #NPC $Obj1Msg #Obj1Room <ROOM_LIST0>Where BKillsPlayer" |
| 298 |
" BHoldingSameRoom $Question ?$Question:$Hint1,$Hint2 #Obj2" |
| 299 |
" ?!#Obj2=0:#Obj2Var1,#Obj2Var2,$Obj2Msg BWinGame |V380_TASK:_Actions_|" |
| 300 |
" |V380_TASK:_Restrictions_|"}, |
| 301 |
{"TASK_MOVE", |
| 302 |
"#Var1 #Var2 #Var3"}, |
| 303 |
{"ROOM_LIST0", |
| 304 |
"#Type {ROOM_LIST0}"}, |
| 305 |
{"EVENT", |
| 306 |
"$Short #StarterType ?#StarterType=2:#StartTime,#EndTime" |
| 307 |
" ?#StarterType=3:#TaskNum #RestartType BTaskFinished #Time1 #Time2" |
| 308 |
" $StartText $LookText $FinishText <ROOM_LIST0>Where #PauseTask" |
| 309 |
" BPauserCompleted #PrefTime1 $PrefText1 #ResumeTask BResumerCompleted" |
| 310 |
" #PrefTime2 $PrefText2 #Obj2 #Obj2Dest #Obj3 #Obj3Dest #Obj1 #Obj1Dest" |
| 311 |
" #TaskAffected"}, |
| 312 |
{"NPC", |
| 313 |
"$Name $Prefix [1]$Alias $Descr #StartRoom $AltText #Task V<TOPIC>Topics" |
| 314 |
" V<WALK>Walks BShowEnterExit ?BShowEnterExit:$EnterText,$ExitText" |
| 315 |
" $InRoomText ZGender"}, |
| 316 |
{"TOPIC", |
| 317 |
"$Subject $Reply #Task $AltReply"}, |
| 318 |
{"WALK", |
| 319 |
"#NumStops BLoop #StartTask #CharTask #MeetObject" |
| 320 |
" ?!#MeetObject=0:|V380_WALK:_MeetObject_| #ObjectTask ZMeetChar" |
| 321 |
" {WALK:#Rooms_#Times} ZStoppingTask EChangedDesc"}, |
| 322 |
{"ROOM_GROUP", |
| 323 |
"$Name {ROOM_GROUP:[]BList}"}, |
| 324 |
{"SYNONYM", |
| 325 |
"$Replacement $Original"}, |
| 326 |
{NULL, NULL} |
| 327 |
}; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
static const sc_parse_schema_t * |
| 336 |
parse_select_schema (sc_tafref_t taf) |
| 337 |
{ |
| 338 |
|
| 339 |
switch (taf_get_version (taf)) |
| 340 |
{ |
| 341 |
case TAF_VERSION_400: |
| 342 |
return V400_PARSE_SCHEMA; |
| 343 |
case TAF_VERSION_390: |
| 344 |
return V390_PARSE_SCHEMA; |
| 345 |
case TAF_VERSION_380: |
| 346 |
return V380_PARSE_SCHEMA; |
| 347 |
default: |
| 348 |
sc_fatal ("parse_select_schema: invalid TAF file version\n"); |
| 349 |
return NULL; |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
static sc_tafref_t parse_taf = NULL; |
| 356 |
static sc_int parse_tafline = 0; |
| 357 |
|
| 358 |
|
| 359 |
static sc_parse_schema_t const *parse_schema = NULL; |
| 360 |
|
| 361 |
|
| 362 |
static sc_prop_setref_t parse_bundle = NULL; |
| 363 |
static sc_bool parse_trace = FALSE; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
static sc_vartype_t parse_vt_key[PARSE_MAX_DEPTH]; |
| 370 |
static sc_char parse_format[PARSE_MAX_DEPTH]; |
| 371 |
static sc_int parse_depth = 0; |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
static void |
| 382 |
parse_push_key (sc_vartype_t vt_key, sc_char type) |
| 383 |
{ |
| 384 |
if (parse_depth == PARSE_MAX_DEPTH) |
| 385 |
sc_fatal ("parse_push_key: stack overrun\n"); |
| 386 |
|
| 387 |
|
| 388 |
parse_vt_key[parse_depth] = vt_key; |
| 389 |
parse_format[parse_depth] = type; |
| 390 |
parse_depth++; |
| 391 |
} |
| 392 |
|
| 393 |
static void |
| 394 |
parse_pop_key (void) |
| 395 |
{ |
| 396 |
|
| 397 |
if (parse_depth == 0) |
| 398 |
sc_fatal ("parse_pop_key: stack underrun\n"); |
| 399 |
parse_depth--; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
static void |
| 411 |
parse_retrieve_stack (sc_char format[], sc_vartype_t vt_key[], sc_int *depth) |
| 412 |
{ |
| 413 |
sc_int index_; |
| 414 |
|
| 415 |
|
| 416 |
for (index_ = 0; index_ < parse_depth; index_++) |
| 417 |
{ |
| 418 |
if (index_ < parse_depth - 1 |
| 419 |
&& parse_format[index_] == PROP_KEY_INTEGER |
| 420 |
&& parse_format[index_ + 1] == PROP_KEY_STRING) |
| 421 |
{ |
| 422 |
|
| 423 |
format[index_] = parse_format[index_ + 1]; |
| 424 |
format[index_ + 1] = parse_format[index_]; |
| 425 |
vt_key[index_] = parse_vt_key[index_ + 1]; |
| 426 |
vt_key[index_ + 1] = parse_vt_key[index_]; |
| 427 |
|
| 428 |
index_++; |
| 429 |
} |
| 430 |
else |
| 431 |
{ |
| 432 |
|
| 433 |
format[index_] = parse_format[index_]; |
| 434 |
vt_key[index_] = parse_vt_key[index_]; |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
*depth = parse_depth; |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
static void |
| 450 |
parse_stack_backtrace (void) |
| 451 |
{ |
| 452 |
sc_vartype_t vt_key[PARSE_MAX_DEPTH]; |
| 453 |
sc_char format[PARSE_MAX_DEPTH]; |
| 454 |
sc_int depth, index_; |
| 455 |
|
| 456 |
parse_retrieve_stack (format, vt_key, &depth); |
| 457 |
|
| 458 |
sc_error ("parse_stack_backtrace: version %s schema parsed to depth %ld\n", |
| 459 |
(parse_schema == V400_PARSE_SCHEMA) ? "4.00" : |
| 460 |
(parse_schema == V390_PARSE_SCHEMA) ? "3.90" : |
| 461 |
(parse_schema == V380_PARSE_SCHEMA) ? "3.80" : "[Invalid]", |
| 462 |
depth); |
| 463 |
|
| 464 |
sc_error ("parse_stack_backtrace: parse stack backtrace follows...\n"); |
| 465 |
for (index_ = 0; index_ < depth; index_++) |
| 466 |
{ |
| 467 |
sc_char type; |
| 468 |
|
| 469 |
type = format[index_]; |
| 470 |
if (type == PROP_KEY_INTEGER) |
| 471 |
sc_error ("%2ld - [%c] %ld\n", index_, type, vt_key[index_].integer); |
| 472 |
else if (type == PROP_KEY_STRING) |
| 473 |
sc_error ("%2ld - [%c] \"%s\"\n", index_, type, vt_key[index_].string); |
| 474 |
else |
| 475 |
sc_error ("%2ld - [%c] %p\n", index_, type, vt_key[index_].voidp); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
static void |
| 487 |
parse_put_property (sc_vartype_t vt_value, sc_char type) |
| 488 |
{ |
| 489 |
sc_vartype_t vt_key[PARSE_MAX_DEPTH]; |
| 490 |
sc_char format[PARSE_MAX_DEPTH + 4]; |
| 491 |
sc_int depth; |
| 492 |
|
| 493 |
|
| 494 |
parse_retrieve_stack (format + 3, vt_key, &depth); |
| 495 |
|
| 496 |
|
| 497 |
format[0] = type; |
| 498 |
format[1] = '-'; |
| 499 |
format[2] = '>'; |
| 500 |
format[depth + 3] = NUL; |
| 501 |
|
| 502 |
|
| 503 |
assert (parse_bundle); |
| 504 |
prop_put (parse_bundle, format, vt_value, vt_key); |
| 505 |
} |
| 506 |
|
| 507 |
static sc_bool |
| 508 |
parse_get_property (sc_vartype_t *vt_rvalue, sc_char type) |
| 509 |
{ |
| 510 |
sc_vartype_t vt_key[PARSE_MAX_DEPTH]; |
| 511 |
sc_char format[PARSE_MAX_DEPTH + 4]; |
| 512 |
sc_int depth; |
| 513 |
sc_bool status; |
| 514 |
|
| 515 |
|
| 516 |
parse_retrieve_stack (format + 3, vt_key, &depth); |
| 517 |
|
| 518 |
|
| 519 |
format[0] = type; |
| 520 |
format[1] = '<'; |
| 521 |
format[2] = '-'; |
| 522 |
format[depth + 3] = NUL; |
| 523 |
|
| 524 |
|
| 525 |
assert (parse_bundle); |
| 526 |
status = prop_get (parse_bundle, format, vt_rvalue, vt_key); |
| 527 |
|
| 528 |
return status; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
static sc_int |
| 540 |
parse_get_child_count (void) |
| 541 |
{ |
| 542 |
sc_vartype_t vt_rvalue; |
| 543 |
|
| 544 |
if (!parse_get_property (&vt_rvalue, PROP_INTEGER)) |
| 545 |
vt_rvalue.integer = 0; |
| 546 |
|
| 547 |
return vt_rvalue.integer; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
static sc_int |
| 560 |
parse_get_integer_property (void) |
| 561 |
{ |
| 562 |
sc_vartype_t vt_rvalue; |
| 563 |
|
| 564 |
if (!parse_get_property (&vt_rvalue, PROP_INTEGER)) |
| 565 |
sc_fatal ("parse_get_integer_property: missing property\n"); |
| 566 |
|
| 567 |
return vt_rvalue.integer; |
| 568 |
} |
| 569 |
|
| 570 |
static sc_bool |
| 571 |
parse_get_boolean_property (void) |
| 572 |
{ |
| 573 |
sc_vartype_t vt_rvalue; |
| 574 |
|
| 575 |
if (!parse_get_property (&vt_rvalue, PROP_BOOLEAN)) |
| 576 |
sc_fatal ("parse_get_boolean_property: missing property\n"); |
| 577 |
|
| 578 |
return vt_rvalue.boolean; |
| 579 |
} |
| 580 |
|
| 581 |
static const sc_char * |
| 582 |
parse_get_string_property (void) |
| 583 |
{ |
| 584 |
sc_vartype_t vt_rvalue; |
| 585 |
|
| 586 |
if (!parse_get_property (&vt_rvalue, PROP_STRING)) |
| 587 |
sc_fatal ("parse_get_string_property: missing property\n"); |
| 588 |
|
| 589 |
return vt_rvalue.string; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
static jmp_buf parse_taf_error; |
| 595 |
|
| 596 |
|
| 597 |
static const sc_char *parse_pushback_line = NULL; |
| 598 |
static sc_bool parse_use_pushback = FALSE; |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
static const sc_char * |
| 611 |
parse_get_taf_string (void) |
| 612 |
{ |
| 613 |
const sc_char *line; |
| 614 |
|
| 615 |
|
| 616 |
if (parse_use_pushback) |
| 617 |
{ |
| 618 |
|
| 619 |
assert (parse_pushback_line); |
| 620 |
line = parse_pushback_line; |
| 621 |
parse_use_pushback = FALSE; |
| 622 |
} |
| 623 |
else |
| 624 |
{ |
| 625 |
|
| 626 |
line = taf_next_line (parse_taf); |
| 627 |
if (!line) |
| 628 |
{ |
| 629 |
sc_error ("parse_get_taf_string:" |
| 630 |
" out of TAF data at line %ld\n", parse_tafline); |
| 631 |
parse_stack_backtrace (); |
| 632 |
longjmp (parse_taf_error, 1); |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
parse_pushback_line = line; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
if (parse_trace) |
| 641 |
sc_trace ("Parse: read in line %ld : %s\n", parse_tafline, line); |
| 642 |
|
| 643 |
parse_tafline++; |
| 644 |
return line; |
| 645 |
} |
| 646 |
|
| 647 |
static sc_int |
| 648 |
parse_get_taf_integer (void) |
| 649 |
{ |
| 650 |
const sc_char *line; |
| 651 |
sc_int integer; |
| 652 |
|
| 653 |
|
| 654 |
line = parse_get_taf_string (); |
| 655 |
if (sscanf (line, "%ld", &integer) != 1) |
| 656 |
{ |
| 657 |
sc_error ("parse_get_taf_integer:" |
| 658 |
" invalid integer at line %ld\n", parse_tafline - 1); |
| 659 |
parse_stack_backtrace (); |
| 660 |
longjmp (parse_taf_error, 1); |
| 661 |
} |
| 662 |
|
| 663 |
return integer; |
| 664 |
} |
| 665 |
|
| 666 |
static sc_bool |
| 667 |
parse_get_taf_boolean (void) |
| 668 |
{ |
| 669 |
const sc_char *line; |
| 670 |
sc_uint boolean; |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
line = parse_get_taf_string (); |
| 677 |
if (sscanf (line, "%lu", &boolean) != 1) |
| 678 |
{ |
| 679 |
sc_error ("parse_get_taf_boolean:" |
| 680 |
" invalid boolean at line %ld\n", parse_tafline - 1); |
| 681 |
parse_stack_backtrace (); |
| 682 |
longjmp (parse_taf_error, 1); |
| 683 |
} |
| 684 |
if (boolean != 0 && boolean != 1) |
| 685 |
{ |
| 686 |
sc_error ("parse_get_taf_boolean:" |
| 687 |
" warning: suspect boolean at line %ld\n", parse_tafline - 1); |
| 688 |
} |
| 689 |
|
| 690 |
return boolean != 0; |
| 691 |
} |
| 692 |
|
| 693 |
static void |
| 694 |
parse_taf_pushback (void) |
| 695 |
{ |
| 696 |
if (parse_use_pushback || !parse_pushback_line) |
| 697 |
sc_fatal ("parse_taf_pushback: too much pushback requested\n"); |
| 698 |
|
| 699 |
|
| 700 |
parse_use_pushback = TRUE; |
| 701 |
parse_tafline--; |
| 702 |
|
| 703 |
|
| 704 |
if (parse_trace) |
| 705 |
sc_trace ("Parse: push back at line %ld\n", parse_tafline); |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
enum |
| 711 |
{ PARSE_INTEGER = '#', |
| 712 |
PARSE_DEFAULT_ZERO = 'Z', |
| 713 |
PARSE_BOOLEAN = 'B', |
| 714 |
PARSE_DEFAULT_FALSE = 'F', |
| 715 |
PARSE_DEFAULT_TRUE = 'T', |
| 716 |
PARSE_STRING = '$', |
| 717 |
PARSE_DEFAULT_EMPTY = 'E', |
| 718 |
PARSE_MULTILINE = 'M', |
| 719 |
PARSE_VECTOR = 'V', |
| 720 |
PARSE_VECTOR_ALTERNATE = 'W', |
| 721 |
PARSE_ARRAY = '[', |
| 722 |
PARSE_EXPRESSION = '?', |
| 723 |
PARSE_EXPRESSION_NOT = '!', |
| 724 |
PARSE_GLOBAL_EXPRESSION = 'G', |
| 725 |
PARSE_CLASS = '<', |
| 726 |
PARSE_FIXUP = '|', |
| 727 |
PARSE_SPECIAL = '{', |
| 728 |
PARSE_IGNORE_INTEGER = 'i', |
| 729 |
PARSE_IGNORE_BOOLEAN = 'b', |
| 730 |
PARSE_IGNORE_STRING = 's' |
| 731 |
}; |
| 732 |
|
| 733 |
|
| 734 |
static void parse_element (const sc_char *element); |
| 735 |
static void parse_class (const sc_char *class_); |
| 736 |
static void parse_descriptor (const sc_char *descriptor); |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
static void |
| 744 |
parse_array (const sc_char *array) |
| 745 |
{ |
| 746 |
sc_int count, index_; |
| 747 |
sc_char element[PARSE_TEMP_LENGTH]; |
| 748 |
|
| 749 |
if (parse_trace) |
| 750 |
sc_trace ("Parse: entering array %s\n", array); |
| 751 |
|
| 752 |
|
| 753 |
if (sscanf (array, "[%ld]%[^ ]", &count, element) != 2) |
| 754 |
sc_fatal ("parse_array: bad array, %s\n", array); |
| 755 |
|
| 756 |
|
| 757 |
for (index_ = 0; index_ < count; index_++) |
| 758 |
{ |
| 759 |
sc_vartype_t vt_key; |
| 760 |
|
| 761 |
vt_key.integer = index_; |
| 762 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 763 |
|
| 764 |
parse_element (element); |
| 765 |
|
| 766 |
parse_pop_key (); |
| 767 |
} |
| 768 |
|
| 769 |
if (parse_trace) |
| 770 |
sc_trace ("Parse: leaving array %s\n", array); |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
static void |
| 782 |
parse_vector_common (const sc_char *vector, sc_int count) |
| 783 |
{ |
| 784 |
sc_int index_; |
| 785 |
|
| 786 |
|
| 787 |
for (index_ = 0; index_ < count; index_++) |
| 788 |
{ |
| 789 |
sc_vartype_t vt_key; |
| 790 |
|
| 791 |
vt_key.integer = index_; |
| 792 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 793 |
|
| 794 |
parse_element (vector + 1); |
| 795 |
|
| 796 |
parse_pop_key (); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
static void |
| 801 |
parse_vector (const sc_char *vector) |
| 802 |
{ |
| 803 |
sc_int count; |
| 804 |
|
| 805 |
if (parse_trace) |
| 806 |
sc_trace ("Parse: entering vector %s\n", vector); |
| 807 |
|
| 808 |
|
| 809 |
count = parse_get_taf_integer (); |
| 810 |
parse_vector_common (vector, count); |
| 811 |
|
| 812 |
if (parse_trace) |
| 813 |
sc_trace ("Parse: leaving vector %s\n", vector); |
| 814 |
} |
| 815 |
|
| 816 |
static void |
| 817 |
parse_vector_alternate (const sc_char *vector) |
| 818 |
{ |
| 819 |
sc_int count; |
| 820 |
|
| 821 |
if (parse_trace) |
| 822 |
sc_trace ("Parse: entering alternate vector %s\n", vector); |
| 823 |
|
| 824 |
|
| 825 |
count = parse_get_taf_integer () + 1; |
| 826 |
parse_vector_common (vector, count); |
| 827 |
|
| 828 |
if (parse_trace) |
| 829 |
sc_trace ("Parse: leaving alternate vector %s\n", vector); |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
static sc_bool |
| 840 |
parse_test_expression (const sc_char *test_expression) |
| 841 |
{ |
| 842 |
sc_vartype_t vt_key; |
| 843 |
sc_char plhs[PARSE_TEMP_LENGTH]; |
| 844 |
sc_int rhs; |
| 845 |
sc_bool retval = FALSE; |
| 846 |
|
| 847 |
|
| 848 |
switch (test_expression[0]) |
| 849 |
{ |
| 850 |
case PARSE_BOOLEAN: |
| 851 |
|
| 852 |
vt_key.string = test_expression + 1; |
| 853 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 854 |
retval = parse_get_boolean_property (); |
| 855 |
parse_pop_key (); |
| 856 |
break; |
| 857 |
|
| 858 |
case PARSE_INTEGER: |
| 859 |
|
| 860 |
if (sscanf (test_expression, "#%[^=]=%ld", plhs, &rhs) != 2) |
| 861 |
{ |
| 862 |
sc_fatal ("parse_test_expression: bad = compare, %s\n", |
| 863 |
test_expression + 1); |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
vt_key.string = plhs; |
| 868 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 869 |
retval = (parse_get_integer_property () == rhs); |
| 870 |
parse_pop_key (); |
| 871 |
break; |
| 872 |
|
| 873 |
case PARSE_STRING: |
| 874 |
|
| 875 |
vt_key.string = test_expression + 1; |
| 876 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 877 |
retval = !sc_strempty (parse_get_string_property ()); |
| 878 |
parse_pop_key (); |
| 879 |
break; |
| 880 |
|
| 881 |
case PARSE_GLOBAL_EXPRESSION: |
| 882 |
{ |
| 883 |
sc_vartype_t vt_gkey[2]; |
| 884 |
|
| 885 |
|
| 886 |
vt_gkey[0].string = "Globals"; |
| 887 |
vt_gkey[1].string = test_expression + 1; |
| 888 |
retval = prop_get_boolean (parse_bundle, "B<-ss", vt_gkey); |
| 889 |
break; |
| 890 |
} |
| 891 |
|
| 892 |
default: |
| 893 |
sc_fatal ("parse_test_expression:" |
| 894 |
" bad expression, %s\n", test_expression + 1); |
| 895 |
} |
| 896 |
|
| 897 |
if (parse_trace) |
| 898 |
sc_trace ("Parse: expression is %s\n", retval ? "true" : "false"); |
| 899 |
|
| 900 |
return retval; |
| 901 |
} |
| 902 |
|
| 903 |
static void |
| 904 |
parse_expression (const sc_char *expression) |
| 905 |
{ |
| 906 |
sc_char test_expression[PARSE_TEMP_LENGTH]; |
| 907 |
sc_bool is_present; |
| 908 |
|
| 909 |
if (parse_trace) |
| 910 |
sc_trace ("Parse: entering expression %s\n", expression); |
| 911 |
|
| 912 |
|
| 913 |
if (sscanf (expression, "?%[^:]", test_expression) != 1) |
| 914 |
sc_fatal ("parse_expression: bad expression, %s\n", expression); |
| 915 |
|
| 916 |
|
| 917 |
is_present = (test_expression[0] == PARSE_EXPRESSION_NOT) |
| 918 |
? !parse_test_expression (test_expression + 1) |
| 919 |
: parse_test_expression (test_expression); |
| 920 |
if (is_present) |
| 921 |
{ |
| 922 |
sc_int next; |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
for (next = strlen (test_expression) + 2; expression[next] != NUL; ) |
| 928 |
{ |
| 929 |
sc_char element[PARSE_TEMP_LENGTH]; |
| 930 |
|
| 931 |
|
| 932 |
if (sscanf (expression + next, "%[^,]", element) != 1) |
| 933 |
sc_fatal ("parse_expression: bad list, %s\n", expression + next); |
| 934 |
|
| 935 |
|
| 936 |
parse_element (element); |
| 937 |
|
| 938 |
|
| 939 |
next += strlen (element); |
| 940 |
next += strspn (expression + next, ","); |
| 941 |
} |
| 942 |
} |
| 943 |
|
| 944 |
if (parse_trace) |
| 945 |
sc_trace ("Parse: leaving expression %s\n", expression); |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
static sc_char * |
| 956 |
parse_read_multiline (void) |
| 957 |
{ |
| 958 |
const sc_byte *separator = NULL; |
| 959 |
const sc_char *line; |
| 960 |
sc_char *multiline; |
| 961 |
|
| 962 |
|
| 963 |
switch (taf_get_version (parse_taf)) |
| 964 |
{ |
| 965 |
case TAF_VERSION_400: |
| 966 |
separator = V400_SEPARATOR; |
| 967 |
break; |
| 968 |
case TAF_VERSION_390: |
| 969 |
separator = V390_SEPARATOR; |
| 970 |
break; |
| 971 |
case TAF_VERSION_380: |
| 972 |
separator = V380_SEPARATOR; |
| 973 |
break; |
| 974 |
default: |
| 975 |
sc_fatal ("parse_read_multiline: invalid TAF file version\n"); |
| 976 |
break; |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
line = parse_get_taf_string (); |
| 981 |
multiline = sc_malloc (strlen (line) + 1); |
| 982 |
strcpy (multiline, line); |
| 983 |
|
| 984 |
|
| 985 |
line = parse_get_taf_string (); |
| 986 |
while (memcmp (line, separator, SEPARATOR_SIZE) != 0) |
| 987 |
{ |
| 988 |
multiline = sc_realloc (multiline, |
| 989 |
strlen (multiline) + strlen (line) + 2); |
| 990 |
strcat (multiline, "\n"); |
| 991 |
strcat (multiline, line); |
| 992 |
line = parse_get_taf_string (); |
| 993 |
} |
| 994 |
|
| 995 |
return multiline; |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
static void |
| 1005 |
parse_terminal (const sc_char *terminal) |
| 1006 |
{ |
| 1007 |
sc_vartype_t vt_key, vt_value; |
| 1008 |
|
| 1009 |
if (parse_trace) |
| 1010 |
sc_trace ("Parse: entering terminal %s\n", terminal); |
| 1011 |
|
| 1012 |
|
| 1013 |
vt_key.string = terminal + 1; |
| 1014 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1015 |
|
| 1016 |
|
| 1017 |
switch (terminal[0]) |
| 1018 |
{ |
| 1019 |
case PARSE_INTEGER: |
| 1020 |
vt_value.integer = parse_get_taf_integer (); |
| 1021 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1022 |
break; |
| 1023 |
case PARSE_DEFAULT_ZERO: |
| 1024 |
vt_value.integer = 0; |
| 1025 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1026 |
break; |
| 1027 |
|
| 1028 |
case PARSE_BOOLEAN: |
| 1029 |
vt_value.boolean = parse_get_taf_boolean (); |
| 1030 |
parse_put_property (vt_value, PROP_BOOLEAN); |
| 1031 |
break; |
| 1032 |
case PARSE_DEFAULT_FALSE: |
| 1033 |
case PARSE_DEFAULT_TRUE: |
| 1034 |
vt_value.boolean = (terminal[0] == PARSE_DEFAULT_TRUE); |
| 1035 |
parse_put_property (vt_value, PROP_BOOLEAN); |
| 1036 |
break; |
| 1037 |
|
| 1038 |
case PARSE_STRING: |
| 1039 |
vt_value.string = parse_get_taf_string (); |
| 1040 |
parse_put_property (vt_value, PROP_STRING); |
| 1041 |
break; |
| 1042 |
case PARSE_DEFAULT_EMPTY: |
| 1043 |
vt_value.string = ""; |
| 1044 |
parse_put_property (vt_value, PROP_STRING); |
| 1045 |
break; |
| 1046 |
|
| 1047 |
case PARSE_MULTILINE: |
| 1048 |
|
| 1049 |
vt_value.mutable_string = parse_read_multiline (); |
| 1050 |
parse_put_property (vt_value, PROP_STRING); |
| 1051 |
|
| 1052 |
assert (parse_bundle); |
| 1053 |
prop_adopt (parse_bundle, vt_value.mutable_string); |
| 1054 |
break; |
| 1055 |
|
| 1056 |
case PARSE_IGNORE_INTEGER: |
| 1057 |
(void) parse_get_taf_integer (); |
| 1058 |
break; |
| 1059 |
case PARSE_IGNORE_BOOLEAN: |
| 1060 |
(void) parse_get_taf_boolean (); |
| 1061 |
break; |
| 1062 |
case PARSE_IGNORE_STRING: |
| 1063 |
(void) parse_get_taf_string (); |
| 1064 |
break; |
| 1065 |
|
| 1066 |
default: |
| 1067 |
sc_fatal ("parse_terminal: bad type, %c\n", terminal[0]); |
| 1068 |
} |
| 1069 |
|
| 1070 |
|
| 1071 |
parse_pop_key (); |
| 1072 |
|
| 1073 |
if (parse_trace) |
| 1074 |
sc_trace ("Parse: leaving terminal %s\n", terminal); |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
typedef struct |
| 1084 |
{ |
| 1085 |
sc_char *name; |
| 1086 |
sc_uint hash; |
| 1087 |
sc_int length; |
| 1088 |
sc_int offset; |
| 1089 |
} sc_parse_resource_t; |
| 1090 |
|
| 1091 |
enum { RESOURCE_GROW_INCREMENT = 32 }; |
| 1092 |
static sc_int parse_resources_length = 0; |
| 1093 |
static sc_int parse_resources_size = 0; |
| 1094 |
static sc_parse_resource_t *parse_resources = NULL; |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
static void |
| 1103 |
parse_clear_v400_resources_table (void) |
| 1104 |
{ |
| 1105 |
|
| 1106 |
if (parse_resources) |
| 1107 |
{ |
| 1108 |
sc_int index_; |
| 1109 |
|
| 1110 |
for (index_ = 0; index_ < parse_resources_length; index_++) |
| 1111 |
sc_free (parse_resources[index_].name); |
| 1112 |
|
| 1113 |
sc_free (parse_resources); |
| 1114 |
parse_resources = NULL; |
| 1115 |
} |
| 1116 |
parse_resources_length = 0; |
| 1117 |
parse_resources_size = 0; |
| 1118 |
} |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
static sc_int |
| 1135 |
parse_get_v400_resource_offset (const sc_char *name, |
| 1136 |
sc_int length, sc_int *real_length) |
| 1137 |
{ |
| 1138 |
sc_char *clean_name; |
| 1139 |
sc_uint hash; |
| 1140 |
sc_int index_, offset; |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
clean_name = sc_malloc (strlen (name) + 1); |
| 1147 |
strcpy (clean_name, name); |
| 1148 |
if (strcmp (clean_name + strlen (clean_name) - 2, "##") == 0) |
| 1149 |
clean_name[strlen (clean_name) - 2] = NUL; |
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
offset = -1; |
| 1159 |
hash = sc_hash (clean_name); |
| 1160 |
for (index_ = 0; index_ < parse_resources_length; index_++) |
| 1161 |
{ |
| 1162 |
if (parse_resources[index_].hash == hash |
| 1163 |
&& strcmp (parse_resources[index_].name, clean_name) == 0) |
| 1164 |
{ |
| 1165 |
offset = parse_resources[index_].offset; |
| 1166 |
break; |
| 1167 |
} |
| 1168 |
} |
| 1169 |
if (offset != -1) |
| 1170 |
{ |
| 1171 |
*real_length = parse_resources[index_].length; |
| 1172 |
sc_free (clean_name); |
| 1173 |
return offset; |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
if (parse_resources_length == parse_resources_size) |
| 1178 |
{ |
| 1179 |
parse_resources_size += RESOURCE_GROW_INCREMENT; |
| 1180 |
parse_resources = sc_realloc (parse_resources, |
| 1181 |
parse_resources_size * |
| 1182 |
sizeof (parse_resources[0])); |
| 1183 |
} |
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
if (parse_resources_length == 0) |
| 1190 |
offset = 0; |
| 1191 |
else |
| 1192 |
{ |
| 1193 |
offset = parse_resources[parse_resources_length - 1].offset |
| 1194 |
+ parse_resources[parse_resources_length - 1].length + 1; |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
parse_resources[parse_resources_length].name = clean_name; |
| 1199 |
parse_resources[parse_resources_length].hash = hash; |
| 1200 |
parse_resources[parse_resources_length].offset = offset; |
| 1201 |
parse_resources[parse_resources_length].length = length; |
| 1202 |
parse_resources_length++; |
| 1203 |
|
| 1204 |
*real_length = length; |
| 1205 |
return offset; |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
static void |
| 1226 |
parse_handle_v400_resources (sc_bool has_sound, sc_bool has_graphics) |
| 1227 |
{ |
| 1228 |
sc_vartype_t vt_key, vt_value; |
| 1229 |
const sc_char *file; |
| 1230 |
sc_int length, offset; |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
if (has_sound) |
| 1237 |
{ |
| 1238 |
|
| 1239 |
vt_key.string = "SoundFile"; |
| 1240 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1241 |
file = parse_get_string_property (); |
| 1242 |
parse_pop_key (); |
| 1243 |
|
| 1244 |
vt_key.string = "SoundLen"; |
| 1245 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1246 |
length = parse_get_integer_property (); |
| 1247 |
parse_pop_key (); |
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
if (!sc_strempty (file) && length != 0) |
| 1254 |
{ |
| 1255 |
sc_int real_length; |
| 1256 |
|
| 1257 |
offset = parse_get_v400_resource_offset (file, length, &real_length); |
| 1258 |
vt_key.string = "SoundOffset"; |
| 1259 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1260 |
|
| 1261 |
vt_value.integer = offset; |
| 1262 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1263 |
|
| 1264 |
parse_pop_key (); |
| 1265 |
|
| 1266 |
|
| 1267 |
if (real_length != length) |
| 1268 |
{ |
| 1269 |
vt_key.string = "SoundLen"; |
| 1270 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1271 |
|
| 1272 |
vt_value.integer = real_length; |
| 1273 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1274 |
|
| 1275 |
parse_pop_key (); |
| 1276 |
} |
| 1277 |
} |
| 1278 |
} |
| 1279 |
|
| 1280 |
|
| 1281 |
if (has_graphics) |
| 1282 |
{ |
| 1283 |
|
| 1284 |
vt_key.string = "GraphicFile"; |
| 1285 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1286 |
file = parse_get_string_property (); |
| 1287 |
parse_pop_key (); |
| 1288 |
|
| 1289 |
vt_key.string = "GraphicLen"; |
| 1290 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1291 |
length = parse_get_integer_property (); |
| 1292 |
parse_pop_key (); |
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
if (!sc_strempty (file) && length != 0) |
| 1299 |
{ |
| 1300 |
sc_int real_length; |
| 1301 |
|
| 1302 |
offset = parse_get_v400_resource_offset (file, length, &real_length); |
| 1303 |
vt_key.string = "GraphicOffset"; |
| 1304 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1305 |
|
| 1306 |
vt_value.integer = offset; |
| 1307 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1308 |
|
| 1309 |
parse_pop_key (); |
| 1310 |
|
| 1311 |
|
| 1312 |
if (real_length != length) |
| 1313 |
{ |
| 1314 |
vt_key.string = "GraphicLen"; |
| 1315 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1316 |
|
| 1317 |
vt_value.integer = real_length; |
| 1318 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1319 |
|
| 1320 |
parse_pop_key (); |
| 1321 |
} |
| 1322 |
} |
| 1323 |
} |
| 1324 |
} |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
static void |
| 1334 |
parse_special (const sc_char *special) |
| 1335 |
{ |
| 1336 |
if (parse_trace) |
| 1337 |
sc_trace ("Parse: entering special %s\n", special); |
| 1338 |
|
| 1339 |
|
| 1340 |
if (strcmp (special, "{V400_RESOURCE}") == 0) |
| 1341 |
{ |
| 1342 |
sc_vartype_t vt_key[2]; |
| 1343 |
sc_bool has_sound, has_graphics; |
| 1344 |
|
| 1345 |
|
| 1346 |
vt_key[0].string = "Globals"; |
| 1347 |
vt_key[1].string = "Sound"; |
| 1348 |
has_sound = prop_get_boolean (parse_bundle, "B<-ss", vt_key); |
| 1349 |
|
| 1350 |
vt_key[1].string = "Graphics"; |
| 1351 |
has_graphics = prop_get_boolean (parse_bundle, "B<-ss", vt_key); |
| 1352 |
|
| 1353 |
|
| 1354 |
parse_handle_v400_resources (has_sound, has_graphics); |
| 1355 |
} |
| 1356 |
|
| 1357 |
|
| 1358 |
else if (strcmp (special, "{V400_ROOM_EXIT:#Dest_#Var1_#Var2_#Var3}") == 0) |
| 1359 |
{ |
| 1360 |
sc_int flag; |
| 1361 |
|
| 1362 |
|
| 1363 |
flag = parse_get_taf_integer (); |
| 1364 |
if (flag != 0) |
| 1365 |
{ |
| 1366 |
parse_taf_pushback (); |
| 1367 |
parse_descriptor ("#Dest #Var1 #Var2 #Var3"); |
| 1368 |
} |
| 1369 |
} |
| 1370 |
|
| 1371 |
|
| 1372 |
else if (strcmp (special, |
| 1373 |
"{V390_V380_ROOM_EXIT:#Dest_#Var1_#Var2_ZVar3}") == 0) |
| 1374 |
{ |
| 1375 |
sc_int flag; |
| 1376 |
|
| 1377 |
|
| 1378 |
flag = parse_get_taf_integer (); |
| 1379 |
if (flag != 0) |
| 1380 |
{ |
| 1381 |
parse_taf_pushback (); |
| 1382 |
parse_descriptor ("#Dest #Var1 #Var2 ZVar3"); |
| 1383 |
} |
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
else if (strcmp (special, "{ROOM_LIST0}") == 0 |
| 1388 |
|| strcmp (special, "{ROOM_LIST1}") == 0) |
| 1389 |
{ |
| 1390 |
sc_vartype_t vt_key, vt_value; |
| 1391 |
sc_int room_count, num_rooms, type, index_; |
| 1392 |
|
| 1393 |
|
| 1394 |
vt_key.string = "Type"; |
| 1395 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1396 |
type = parse_get_integer_property (); |
| 1397 |
parse_pop_key (); |
| 1398 |
|
| 1399 |
|
| 1400 |
switch (type) |
| 1401 |
{ |
| 1402 |
case ROOMLIST_NO_ROOMS: |
| 1403 |
case ROOMLIST_ALL_ROOMS: |
| 1404 |
case ROOMLIST_NPC_PART: |
| 1405 |
break; |
| 1406 |
|
| 1407 |
case ROOMLIST_ONE_ROOM: |
| 1408 |
|
| 1409 |
parse_element ("#Room"); |
| 1410 |
break; |
| 1411 |
|
| 1412 |
case ROOMLIST_SOME_ROOMS: |
| 1413 |
|
| 1414 |
vt_key.string = "Rooms"; |
| 1415 |
room_count = prop_get_child_count (parse_bundle, "I<-s", &vt_key); |
| 1416 |
|
| 1417 |
if (strcmp (special, "{ROOM_LIST1}") == 0) |
| 1418 |
num_rooms = room_count + 1; |
| 1419 |
else |
| 1420 |
num_rooms = room_count; |
| 1421 |
|
| 1422 |
|
| 1423 |
vt_key.string = "Rooms"; |
| 1424 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1425 |
for (index_ = 0; index_ < num_rooms; index_++) |
| 1426 |
{ |
| 1427 |
sc_bool this_room; |
| 1428 |
|
| 1429 |
|
| 1430 |
this_room = parse_get_taf_boolean (); |
| 1431 |
|
| 1432 |
|
| 1433 |
vt_key.integer = index_; |
| 1434 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 1435 |
vt_value.boolean = this_room; |
| 1436 |
parse_put_property (vt_value, PROP_BOOLEAN); |
| 1437 |
parse_pop_key (); |
| 1438 |
} |
| 1439 |
parse_pop_key (); |
| 1440 |
break; |
| 1441 |
|
| 1442 |
default: |
| 1443 |
sc_fatal ("parse_special: bad type, %ld\n", type); |
| 1444 |
} |
| 1445 |
} |
| 1446 |
|
| 1447 |
|
| 1448 |
else if (strcmp (special, "{OBJECT:#Parent}") == 0) |
| 1449 |
{ |
| 1450 |
sc_vartype_t vt_key; |
| 1451 |
sc_int type; |
| 1452 |
|
| 1453 |
|
| 1454 |
vt_key.string = "Where"; |
| 1455 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1456 |
vt_key.string = "Type"; |
| 1457 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1458 |
type = parse_get_integer_property (); |
| 1459 |
parse_pop_key (); |
| 1460 |
parse_pop_key (); |
| 1461 |
|
| 1462 |
|
| 1463 |
if (type == ROOMLIST_NPC_PART) |
| 1464 |
parse_element ("#Parent"); |
| 1465 |
} |
| 1466 |
|
| 1467 |
|
| 1468 |
else if (strcmp (special, "{WALK:#Rooms_#Times}") == 0) |
| 1469 |
{ |
| 1470 |
sc_vartype_t vt_key, vt_value; |
| 1471 |
sc_int num_stops, index_; |
| 1472 |
|
| 1473 |
|
| 1474 |
vt_key.string = "NumStops"; |
| 1475 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1476 |
num_stops = parse_get_integer_property (); |
| 1477 |
parse_pop_key (); |
| 1478 |
|
| 1479 |
|
| 1480 |
for (index_ = 0; index_ < num_stops; index_++) |
| 1481 |
{ |
| 1482 |
sc_int room, time; |
| 1483 |
|
| 1484 |
|
| 1485 |
vt_key.string = "Rooms"; |
| 1486 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1487 |
vt_key.integer = index_; |
| 1488 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 1489 |
|
| 1490 |
room = parse_get_taf_integer (); |
| 1491 |
|
| 1492 |
vt_value.integer = room; |
| 1493 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1494 |
parse_pop_key (); |
| 1495 |
parse_pop_key (); |
| 1496 |
|
| 1497 |
|
| 1498 |
vt_key.string = "Times"; |
| 1499 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1500 |
vt_key.integer = index_; |
| 1501 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 1502 |
|
| 1503 |
time = parse_get_taf_integer (); |
| 1504 |
|
| 1505 |
vt_value.integer = time; |
| 1506 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1507 |
parse_pop_key (); |
| 1508 |
parse_pop_key (); |
| 1509 |
} |
| 1510 |
} |
| 1511 |
|
| 1512 |
|
| 1513 |
else if (strcmp (special, "{ROOM_GROUP:[]BList}") == 0) |
| 1514 |
{ |
| 1515 |
sc_vartype_t vt_key, vt_value; |
| 1516 |
sc_int num_rooms, index_, l2index_; |
| 1517 |
sc_bool in_group; |
| 1518 |
|
| 1519 |
|
| 1520 |
vt_key.string = "Rooms"; |
| 1521 |
num_rooms = prop_get_integer (parse_bundle, "I<-s", &vt_key); |
| 1522 |
|
| 1523 |
|
| 1524 |
l2index_ = 0; |
| 1525 |
for (index_ = 0; index_ < num_rooms; index_++) |
| 1526 |
{ |
| 1527 |
in_group = parse_get_taf_boolean (); |
| 1528 |
|
| 1529 |
|
| 1530 |
vt_key.string = "List"; |
| 1531 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1532 |
vt_key.integer = index_; |
| 1533 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 1534 |
vt_value.boolean = in_group; |
| 1535 |
parse_put_property (vt_value, PROP_BOOLEAN); |
| 1536 |
|
| 1537 |
parse_pop_key (); |
| 1538 |
parse_pop_key (); |
| 1539 |
|
| 1540 |
|
| 1541 |
if (in_group) |
| 1542 |
{ |
| 1543 |
vt_key.string = "List2"; |
| 1544 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1545 |
vt_key.integer = l2index_; |
| 1546 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 1547 |
vt_value.integer = index_; |
| 1548 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1549 |
|
| 1550 |
parse_pop_key (); |
| 1551 |
parse_pop_key (); |
| 1552 |
|
| 1553 |
l2index_++; |
| 1554 |
} |
| 1555 |
} |
| 1556 |
} |
| 1557 |
|
| 1558 |
|
| 1559 |
else |
| 1560 |
{ |
| 1561 |
sc_fatal ("parse_special: no handler for \"%s\"\n", special); |
| 1562 |
} |
| 1563 |
|
| 1564 |
if (parse_trace) |
| 1565 |
sc_trace ("Parse: leaving special %s\n", special); |
| 1566 |
} |
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
static void |
| 1576 |
parse_fixup_v390_v380_room_alt (const sc_char *m1, sc_int type, |
| 1577 |
const sc_char *resource1, |
| 1578 |
const sc_char *m2, sc_int var2, |
| 1579 |
const sc_char *resource2, |
| 1580 |
sc_int hide_objects, |
| 1581 |
const sc_char *changed, |
| 1582 |
sc_int var3, sc_int display_room) |
| 1583 |
{ |
| 1584 |
sc_vartype_t vt_key, vt_value, vt_gkey[2]; |
| 1585 |
sc_bool has_sound, has_graphics; |
| 1586 |
sc_int alt_count; |
| 1587 |
const sc_char *soundfile1, *graphicfile1; |
| 1588 |
const sc_char *soundfile2, *graphicfile2; |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
soundfile1 = ""; |
| 1595 |
graphicfile1 = ""; |
| 1596 |
soundfile2 = ""; |
| 1597 |
graphicfile2 = ""; |
| 1598 |
|
| 1599 |
|
| 1600 |
vt_gkey[0].string = "Globals"; |
| 1601 |
vt_gkey[1].string = "Sound"; |
| 1602 |
has_sound = prop_get_boolean (parse_bundle, "B<-ss", vt_gkey); |
| 1603 |
|
| 1604 |
vt_gkey[1].string = "Graphics"; |
| 1605 |
has_graphics = prop_get_boolean (parse_bundle, "B<-ss", vt_gkey); |
| 1606 |
|
| 1607 |
|
| 1608 |
vt_key.string = "Alts"; |
| 1609 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1610 |
alt_count = parse_get_child_count (); |
| 1611 |
parse_pop_key (); |
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
if (has_sound || has_graphics) |
| 1618 |
{ |
| 1619 |
if (resource1) |
| 1620 |
{ |
| 1621 |
vt_key.string = resource1; |
| 1622 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1623 |
if (has_sound) |
| 1624 |
{ |
| 1625 |
vt_key.string = "SoundFile"; |
| 1626 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1627 |
soundfile1 = parse_get_string_property (); |
| 1628 |
parse_pop_key (); |
| 1629 |
} |
| 1630 |
if (has_graphics) |
| 1631 |
{ |
| 1632 |
vt_key.string = "GraphicFile"; |
| 1633 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1634 |
graphicfile1 = parse_get_string_property (); |
| 1635 |
parse_pop_key (); |
| 1636 |
} |
| 1637 |
parse_pop_key (); |
| 1638 |
} |
| 1639 |
|
| 1640 |
if (resource2) |
| 1641 |
{ |
| 1642 |
vt_key.string = resource2; |
| 1643 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1644 |
if (has_sound) |
| 1645 |
{ |
| 1646 |
vt_key.string = "SoundFile"; |
| 1647 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1648 |
soundfile2 = parse_get_string_property (); |
| 1649 |
parse_pop_key (); |
| 1650 |
} |
| 1651 |
if (has_graphics) |
| 1652 |
{ |
| 1653 |
vt_key.string = "GraphicFile"; |
| 1654 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1655 |
graphicfile2 = parse_get_string_property (); |
| 1656 |
parse_pop_key (); |
| 1657 |
} |
| 1658 |
parse_pop_key (); |
| 1659 |
} |
| 1660 |
} |
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
vt_key.integer = alt_count; |
| 1669 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 1670 |
vt_key.string = "Alts"; |
| 1671 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1672 |
|
| 1673 |
|
| 1674 |
vt_key.string = "M1"; |
| 1675 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1676 |
vt_value.string = m1; |
| 1677 |
parse_put_property (vt_value, PROP_STRING); |
| 1678 |
parse_pop_key (); |
| 1679 |
vt_key.string = "Type"; |
| 1680 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1681 |
vt_value.integer = type; |
| 1682 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1683 |
parse_pop_key (); |
| 1684 |
|
| 1685 |
|
| 1686 |
if (has_sound || has_graphics) |
| 1687 |
{ |
| 1688 |
vt_key.string = "Res1"; |
| 1689 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1690 |
if (has_sound) |
| 1691 |
{ |
| 1692 |
vt_key.string = "SoundFile"; |
| 1693 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1694 |
vt_value.string = soundfile1; |
| 1695 |
parse_put_property (vt_value, PROP_STRING); |
| 1696 |
parse_pop_key (); |
| 1697 |
vt_key.string = "SoundLen"; |
| 1698 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1699 |
vt_value.integer = 0; |
| 1700 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1701 |
parse_pop_key (); |
| 1702 |
} |
| 1703 |
if (has_graphics) |
| 1704 |
{ |
| 1705 |
vt_key.string = "GraphicFile"; |
| 1706 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1707 |
vt_value.string = graphicfile1; |
| 1708 |
parse_put_property (vt_value, PROP_STRING); |
| 1709 |
parse_pop_key (); |
| 1710 |
vt_key.string = "GraphicLen"; |
| 1711 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1712 |
vt_value.integer = 0; |
| 1713 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1714 |
parse_pop_key (); |
| 1715 |
} |
| 1716 |
parse_pop_key (); |
| 1717 |
} |
| 1718 |
|
| 1719 |
|
| 1720 |
vt_key.string = "M2"; |
| 1721 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1722 |
vt_value.string = m2; |
| 1723 |
parse_put_property (vt_value, PROP_STRING); |
| 1724 |
parse_pop_key (); |
| 1725 |
vt_key.string = "Var2"; |
| 1726 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1727 |
vt_value.integer = var2; |
| 1728 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1729 |
parse_pop_key (); |
| 1730 |
|
| 1731 |
|
| 1732 |
if (has_sound || has_graphics) |
| 1733 |
{ |
| 1734 |
vt_key.string = "Res2"; |
| 1735 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1736 |
if (has_sound) |
| 1737 |
{ |
| 1738 |
vt_key.string = "SoundFile"; |
| 1739 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1740 |
vt_value.string = soundfile2; |
| 1741 |
parse_put_property (vt_value, PROP_STRING); |
| 1742 |
parse_pop_key (); |
| 1743 |
vt_key.string = "SoundLen"; |
| 1744 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1745 |
vt_value.integer = 0; |
| 1746 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1747 |
parse_pop_key (); |
| 1748 |
} |
| 1749 |
if (has_graphics) |
| 1750 |
{ |
| 1751 |
vt_key.string = "GraphicFile"; |
| 1752 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1753 |
vt_value.string = graphicfile2; |
| 1754 |
parse_put_property (vt_value, PROP_STRING); |
| 1755 |
parse_pop_key (); |
| 1756 |
vt_key.string = "GraphicLen"; |
| 1757 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1758 |
vt_value.integer = 0; |
| 1759 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1760 |
parse_pop_key (); |
| 1761 |
} |
| 1762 |
parse_pop_key (); |
| 1763 |
} |
| 1764 |
|
| 1765 |
|
| 1766 |
vt_key.string = "HideObjects"; |
| 1767 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1768 |
vt_value.integer = hide_objects; |
| 1769 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1770 |
parse_pop_key (); |
| 1771 |
vt_key.string = "Changed"; |
| 1772 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1773 |
vt_value.string = changed; |
| 1774 |
parse_put_property (vt_value, PROP_STRING); |
| 1775 |
parse_pop_key (); |
| 1776 |
vt_key.string = "Var3"; |
| 1777 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1778 |
vt_value.integer = var3; |
| 1779 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1780 |
parse_pop_key (); |
| 1781 |
vt_key.string = "DisplayRoom"; |
| 1782 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1783 |
vt_value.integer = display_room; |
| 1784 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1785 |
parse_pop_key (); |
| 1786 |
|
| 1787 |
parse_pop_key (); |
| 1788 |
parse_pop_key (); |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
enum { V390_V380_ALT_TYPEHIDE_MULT = 10 }; |
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
static void |
| 1803 |
parse_fixup_v390_v380_room_alts (void) |
| 1804 |
{ |
| 1805 |
sc_vartype_t vt_key; |
| 1806 |
const sc_char *m1, *m2, *changed; |
| 1807 |
sc_int type, var2, hide_objects, var3, display_room; |
| 1808 |
|
| 1809 |
|
| 1810 |
m2 = ""; |
| 1811 |
changed = ""; |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
type = 2; |
| 1818 |
display_room = 0; |
| 1819 |
|
| 1820 |
vt_key.string = "Obj"; |
| 1821 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1822 |
var3 = parse_get_integer_property (); |
| 1823 |
parse_pop_key (); |
| 1824 |
|
| 1825 |
if (var3 > 0) |
| 1826 |
{ |
| 1827 |
sc_int typehideobjects; |
| 1828 |
|
| 1829 |
vt_key.string = "AltDesc"; |
| 1830 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1831 |
m1 = parse_get_string_property (); |
| 1832 |
parse_pop_key (); |
| 1833 |
|
| 1834 |
vt_key.string = "TypeHideObjects"; |
| 1835 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1836 |
typehideobjects = parse_get_integer_property (); |
| 1837 |
parse_pop_key (); |
| 1838 |
|
| 1839 |
var2 = typehideobjects / V390_V380_ALT_TYPEHIDE_MULT; |
| 1840 |
hide_objects = typehideobjects % V390_V380_ALT_TYPEHIDE_MULT; |
| 1841 |
|
| 1842 |
parse_fixup_v390_v380_room_alt (m1, type, "AltRes", |
| 1843 |
m2, var2, NULL, |
| 1844 |
hide_objects, changed, var3, |
| 1845 |
display_room); |
| 1846 |
} |
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
type = 0; |
| 1853 |
display_room = 1; |
| 1854 |
|
| 1855 |
vt_key.string = "Task2"; |
| 1856 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1857 |
var2 = parse_get_integer_property (); |
| 1858 |
parse_pop_key (); |
| 1859 |
|
| 1860 |
if (var2 > 0) |
| 1861 |
{ |
| 1862 |
vt_key.string = "AddDesc2"; |
| 1863 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1864 |
m1 = parse_get_string_property (); |
| 1865 |
parse_pop_key (); |
| 1866 |
|
| 1867 |
var3 = 0; |
| 1868 |
hide_objects = 0; |
| 1869 |
|
| 1870 |
parse_fixup_v390_v380_room_alt (m1, type, "Task2Res", |
| 1871 |
m2, var2, NULL, |
| 1872 |
hide_objects, changed, var3, |
| 1873 |
display_room); |
| 1874 |
} |
| 1875 |
|
| 1876 |
|
| 1877 |
type = 0; |
| 1878 |
display_room = 1; |
| 1879 |
|
| 1880 |
vt_key.string = "Task1"; |
| 1881 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1882 |
var2 = parse_get_integer_property (); |
| 1883 |
parse_pop_key (); |
| 1884 |
|
| 1885 |
if (var2 > 0) |
| 1886 |
{ |
| 1887 |
vt_key.string = "AddDesc1"; |
| 1888 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1889 |
m1 = parse_get_string_property (); |
| 1890 |
parse_pop_key (); |
| 1891 |
|
| 1892 |
var3 = 0; |
| 1893 |
hide_objects = 0; |
| 1894 |
|
| 1895 |
parse_fixup_v390_v380_room_alt (m1, type, "Task1Res", |
| 1896 |
m2, var2, NULL, |
| 1897 |
hide_objects, changed, var3, |
| 1898 |
display_room); |
| 1899 |
} |
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
type = 0; |
| 1906 |
display_room = 2; |
| 1907 |
|
| 1908 |
vt_key.string = "LastDesc"; |
| 1909 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1910 |
m1 = parse_get_string_property (); |
| 1911 |
parse_pop_key (); |
| 1912 |
|
| 1913 |
if (!sc_strempty (m1)) |
| 1914 |
{ |
| 1915 |
var2 = 0; |
| 1916 |
var3 = 0; |
| 1917 |
hide_objects = 0; |
| 1918 |
|
| 1919 |
parse_fixup_v390_v380_room_alt (m1, type, "LastRes", |
| 1920 |
m2, var2, NULL, |
| 1921 |
hide_objects, changed, var3, |
| 1922 |
display_room); |
| 1923 |
} |
| 1924 |
} |
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
static void |
| 1934 |
parse_fixup_v390 (const sc_char *fixup) |
| 1935 |
{ |
| 1936 |
if (parse_trace) |
| 1937 |
sc_trace ("Parse: entering version 3.9 fixup %s\n", fixup); |
| 1938 |
|
| 1939 |
|
| 1940 |
if (strcmp (fixup, "|V390_TASK_ACTION:Type>4?#Type++|") == 0) |
| 1941 |
{ |
| 1942 |
sc_vartype_t vt_key, vt_value; |
| 1943 |
sc_int type; |
| 1944 |
|
| 1945 |
|
| 1946 |
vt_key.string = "Type"; |
| 1947 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1948 |
type = parse_get_integer_property (); |
| 1949 |
|
| 1950 |
if (type > 4) |
| 1951 |
{ |
| 1952 |
vt_value.integer = type + 1; |
| 1953 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1954 |
} |
| 1955 |
|
| 1956 |
parse_pop_key (); |
| 1957 |
} |
| 1958 |
|
| 1959 |
|
| 1960 |
else if (strcmp (fixup, "|V390_TASK_ACTION:$Expr_#Var5|") == 0) |
| 1961 |
{ |
| 1962 |
sc_vartype_t vt_key; |
| 1963 |
sc_int var2; |
| 1964 |
|
| 1965 |
|
| 1966 |
vt_key.string = "Var2"; |
| 1967 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1968 |
var2 = parse_get_integer_property (); |
| 1969 |
parse_pop_key (); |
| 1970 |
|
| 1971 |
if (var2 == 5) |
| 1972 |
parse_descriptor ("$Expr ZVar5"); |
| 1973 |
else |
| 1974 |
parse_descriptor ("EExpr #Var5"); |
| 1975 |
} |
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
else if (strcmp (fixup, "|V390_OBJECT:_Openable_,Key|") == 0) |
| 1981 |
{ |
| 1982 |
sc_vartype_t vt_key, vt_value; |
| 1983 |
sc_int openable; |
| 1984 |
|
| 1985 |
|
| 1986 |
vt_key.string = "Openable"; |
| 1987 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 1988 |
openable = parse_get_integer_property (); |
| 1989 |
|
| 1990 |
if (openable == 5 || openable == 6) |
| 1991 |
{ |
| 1992 |
vt_value.integer = (openable == 5) ? 6 : 5; |
| 1993 |
parse_put_property (vt_value, PROP_INTEGER); |
| 1994 |
} |
| 1995 |
|
| 1996 |
parse_pop_key (); |
| 1997 |
|
| 1998 |
|
| 1999 |
if (openable == 5 || openable == 6) |
| 2000 |
{ |
| 2001 |
vt_key.string = "Key"; |
| 2002 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2003 |
vt_value.integer = -1; |
| 2004 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2005 |
parse_pop_key (); |
| 2006 |
} |
| 2007 |
} |
| 2008 |
|
| 2009 |
|
| 2010 |
else if (strcmp (fixup, "|V390_TASK:$RestrMask|") == 0) |
| 2011 |
{ |
| 2012 |
sc_vartype_t vt_key, vt_value; |
| 2013 |
sc_int restriction_count; |
| 2014 |
|
| 2015 |
|
| 2016 |
vt_key.string = "Restrictions"; |
| 2017 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2018 |
restriction_count = parse_get_child_count (); |
| 2019 |
parse_pop_key (); |
| 2020 |
|
| 2021 |
|
| 2022 |
if (restriction_count > 0) |
| 2023 |
{ |
| 2024 |
sc_char *restrmask; |
| 2025 |
sc_int index_; |
| 2026 |
|
| 2027 |
restrmask = sc_malloc (2 * restriction_count); |
| 2028 |
strcpy (restrmask, "#"); |
| 2029 |
for (index_ = 1; index_ < restriction_count; index_++) |
| 2030 |
strcat (restrmask, "A#"); |
| 2031 |
|
| 2032 |
vt_key.string = "RestrMask"; |
| 2033 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2034 |
vt_value.string = restrmask; |
| 2035 |
parse_put_property (vt_value, PROP_STRING); |
| 2036 |
parse_pop_key (); |
| 2037 |
|
| 2038 |
prop_adopt (parse_bundle, restrmask); |
| 2039 |
} |
| 2040 |
} |
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
else if (strcmp (fixup, "|V390_TASK_RESTR:Var1>0?#Var1++|") == 0) |
| 2047 |
{ |
| 2048 |
sc_vartype_t vt_key, vt_value; |
| 2049 |
sc_int var1; |
| 2050 |
|
| 2051 |
|
| 2052 |
vt_key.string = "Var1"; |
| 2053 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2054 |
var1 = parse_get_integer_property (); |
| 2055 |
|
| 2056 |
if (var1 > 0) |
| 2057 |
{ |
| 2058 |
vt_value.integer = var1 + 1; |
| 2059 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2060 |
} |
| 2061 |
|
| 2062 |
parse_pop_key (); |
| 2063 |
} |
| 2064 |
|
| 2065 |
|
| 2066 |
else if (strcmp (fixup, "|V390_ROOM:_Alts_|") == 0) |
| 2067 |
{ |
| 2068 |
parse_fixup_v390_v380_room_alts (); |
| 2069 |
} |
| 2070 |
|
| 2071 |
|
| 2072 |
else |
| 2073 |
{ |
| 2074 |
sc_fatal ("parse_fixup_v390: no handler for \"%s\"\n", fixup); |
| 2075 |
} |
| 2076 |
|
| 2077 |
if (parse_trace) |
| 2078 |
sc_trace ("Parse: leaving version 3.9 fixup %s\n", fixup); |
| 2079 |
} |
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
enum { V380_OBJ_IS_SURFACE = 2, V380_OBJ_IS_CONTAINER = 1 }; |
| 2088 |
enum { V380_OBJ_CAPACITY_MULT = 10, V380_OBJ_DEFAULT_SIZE = 2 }; |
| 2089 |
enum { V380_TASK_MOVEMENTS = 6 }; |
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
static void |
| 2097 |
parse_fixup_v380_action (sc_int type, sc_int var_count, |
| 2098 |
sc_int var1, sc_int var2, sc_int var3) |
| 2099 |
{ |
| 2100 |
sc_vartype_t vt_key, vt_value; |
| 2101 |
sc_int action_count; |
| 2102 |
|
| 2103 |
|
| 2104 |
vt_key.string = "Actions"; |
| 2105 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2106 |
action_count = parse_get_child_count (); |
| 2107 |
parse_pop_key (); |
| 2108 |
|
| 2109 |
|
| 2110 |
vt_key.integer = action_count; |
| 2111 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 2112 |
vt_key.string = "Actions"; |
| 2113 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2114 |
|
| 2115 |
|
| 2116 |
vt_key.string = "Type"; |
| 2117 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2118 |
vt_value.integer = type; |
| 2119 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2120 |
parse_pop_key (); |
| 2121 |
|
| 2122 |
vt_key.string = "Var1"; |
| 2123 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2124 |
vt_value.integer = var1; |
| 2125 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2126 |
parse_pop_key (); |
| 2127 |
|
| 2128 |
if (var_count > 1) |
| 2129 |
{ |
| 2130 |
vt_key.string = "Var2"; |
| 2131 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2132 |
vt_value.integer = var2; |
| 2133 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2134 |
parse_pop_key (); |
| 2135 |
} |
| 2136 |
|
| 2137 |
if (var_count > 2) |
| 2138 |
{ |
| 2139 |
vt_key.string = "Var3"; |
| 2140 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2141 |
vt_value.integer = var3; |
| 2142 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2143 |
parse_pop_key (); |
| 2144 |
} |
| 2145 |
|
| 2146 |
parse_pop_key (); |
| 2147 |
parse_pop_key (); |
| 2148 |
} |
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
static void |
| 2157 |
parse_fixup_v380_movement (sc_int mvar1, sc_int mvar2, sc_int mvar3) |
| 2158 |
{ |
| 2159 |
sc_int var1; |
| 2160 |
|
| 2161 |
|
| 2162 |
if (mvar1 == 0) |
| 2163 |
return; |
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
if (mvar1 == 1) |
| 2171 |
{ |
| 2172 |
if (mvar3 == 0 && mvar2 >= 2) |
| 2173 |
parse_fixup_v380_action (1, 3, 0, 0, mvar2 - 2); |
| 2174 |
return; |
| 2175 |
} |
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
switch (mvar1) |
| 2182 |
{ |
| 2183 |
case 2: |
| 2184 |
var1 = 2; |
| 2185 |
break; |
| 2186 |
case 3: |
| 2187 |
var1 = 0; |
| 2188 |
break; |
| 2189 |
default: |
| 2190 |
var1 = mvar1 - 1; |
| 2191 |
break; |
| 2192 |
} |
| 2193 |
|
| 2194 |
|
| 2195 |
switch (mvar3) |
| 2196 |
{ |
| 2197 |
case 0: |
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
if (mvar2 == 0) |
| 2204 |
parse_fixup_v380_action (0, 3, var1, 0, 0); |
| 2205 |
else if (mvar2 == 1) |
| 2206 |
parse_fixup_v380_action (0, 3, var1, 6, 0); |
| 2207 |
else |
| 2208 |
parse_fixup_v380_action (0, 3, var1, 0, mvar2 - 1); |
| 2209 |
break; |
| 2210 |
|
| 2211 |
case 1: |
| 2212 |
case 2: |
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
if (mvar2 > 0) |
| 2218 |
parse_fixup_v380_action (0, 3, var1, mvar3 + 1, mvar2 - 1); |
| 2219 |
break; |
| 2220 |
|
| 2221 |
case 3: |
| 2222 |
case 4: |
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
parse_fixup_v380_action (0, 3, var1, mvar3 + 1, mvar2); |
| 2229 |
break; |
| 2230 |
|
| 2231 |
default: |
| 2232 |
sc_fatal ("parse_fixup_v380_movement: invalid mvar3, %ld\n", mvar3); |
| 2233 |
} |
| 2234 |
} |
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
static void |
| 2243 |
parse_fixup_v380_restr (sc_int type, sc_int var_count, |
| 2244 |
sc_int var1, sc_int var2, sc_int var3, |
| 2245 |
const sc_char *failmessage) |
| 2246 |
{ |
| 2247 |
sc_vartype_t vt_key, vt_value; |
| 2248 |
sc_int restriction_count; |
| 2249 |
|
| 2250 |
|
| 2251 |
vt_key.string = "Restrictions"; |
| 2252 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2253 |
restriction_count = parse_get_child_count (); |
| 2254 |
parse_pop_key (); |
| 2255 |
|
| 2256 |
|
| 2257 |
vt_key.integer = restriction_count; |
| 2258 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 2259 |
vt_key.string = "Restrictions"; |
| 2260 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2261 |
|
| 2262 |
|
| 2263 |
vt_key.string = "Type"; |
| 2264 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2265 |
vt_value.integer = type; |
| 2266 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2267 |
parse_pop_key (); |
| 2268 |
|
| 2269 |
vt_key.string = "Var1"; |
| 2270 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2271 |
vt_value.integer = var1; |
| 2272 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2273 |
parse_pop_key (); |
| 2274 |
|
| 2275 |
if (var_count > 1) |
| 2276 |
{ |
| 2277 |
vt_key.string = "Var2"; |
| 2278 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2279 |
vt_value.integer = var2; |
| 2280 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2281 |
parse_pop_key (); |
| 2282 |
} |
| 2283 |
|
| 2284 |
if (var_count > 2) |
| 2285 |
{ |
| 2286 |
vt_key.string = "Var3"; |
| 2287 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2288 |
vt_value.integer = var3; |
| 2289 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2290 |
parse_pop_key (); |
| 2291 |
} |
| 2292 |
|
| 2293 |
vt_key.string = "FailMessage"; |
| 2294 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2295 |
vt_value.string = failmessage; |
| 2296 |
parse_put_property (vt_value, PROP_STRING); |
| 2297 |
parse_pop_key (); |
| 2298 |
|
| 2299 |
parse_pop_key (); |
| 2300 |
parse_pop_key (); |
| 2301 |
} |
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
static void |
| 2315 |
parse_fixup_v380_obj_restr (sc_bool holding, |
| 2316 |
sc_int holdobj, const sc_char *failmessage) |
| 2317 |
{ |
| 2318 |
|
| 2319 |
if (holdobj > 0) |
| 2320 |
{ |
| 2321 |
sc_int var1, var2; |
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
var1 = (holdobj == 1) ? 2 : holdobj + 1; |
| 2329 |
var2 = holding ? 1 : 3; |
| 2330 |
parse_fixup_v380_restr (0, 3, var1, var2, 0, failmessage); |
| 2331 |
} |
| 2332 |
} |
| 2333 |
|
| 2334 |
static void |
| 2335 |
parse_fixup_v380_task_restr (sc_bool tasknotdone, sc_int task, |
| 2336 |
const sc_char *failmessage) |
| 2337 |
{ |
| 2338 |
|
| 2339 |
if (task > 0) |
| 2340 |
{ |
| 2341 |
sc_int var2; |
| 2342 |
|
| 2343 |
|
| 2344 |
var2 = tasknotdone ? 1 : 0; |
| 2345 |
parse_fixup_v380_restr (2, 2, task, var2, 0, failmessage); |
| 2346 |
} |
| 2347 |
} |
| 2348 |
|
| 2349 |
static void |
| 2350 |
parse_fixup_v380_wear_restr (sc_int wearobj, const sc_char *failmessage) |
| 2351 |
{ |
| 2352 |
|
| 2353 |
if (wearobj > 0) |
| 2354 |
{ |
| 2355 |
sc_vartype_t vt_key[3]; |
| 2356 |
sc_int object_count, object, dynamic, obj_index; |
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
if (wearobj == 1) |
| 2363 |
{ |
| 2364 |
parse_fixup_v380_restr (0, 3, 1, 2, 0, failmessage); |
| 2365 |
return; |
| 2366 |
} |
| 2367 |
else if (wearobj == 2) |
| 2368 |
{ |
| 2369 |
parse_fixup_v380_restr (0, 3, 0, 2, 0, failmessage); |
| 2370 |
return; |
| 2371 |
} |
| 2372 |
|
| 2373 |
|
| 2374 |
vt_key[0].string = "Objects"; |
| 2375 |
object_count = prop_get_child_count (parse_bundle, "I<-s", vt_key); |
| 2376 |
|
| 2377 |
|
| 2378 |
wearobj -= 2; |
| 2379 |
for (object = 0; object < object_count && wearobj > 0; object++) |
| 2380 |
{ |
| 2381 |
sc_bool bstatic, wearable; |
| 2382 |
|
| 2383 |
vt_key[1].integer = object; |
| 2384 |
vt_key[2].string = "Static"; |
| 2385 |
bstatic = prop_get_boolean (parse_bundle, "B<-sis", vt_key); |
| 2386 |
if (!bstatic) |
| 2387 |
{ |
| 2388 |
vt_key[2].string = "Wearable"; |
| 2389 |
wearable = prop_get_boolean (parse_bundle, "B<-sis", vt_key); |
| 2390 |
if (wearable) |
| 2391 |
wearobj--; |
| 2392 |
} |
| 2393 |
} |
| 2394 |
obj_index = object - 1; |
| 2395 |
|
| 2396 |
|
| 2397 |
dynamic = 0; |
| 2398 |
for (object = 0; object <= obj_index; object++) |
| 2399 |
{ |
| 2400 |
sc_bool bstatic; |
| 2401 |
|
| 2402 |
vt_key[1].integer = object; |
| 2403 |
vt_key[2].string = "Static"; |
| 2404 |
bstatic = prop_get_boolean (parse_bundle, "B<-sis", vt_key); |
| 2405 |
if (!bstatic) |
| 2406 |
dynamic++; |
| 2407 |
} |
| 2408 |
dynamic--; |
| 2409 |
|
| 2410 |
|
| 2411 |
parse_fixup_v380_restr (0, 3, dynamic + 3, 2, 0, failmessage); |
| 2412 |
} |
| 2413 |
} |
| 2414 |
|
| 2415 |
static void |
| 2416 |
parse_fixup_v380_npc_restr (sc_bool notinsameroom, sc_int npc, |
| 2417 |
const sc_char *failmessage) |
| 2418 |
{ |
| 2419 |
|
| 2420 |
if (npc > 0) |
| 2421 |
{ |
| 2422 |
sc_int var2; |
| 2423 |
|
| 2424 |
if (npc == 1) |
| 2425 |
{ |
| 2426 |
|
| 2427 |
var2 = notinsameroom ? 3 : 2; |
| 2428 |
parse_fixup_v380_restr (3, 3, 0, var2, 0, failmessage); |
| 2429 |
return; |
| 2430 |
} |
| 2431 |
|
| 2432 |
|
| 2433 |
var2 = notinsameroom ? 1 : 0; |
| 2434 |
parse_fixup_v380_restr (3, 3, 0, var2, npc, failmessage); |
| 2435 |
} |
| 2436 |
} |
| 2437 |
|
| 2438 |
static void |
| 2439 |
parse_fixup_v380_objroom_restr (sc_int obj, sc_int objroom, |
| 2440 |
const sc_char *failmessage) |
| 2441 |
{ |
| 2442 |
|
| 2443 |
if (obj > 0) |
| 2444 |
{ |
| 2445 |
|
| 2446 |
parse_fixup_v380_restr (0, 3, obj + 1, 0, objroom, failmessage); |
| 2447 |
} |
| 2448 |
} |
| 2449 |
|
| 2450 |
static void |
| 2451 |
parse_fixup_v380_objstate_restr (sc_int obj, sc_int ivar1, sc_int ivar2, |
| 2452 |
const sc_char *failmessage) |
| 2453 |
{ |
| 2454 |
sc_vartype_t vt_key[3]; |
| 2455 |
sc_int object, dynamic, var2, var3; |
| 2456 |
|
| 2457 |
|
| 2458 |
var2 = -1; |
| 2459 |
var3 = -1; |
| 2460 |
|
| 2461 |
|
| 2462 |
if (ivar1 == 0) |
| 2463 |
return; |
| 2464 |
|
| 2465 |
|
| 2466 |
if (ivar1 == 3 || ivar1 == 4) |
| 2467 |
{ |
| 2468 |
sc_int stateful; |
| 2469 |
|
| 2470 |
|
| 2471 |
stateful = 0; |
| 2472 |
for (object = 0; object <= obj - 1; object++) |
| 2473 |
{ |
| 2474 |
sc_int openable; |
| 2475 |
|
| 2476 |
vt_key[0].string = "Objects"; |
| 2477 |
vt_key[1].integer = object; |
| 2478 |
vt_key[2].string = "Openable"; |
| 2479 |
openable = prop_get_integer (parse_bundle, "I<-sis", vt_key); |
| 2480 |
if (openable > 0) |
| 2481 |
stateful++; |
| 2482 |
} |
| 2483 |
stateful--; |
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
var2 = (ivar1 == 3) ? 0 : 1; |
| 2490 |
parse_fixup_v380_restr (1, 2, stateful + 1, var2, 0, failmessage); |
| 2491 |
return; |
| 2492 |
} |
| 2493 |
|
| 2494 |
|
| 2495 |
dynamic = 0; |
| 2496 |
for (object = 0; object <= obj - 1; object++) |
| 2497 |
{ |
| 2498 |
sc_bool bstatic; |
| 2499 |
|
| 2500 |
vt_key[0].string = "Objects"; |
| 2501 |
vt_key[1].integer = object; |
| 2502 |
vt_key[2].string = "Static"; |
| 2503 |
bstatic = prop_get_boolean (parse_bundle, "B<-sis", vt_key); |
| 2504 |
if (!bstatic) |
| 2505 |
dynamic++; |
| 2506 |
} |
| 2507 |
dynamic--; |
| 2508 |
|
| 2509 |
|
| 2510 |
switch (ivar1) |
| 2511 |
{ |
| 2512 |
case 1: |
| 2513 |
var2 = 4; |
| 2514 |
var3 = ivar2; |
| 2515 |
break; |
| 2516 |
case 2: |
| 2517 |
var2 = 5; |
| 2518 |
var3 = ivar2; |
| 2519 |
break; |
| 2520 |
case 5: |
| 2521 |
var2 = 1; |
| 2522 |
var3 = ivar2 + 1; |
| 2523 |
break; |
| 2524 |
case 6: |
| 2525 |
var2 = 2; |
| 2526 |
var3 = ivar2 + 1; |
| 2527 |
break; |
| 2528 |
default: |
| 2529 |
sc_fatal ("parse_fixup_v380_objstate_restr: invalid ivar1, %ld\n", ivar1); |
| 2530 |
} |
| 2531 |
parse_fixup_v380_restr (0, 3, dynamic + 3, var2, var3, failmessage); |
| 2532 |
} |
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
static void |
| 2542 |
parse_fixup_v380 (const sc_char *fixup) |
| 2543 |
{ |
| 2544 |
if (parse_trace) |
| 2545 |
sc_trace ("Parse: entering version 3.8 fixup %s\n", fixup); |
| 2546 |
|
| 2547 |
|
| 2548 |
if (strcmp (fixup, "|V380_OBJECT:#Capacity*10+2|") == 0) |
| 2549 |
{ |
| 2550 |
sc_vartype_t vt_key, vt_value; |
| 2551 |
sc_int surfacecontainer; |
| 2552 |
|
| 2553 |
|
| 2554 |
vt_key.string = "SurfaceContainer"; |
| 2555 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2556 |
surfacecontainer = parse_get_integer_property (); |
| 2557 |
parse_pop_key (); |
| 2558 |
|
| 2559 |
|
| 2560 |
if (surfacecontainer == V380_OBJ_IS_CONTAINER) |
| 2561 |
{ |
| 2562 |
sc_int capacity; |
| 2563 |
|
| 2564 |
vt_key.string = "Capacity"; |
| 2565 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2566 |
capacity = parse_get_integer_property (); |
| 2567 |
|
| 2568 |
capacity = capacity * V380_OBJ_CAPACITY_MULT + V380_OBJ_DEFAULT_SIZE; |
| 2569 |
|
| 2570 |
vt_value.integer = capacity; |
| 2571 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2572 |
parse_pop_key (); |
| 2573 |
} |
| 2574 |
} |
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
else if (strcmp (fixup, "|V380_OBJECT:_Openable_,Key|") == 0) |
| 2581 |
{ |
| 2582 |
sc_vartype_t vt_key, vt_value; |
| 2583 |
sc_int openable; |
| 2584 |
|
| 2585 |
|
| 2586 |
vt_key.string = "Openable"; |
| 2587 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2588 |
openable = parse_get_integer_property (); |
| 2589 |
|
| 2590 |
if (openable == 5 || openable == 6) |
| 2591 |
{ |
| 2592 |
vt_value.integer = (openable == 5) ? 6 : 5; |
| 2593 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2594 |
} |
| 2595 |
|
| 2596 |
|
| 2597 |
else if (openable == 1) |
| 2598 |
{ |
| 2599 |
vt_value.integer = 0; |
| 2600 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2601 |
} |
| 2602 |
|
| 2603 |
parse_pop_key (); |
| 2604 |
|
| 2605 |
|
| 2606 |
if (openable == 5 || openable == 6) |
| 2607 |
{ |
| 2608 |
vt_key.string = "Key"; |
| 2609 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2610 |
vt_value.integer = -1; |
| 2611 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2612 |
parse_pop_key (); |
| 2613 |
} |
| 2614 |
} |
| 2615 |
|
| 2616 |
|
| 2617 |
else if (strcmp (fixup, "|V380_TASK:_Actions_|") == 0) |
| 2618 |
{ |
| 2619 |
sc_vartype_t vt_key; |
| 2620 |
sc_int score; |
| 2621 |
sc_bool killsplayer, wingame; |
| 2622 |
sc_int movement; |
| 2623 |
|
| 2624 |
|
| 2625 |
vt_key.string = "Score"; |
| 2626 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2627 |
score = parse_get_integer_property (); |
| 2628 |
parse_pop_key (); |
| 2629 |
|
| 2630 |
|
| 2631 |
if (score != 0) |
| 2632 |
parse_fixup_v380_action (4, 1, score, 0, 0); |
| 2633 |
|
| 2634 |
|
| 2635 |
vt_key.string = "KillsPlayer"; |
| 2636 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2637 |
killsplayer = parse_get_boolean_property (); |
| 2638 |
parse_pop_key (); |
| 2639 |
vt_key.string = "WinGame"; |
| 2640 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2641 |
wingame = parse_get_boolean_property (); |
| 2642 |
parse_pop_key (); |
| 2643 |
|
| 2644 |
|
| 2645 |
if (killsplayer) |
| 2646 |
parse_fixup_v380_action (6, 1, 2, 0, 0); |
| 2647 |
if (wingame) |
| 2648 |
parse_fixup_v380_action (6, 1, 0, 0, 0); |
| 2649 |
|
| 2650 |
|
| 2651 |
for (movement = 0; movement < V380_TASK_MOVEMENTS; movement++) |
| 2652 |
{ |
| 2653 |
sc_int mvar1, mvar2, mvar3; |
| 2654 |
|
| 2655 |
vt_key.integer = movement; |
| 2656 |
parse_push_key (vt_key, PROP_KEY_INTEGER); |
| 2657 |
vt_key.string = "Movements"; |
| 2658 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2659 |
|
| 2660 |
|
| 2661 |
vt_key.string = "Var1"; |
| 2662 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2663 |
mvar1 = parse_get_integer_property (); |
| 2664 |
parse_pop_key (); |
| 2665 |
vt_key.string = "Var2"; |
| 2666 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2667 |
mvar2 = parse_get_integer_property (); |
| 2668 |
parse_pop_key (); |
| 2669 |
vt_key.string = "Var3"; |
| 2670 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2671 |
mvar3 = parse_get_integer_property (); |
| 2672 |
parse_pop_key (); |
| 2673 |
|
| 2674 |
parse_pop_key (); |
| 2675 |
parse_pop_key (); |
| 2676 |
|
| 2677 |
|
| 2678 |
parse_fixup_v380_movement (mvar1, mvar2, mvar3); |
| 2679 |
} |
| 2680 |
} |
| 2681 |
|
| 2682 |
|
| 2683 |
else if (strcmp (fixup, "|V380_TASK:_Restrictions_|") == 0) |
| 2684 |
{ |
| 2685 |
sc_vartype_t vt_key, vt_value; |
| 2686 |
sc_bool holding, tasknotdone, notinsameroom; |
| 2687 |
sc_int holdobj1, holdobj2, holdobj3, task; |
| 2688 |
sc_int wearobj1, wearobj2, npc, obj1, obj1room, obj2; |
| 2689 |
const sc_char *holdmsg, *taskmsg, *wearmsg, *companymsg; |
| 2690 |
const sc_char *obj1msg; |
| 2691 |
sc_int restriction_count; |
| 2692 |
|
| 2693 |
|
| 2694 |
vt_key.string = "HoldingSameRoom"; |
| 2695 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2696 |
holding = parse_get_boolean_property (); |
| 2697 |
parse_pop_key (); |
| 2698 |
|
| 2699 |
vt_key.string = "HoldObj1"; |
| 2700 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2701 |
holdobj1 = parse_get_integer_property (); |
| 2702 |
parse_pop_key (); |
| 2703 |
|
| 2704 |
vt_key.string = "HoldObj2"; |
| 2705 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2706 |
holdobj2 = parse_get_integer_property (); |
| 2707 |
parse_pop_key (); |
| 2708 |
|
| 2709 |
vt_key.string = "HoldObj3"; |
| 2710 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2711 |
holdobj3 = parse_get_integer_property (); |
| 2712 |
parse_pop_key (); |
| 2713 |
|
| 2714 |
vt_key.string = "HoldMsg"; |
| 2715 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2716 |
holdmsg = parse_get_string_property (); |
| 2717 |
parse_pop_key (); |
| 2718 |
|
| 2719 |
parse_fixup_v380_obj_restr (holding, holdobj1, holdmsg); |
| 2720 |
parse_fixup_v380_obj_restr (holding, holdobj2, holdmsg); |
| 2721 |
parse_fixup_v380_obj_restr (holding, holdobj3, holdmsg); |
| 2722 |
|
| 2723 |
|
| 2724 |
vt_key.string = "TaskNotDone"; |
| 2725 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2726 |
tasknotdone = parse_get_boolean_property (); |
| 2727 |
parse_pop_key (); |
| 2728 |
|
| 2729 |
vt_key.string = "Task"; |
| 2730 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2731 |
task = parse_get_integer_property (); |
| 2732 |
parse_pop_key (); |
| 2733 |
|
| 2734 |
vt_key.string = "TaskMsg"; |
| 2735 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2736 |
taskmsg = parse_get_string_property (); |
| 2737 |
parse_pop_key (); |
| 2738 |
|
| 2739 |
parse_fixup_v380_task_restr (tasknotdone, task, taskmsg); |
| 2740 |
|
| 2741 |
|
| 2742 |
vt_key.string = "WearObj1"; |
| 2743 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2744 |
wearobj1 = parse_get_integer_property (); |
| 2745 |
parse_pop_key (); |
| 2746 |
|
| 2747 |
vt_key.string = "WearObj2"; |
| 2748 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2749 |
wearobj2 = parse_get_integer_property (); |
| 2750 |
parse_pop_key (); |
| 2751 |
|
| 2752 |
vt_key.string = "WearMsg"; |
| 2753 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2754 |
wearmsg = parse_get_string_property (); |
| 2755 |
parse_pop_key (); |
| 2756 |
|
| 2757 |
parse_fixup_v380_wear_restr (wearobj1, wearmsg); |
| 2758 |
parse_fixup_v380_wear_restr (wearobj2, wearmsg); |
| 2759 |
|
| 2760 |
|
| 2761 |
vt_key.string = "NotInSameRoom"; |
| 2762 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2763 |
notinsameroom = parse_get_boolean_property (); |
| 2764 |
parse_pop_key (); |
| 2765 |
|
| 2766 |
vt_key.string = "NPC"; |
| 2767 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2768 |
npc = parse_get_integer_property (); |
| 2769 |
parse_pop_key (); |
| 2770 |
|
| 2771 |
vt_key.string = "CompanyMsg"; |
| 2772 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2773 |
companymsg = parse_get_string_property (); |
| 2774 |
parse_pop_key (); |
| 2775 |
|
| 2776 |
parse_fixup_v380_npc_restr (notinsameroom, npc, companymsg); |
| 2777 |
|
| 2778 |
|
| 2779 |
vt_key.string = "Obj1"; |
| 2780 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2781 |
obj1 = parse_get_integer_property (); |
| 2782 |
parse_pop_key (); |
| 2783 |
|
| 2784 |
vt_key.string = "Obj1Room"; |
| 2785 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2786 |
obj1room = parse_get_integer_property (); |
| 2787 |
parse_pop_key (); |
| 2788 |
|
| 2789 |
vt_key.string = "Obj1Msg"; |
| 2790 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2791 |
obj1msg = parse_get_string_property (); |
| 2792 |
parse_pop_key (); |
| 2793 |
|
| 2794 |
parse_fixup_v380_objroom_restr (obj1, obj1room, obj1msg); |
| 2795 |
|
| 2796 |
|
| 2797 |
vt_key.string = "Obj2"; |
| 2798 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2799 |
obj2 = parse_get_integer_property (); |
| 2800 |
parse_pop_key (); |
| 2801 |
|
| 2802 |
if (obj2 > 0) |
| 2803 |
{ |
| 2804 |
sc_int var1, var2; |
| 2805 |
const sc_char *obj2msg; |
| 2806 |
|
| 2807 |
vt_key.string = "Obj2Var1"; |
| 2808 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2809 |
var1 = parse_get_integer_property (); |
| 2810 |
parse_pop_key (); |
| 2811 |
|
| 2812 |
vt_key.string = "Obj2Var2"; |
| 2813 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2814 |
var2 = parse_get_integer_property (); |
| 2815 |
parse_pop_key (); |
| 2816 |
|
| 2817 |
vt_key.string = "Obj2Msg"; |
| 2818 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2819 |
obj2msg = parse_get_string_property (); |
| 2820 |
parse_pop_key (); |
| 2821 |
|
| 2822 |
parse_fixup_v380_objstate_restr (obj2, var1, var2, obj2msg); |
| 2823 |
} |
| 2824 |
|
| 2825 |
|
| 2826 |
vt_key.string = "Restrictions"; |
| 2827 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2828 |
restriction_count = parse_get_child_count (); |
| 2829 |
parse_pop_key (); |
| 2830 |
|
| 2831 |
|
| 2832 |
if (restriction_count > 0) |
| 2833 |
{ |
| 2834 |
sc_char *restrmask; |
| 2835 |
sc_int index_; |
| 2836 |
|
| 2837 |
restrmask = sc_malloc (2 * restriction_count); |
| 2838 |
strcpy (restrmask, "#"); |
| 2839 |
for (index_ = 1; index_ < restriction_count; index_++) |
| 2840 |
strcat (restrmask, "A#"); |
| 2841 |
|
| 2842 |
vt_key.string = "RestrMask"; |
| 2843 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2844 |
vt_value.string = restrmask; |
| 2845 |
parse_put_property (vt_value, PROP_STRING); |
| 2846 |
parse_pop_key (); |
| 2847 |
|
| 2848 |
prop_adopt (parse_bundle, restrmask); |
| 2849 |
} |
| 2850 |
} |
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
else if (strcmp (fixup, "|V380_OBJECT:_InitialPositions_|") == 0) |
| 2857 |
{ |
| 2858 |
sc_vartype_t vt_key[3]; |
| 2859 |
sc_int object_count, object, *object_type; |
| 2860 |
|
| 2861 |
|
| 2862 |
vt_key[0].string = "Objects"; |
| 2863 |
object_count = prop_get_child_count (parse_bundle, "I<-s", vt_key); |
| 2864 |
|
| 2865 |
|
| 2866 |
object_type = sc_malloc (object_count * sizeof (*object_type)); |
| 2867 |
for (object = 0; object < object_count; object++) |
| 2868 |
{ |
| 2869 |
vt_key[1].integer = object; |
| 2870 |
vt_key[2].string = "SurfaceContainer"; |
| 2871 |
object_type[object] = prop_get_integer (parse_bundle, |
| 2872 |
"I<-sis", vt_key); |
| 2873 |
} |
| 2874 |
|
| 2875 |
|
| 2876 |
for (object = 0; object < object_count; object++) |
| 2877 |
{ |
| 2878 |
sc_vartype_t vt_value; |
| 2879 |
sc_bool is_static; |
| 2880 |
sc_int initialposition; |
| 2881 |
|
| 2882 |
|
| 2883 |
vt_key[1].integer = object; |
| 2884 |
vt_key[2].string = "Static"; |
| 2885 |
is_static = prop_get_boolean (parse_bundle, "B<-sis", vt_key); |
| 2886 |
if (is_static) |
| 2887 |
continue; |
| 2888 |
|
| 2889 |
|
| 2890 |
vt_key[1].integer = object; |
| 2891 |
vt_key[2].string = "InitialPosition"; |
| 2892 |
initialposition = prop_get_integer (parse_bundle, "I<-sis", vt_key); |
| 2893 |
if (initialposition > 2) |
| 2894 |
{ |
| 2895 |
vt_value.integer = initialposition + 1; |
| 2896 |
prop_put (parse_bundle, "I->sis", vt_value, vt_key); |
| 2897 |
} |
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
if (initialposition == 2) |
| 2905 |
{ |
| 2906 |
sc_int count, parent, index_; |
| 2907 |
|
| 2908 |
|
| 2909 |
vt_key[1].integer = object; |
| 2910 |
vt_key[2].string = "Parent"; |
| 2911 |
count = prop_get_integer (parse_bundle, "I<-sis", vt_key); |
| 2912 |
|
| 2913 |
|
| 2914 |
for (parent = 0; parent < object_count && count >= 0; parent++) |
| 2915 |
{ |
| 2916 |
if (object_type[parent] == V380_OBJ_IS_CONTAINER |
| 2917 |
|| object_type[parent] == V380_OBJ_IS_SURFACE) |
| 2918 |
count--; |
| 2919 |
} |
| 2920 |
parent--; |
| 2921 |
|
| 2922 |
|
| 2923 |
if (object_type[parent] == V380_OBJ_IS_SURFACE) |
| 2924 |
{ |
| 2925 |
vt_key[2].string = "InitialPosition"; |
| 2926 |
vt_value.integer = initialposition + 1; |
| 2927 |
prop_put (parse_bundle, "I->sis", vt_value, vt_key); |
| 2928 |
} |
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
count = 0; |
| 2935 |
for (index_ = 0; index_ < parent; index_++) |
| 2936 |
{ |
| 2937 |
if (object_type[index_] == object_type[parent]) |
| 2938 |
count++; |
| 2939 |
} |
| 2940 |
vt_key[2].string = "Parent"; |
| 2941 |
vt_value.integer = count; |
| 2942 |
prop_put (parse_bundle, "I->sis", vt_value, vt_key); |
| 2943 |
} |
| 2944 |
} |
| 2945 |
|
| 2946 |
|
| 2947 |
sc_free (object_type); |
| 2948 |
} |
| 2949 |
|
| 2950 |
|
| 2951 |
else if (strcmp (fixup, "|V380_MaxSize_MaxWt_|") == 0) |
| 2952 |
{ |
| 2953 |
sc_vartype_t vt_key, vt_value; |
| 2954 |
sc_int maxcarried; |
| 2955 |
|
| 2956 |
vt_key.string = "MaxCarried"; |
| 2957 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2958 |
maxcarried = parse_get_integer_property (); |
| 2959 |
parse_pop_key (); |
| 2960 |
|
| 2961 |
vt_value.integer = maxcarried * V380_OBJ_CAPACITY_MULT |
| 2962 |
+ V380_OBJ_DEFAULT_SIZE; |
| 2963 |
|
| 2964 |
vt_key.string = "MaxSize"; |
| 2965 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2966 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2967 |
parse_pop_key (); |
| 2968 |
|
| 2969 |
vt_key.string = "MaxWt"; |
| 2970 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 2971 |
parse_put_property (vt_value, PROP_INTEGER); |
| 2972 |
parse_pop_key (); |
| 2973 |
} |
| 2974 |
|
| 2975 |
|
| 2976 |
else if (strcmp (fixup, "|V380_GLOBAL:_MaxScore_|") == 0) |
| 2977 |
{ |
| 2978 |
sc_vartype_t vt_key[3], vt_value; |
| 2979 |
sc_int task_count, maxscore, task; |
| 2980 |
|
| 2981 |
|
| 2982 |
vt_key[0].string = "Tasks"; |
| 2983 |
task_count = prop_get_child_count (parse_bundle, "I<-s", vt_key); |
| 2984 |
|
| 2985 |
|
| 2986 |
maxscore = 0; |
| 2987 |
for (task = 0; task < task_count; task++) |
| 2988 |
{ |
| 2989 |
sc_int score; |
| 2990 |
|
| 2991 |
vt_key[1].integer = task; |
| 2992 |
vt_key[2].string = "Score"; |
| 2993 |
score = prop_get_integer (parse_bundle, "I<-sis", vt_key); |
| 2994 |
if (score > 0) |
| 2995 |
maxscore += score; |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
vt_key[0].string = "Globals"; |
| 3000 |
vt_key[1].string = "MaxScore"; |
| 3001 |
vt_value.integer = maxscore; |
| 3002 |
prop_put (parse_bundle, "I->ss", vt_value, vt_key); |
| 3003 |
} |
| 3004 |
|
| 3005 |
|
| 3006 |
else if (strcmp (fixup, "|V380_WALK:_MeetObject_|") == 0) |
| 3007 |
{ |
| 3008 |
sc_vartype_t vt_key, vt_value, vt_gkey[3]; |
| 3009 |
sc_int meetobject, count, object_count, object; |
| 3010 |
|
| 3011 |
vt_key.string = "MeetObject"; |
| 3012 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 3013 |
meetobject = parse_get_integer_property (); |
| 3014 |
|
| 3015 |
|
| 3016 |
vt_gkey[0].string = "Objects"; |
| 3017 |
object_count = prop_get_child_count (parse_bundle, "I<-s", vt_gkey); |
| 3018 |
|
| 3019 |
|
| 3020 |
count = meetobject - 1; |
| 3021 |
for (object = 0; object < object_count && count >= 0; object++) |
| 3022 |
{ |
| 3023 |
sc_bool bstatic; |
| 3024 |
|
| 3025 |
vt_gkey[1].integer = object; |
| 3026 |
vt_gkey[2].string = "Static"; |
| 3027 |
bstatic = prop_get_boolean (parse_bundle, "B<-sis", vt_gkey); |
| 3028 |
if (!bstatic) |
| 3029 |
count--; |
| 3030 |
} |
| 3031 |
object--; |
| 3032 |
|
| 3033 |
vt_value.integer = object; |
| 3034 |
parse_put_property (vt_value, PROP_INTEGER); |
| 3035 |
parse_pop_key (); |
| 3036 |
} |
| 3037 |
|
| 3038 |
|
| 3039 |
else if (strcmp (fixup, "|V380_ROOM:_Alts_|") == 0) |
| 3040 |
{ |
| 3041 |
parse_fixup_v390_v380_room_alts (); |
| 3042 |
} |
| 3043 |
|
| 3044 |
|
| 3045 |
else |
| 3046 |
{ |
| 3047 |
sc_fatal ("parse_fixup_v380: no handler for \"%s\"\n", fixup); |
| 3048 |
} |
| 3049 |
|
| 3050 |
if (parse_trace) |
| 3051 |
sc_trace ("Parse: leaving version 3.8 fixup %s\n", fixup); |
| 3052 |
} |
| 3053 |
|
| 3054 |
|
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
|
| 3061 |
static void |
| 3062 |
parse_fixup (const sc_char *fixup) |
| 3063 |
{ |
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
switch (taf_get_version (parse_taf)) |
| 3069 |
{ |
| 3070 |
case TAF_VERSION_400: |
| 3071 |
sc_fatal ("parse_fixup: unexpected call\n"); |
| 3072 |
break; |
| 3073 |
case TAF_VERSION_390: |
| 3074 |
parse_fixup_v390 (fixup); |
| 3075 |
break; |
| 3076 |
case TAF_VERSION_380: |
| 3077 |
parse_fixup_v380 (fixup); |
| 3078 |
break; |
| 3079 |
default: |
| 3080 |
sc_fatal ("parse_fixup: invalid TAF file version\n"); |
| 3081 |
break; |
| 3082 |
} |
| 3083 |
} |
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
static void |
| 3092 |
parse_element (const sc_char *element) |
| 3093 |
{ |
| 3094 |
if (parse_trace) |
| 3095 |
sc_trace ("Parse: entering element %s\n", element); |
| 3096 |
|
| 3097 |
|
| 3098 |
switch (element[0]) |
| 3099 |
{ |
| 3100 |
case PARSE_ARRAY: |
| 3101 |
parse_array (element); |
| 3102 |
break; |
| 3103 |
case PARSE_VECTOR: |
| 3104 |
parse_vector (element); |
| 3105 |
break; |
| 3106 |
case PARSE_VECTOR_ALTERNATE: |
| 3107 |
parse_vector_alternate (element); |
| 3108 |
break; |
| 3109 |
case PARSE_CLASS: |
| 3110 |
parse_class (element); |
| 3111 |
break; |
| 3112 |
case PARSE_EXPRESSION: |
| 3113 |
parse_expression (element); |
| 3114 |
break; |
| 3115 |
case PARSE_SPECIAL: |
| 3116 |
parse_special (element); |
| 3117 |
break; |
| 3118 |
case PARSE_FIXUP: |
| 3119 |
parse_fixup (element); |
| 3120 |
break; |
| 3121 |
|
| 3122 |
case PARSE_INTEGER: |
| 3123 |
case PARSE_DEFAULT_ZERO: |
| 3124 |
case PARSE_BOOLEAN: |
| 3125 |
case PARSE_DEFAULT_TRUE: |
| 3126 |
case PARSE_DEFAULT_FALSE: |
| 3127 |
case PARSE_STRING: |
| 3128 |
case PARSE_DEFAULT_EMPTY: |
| 3129 |
case PARSE_IGNORE_INTEGER: |
| 3130 |
case PARSE_IGNORE_BOOLEAN: |
| 3131 |
case PARSE_IGNORE_STRING: |
| 3132 |
case PARSE_MULTILINE: |
| 3133 |
parse_terminal (element); |
| 3134 |
break; |
| 3135 |
default: |
| 3136 |
sc_fatal ("parse_element: bad type, %c\n", element[0]); |
| 3137 |
} |
| 3138 |
|
| 3139 |
if (parse_trace) |
| 3140 |
sc_trace ("Parse: leaving element %s\n", element); |
| 3141 |
} |
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
|
| 3148 |
|
| 3149 |
static void |
| 3150 |
parse_descriptor (const sc_char *descriptor) |
| 3151 |
{ |
| 3152 |
sc_int next; |
| 3153 |
|
| 3154 |
|
| 3155 |
for (next = 0; descriptor[next] != NUL; ) |
| 3156 |
{ |
| 3157 |
sc_char element[PARSE_TEMP_LENGTH]; |
| 3158 |
|
| 3159 |
|
| 3160 |
if (sscanf (descriptor + next, "%[^ ]", element) != 1) |
| 3161 |
sc_fatal ("parse_element: no element, %s\n", descriptor + next); |
| 3162 |
|
| 3163 |
|
| 3164 |
parse_element (element); |
| 3165 |
|
| 3166 |
|
| 3167 |
next += strlen (element); |
| 3168 |
next += strspn (descriptor + next, " "); |
| 3169 |
} |
| 3170 |
} |
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
static void |
| 3179 |
parse_class (const sc_char *class_) |
| 3180 |
{ |
| 3181 |
sc_char class_name[PARSE_TEMP_LENGTH]; |
| 3182 |
sc_int index_; |
| 3183 |
sc_vartype_t vt_key; |
| 3184 |
|
| 3185 |
|
| 3186 |
if (sscanf (class_, "<%[^>]", class_name) != 1) |
| 3187 |
sc_fatal ("parse_class: error in class, %s\n", class_); |
| 3188 |
if (parse_trace) |
| 3189 |
sc_trace ("Parse: entering class %s\n", class_name); |
| 3190 |
|
| 3191 |
|
| 3192 |
for (index_ = 0; parse_schema[index_].class_name; index_++) |
| 3193 |
{ |
| 3194 |
if (strcmp (parse_schema[index_].class_name, class_name) == 0) |
| 3195 |
break; |
| 3196 |
} |
| 3197 |
if (!parse_schema[index_].class_name) |
| 3198 |
sc_fatal ("parse_class: class not described, %s\n", class_name); |
| 3199 |
|
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
if (index_ > 0) |
| 3206 |
{ |
| 3207 |
vt_key.string = class_ + strlen (class_name) + 2; |
| 3208 |
parse_push_key (vt_key, PROP_KEY_STRING); |
| 3209 |
} |
| 3210 |
|
| 3211 |
|
| 3212 |
parse_descriptor (parse_schema[index_].descriptor); |
| 3213 |
|
| 3214 |
|
| 3215 |
if (index_ > 0) |
| 3216 |
parse_pop_key (); |
| 3217 |
|
| 3218 |
if (parse_trace) |
| 3219 |
sc_trace ("Parse: leaving class %s\n", class_name); |
| 3220 |
} |
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
static void |
| 3230 |
parse_add_walkalerts (sc_prop_setref_t bundle) |
| 3231 |
{ |
| 3232 |
sc_vartype_t vt_key[5]; |
| 3233 |
sc_int npcs_count, npc; |
| 3234 |
|
| 3235 |
|
| 3236 |
vt_key[0].string = "NPCs"; |
| 3237 |
npcs_count = prop_get_child_count (bundle, "I<-s", vt_key); |
| 3238 |
|
| 3239 |
|
| 3240 |
for (npc = 0; npc < npcs_count; npc++) |
| 3241 |
{ |
| 3242 |
sc_int walk_count, walk; |
| 3243 |
|
| 3244 |
|
| 3245 |
vt_key[1].integer = npc; |
| 3246 |
vt_key[2].string = "Walks"; |
| 3247 |
walk_count = prop_get_child_count (bundle, "I<-sis", vt_key); |
| 3248 |
|
| 3249 |
for (walk = 0; walk < walk_count; walk++) |
| 3250 |
{ |
| 3251 |
sc_int starttask; |
| 3252 |
|
| 3253 |
|
| 3254 |
vt_key[3].integer = walk; |
| 3255 |
vt_key[4].string = "StartTask"; |
| 3256 |
starttask = prop_get_integer (bundle, "I<-sisis", vt_key) - 1; |
| 3257 |
if (starttask >= 0) |
| 3258 |
{ |
| 3259 |
sc_vartype_t vt_key2[4], vt_value; |
| 3260 |
sc_int count; |
| 3261 |
|
| 3262 |
|
| 3263 |
vt_key2[0].string = "Tasks"; |
| 3264 |
vt_key2[1].integer = starttask; |
| 3265 |
vt_key2[2].string = "NPCWalkAlert"; |
| 3266 |
count = prop_get_child_count (bundle, "I<-sis", vt_key2); |
| 3267 |
|
| 3268 |
|
| 3269 |
vt_key2[3].integer = count; |
| 3270 |
vt_value.integer = npc; |
| 3271 |
prop_put (bundle, "I->sisi", vt_value, vt_key2); |
| 3272 |
vt_key2[3].integer = count + 1; |
| 3273 |
vt_value.integer = walk; |
| 3274 |
prop_put (bundle, "I->sisi", vt_value, vt_key2); |
| 3275 |
} |
| 3276 |
} |
| 3277 |
} |
| 3278 |
} |
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
static void |
| 3288 |
parse_add_movetimes (sc_prop_setref_t bundle) |
| 3289 |
{ |
| 3290 |
sc_vartype_t vt_key[6]; |
| 3291 |
sc_int npcs_count, npc; |
| 3292 |
|
| 3293 |
|
| 3294 |
vt_key[0].string = "NPCs"; |
| 3295 |
npcs_count = prop_get_child_count (bundle, "I<-s", vt_key); |
| 3296 |
|
| 3297 |
|
| 3298 |
for (npc = 0; npc < npcs_count; npc++) |
| 3299 |
{ |
| 3300 |
sc_int walk_count, walk; |
| 3301 |
|
| 3302 |
|
| 3303 |
vt_key[1].integer = npc; |
| 3304 |
vt_key[2].string = "Walks"; |
| 3305 |
walk_count = prop_get_child_count (bundle, "I<-sis", vt_key); |
| 3306 |
|
| 3307 |
for (walk = 0; walk < walk_count; walk++) |
| 3308 |
{ |
| 3309 |
sc_int waittimes; |
| 3310 |
sc_int *movetimes, index_; |
| 3311 |
sc_vartype_t vt_value; |
| 3312 |
|
| 3313 |
vt_key[3].integer = walk; |
| 3314 |
vt_key[4].string = "Times"; |
| 3315 |
waittimes = prop_get_child_count (bundle, "I<-sisis", vt_key); |
| 3316 |
|
| 3317 |
movetimes = sc_malloc ((waittimes + 1) * sizeof (*movetimes)); |
| 3318 |
memset (movetimes, 0, (waittimes + 1) * sizeof (*movetimes)); |
| 3319 |
for (index_ = waittimes - 1; index_ >= 0; index_--) |
| 3320 |
{ |
| 3321 |
vt_key[4].string = "Times"; |
| 3322 |
vt_key[5].integer = index_; |
| 3323 |
movetimes[index_] = prop_get_integer (bundle, "I<-sisisi", vt_key) |
| 3324 |
+ movetimes[index_ + 1]; |
| 3325 |
} |
| 3326 |
movetimes[waittimes] = -2; |
| 3327 |
|
| 3328 |
for (index_ = 0; index_ <= waittimes; index_++) |
| 3329 |
{ |
| 3330 |
vt_key[4].string = "MoveTimes"; |
| 3331 |
vt_key[5].integer = index_; |
| 3332 |
vt_value.integer = movetimes[index_]; |
| 3333 |
prop_put (bundle, "I->sisisi", vt_value, vt_key); |
| 3334 |
} |
| 3335 |
sc_free (movetimes); |
| 3336 |
} |
| 3337 |
} |
| 3338 |
} |
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
static void |
| 3348 |
parse_add_alrs_index (sc_prop_setref_t bundle) |
| 3349 |
{ |
| 3350 |
sc_vartype_t vt_key[3]; |
| 3351 |
sc_int alr_count, index_, alr; |
| 3352 |
sc_int *alr_lengths, longest, shortest, length; |
| 3353 |
|
| 3354 |
|
| 3355 |
vt_key[0].string = "ALRs"; |
| 3356 |
alr_count = prop_get_child_count (bundle, "I<-s", vt_key); |
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
alr_lengths = sc_malloc (alr_count * sizeof (*alr_lengths)); |
| 3363 |
shortest = INT_MAX; |
| 3364 |
longest = 0; |
| 3365 |
for (index_ = 0; index_ < alr_count; index_++) |
| 3366 |
{ |
| 3367 |
const sc_char *original; |
| 3368 |
|
| 3369 |
vt_key[1].integer = index_; |
| 3370 |
vt_key[2].string = "Original"; |
| 3371 |
original = prop_get_string (bundle, "S<-sis", vt_key); |
| 3372 |
length = strlen (original); |
| 3373 |
|
| 3374 |
alr_lengths[index_] = length; |
| 3375 |
shortest = (length < shortest) ? length : shortest; |
| 3376 |
longest = (length > longest) ? length : longest; |
| 3377 |
} |
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
|
| 3385 |
vt_key[0].string = "ALRs2"; |
| 3386 |
alr = 0; |
| 3387 |
for (length = longest; length >= shortest; length--) |
| 3388 |
{ |
| 3389 |
|
| 3390 |
for (index_ = 0; index_ < alr_count; index_++) |
| 3391 |
{ |
| 3392 |
if (alr_lengths[index_] == length) |
| 3393 |
{ |
| 3394 |
sc_vartype_t vt_value; |
| 3395 |
|
| 3396 |
vt_key[1].integer = alr++; |
| 3397 |
vt_key[2].string = "ALRIndex"; |
| 3398 |
vt_value.integer = index_; |
| 3399 |
prop_put (bundle, "I->sis", vt_value, vt_key); |
| 3400 |
} |
| 3401 |
} |
| 3402 |
} |
| 3403 |
assert (alr == alr_count); |
| 3404 |
|
| 3405 |
|
| 3406 |
sc_free (alr_lengths); |
| 3407 |
} |
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
static void |
| 3418 |
parse_add_resources_offset (sc_prop_setref_t bundle, sc_tafref_t taf) |
| 3419 |
{ |
| 3420 |
sc_vartype_t vt_key[2], vt_value; |
| 3421 |
sc_bool embedded; |
| 3422 |
sc_int offset; |
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
vt_key[0].string = "Globals"; |
| 3429 |
vt_key[1].string = "Embedded"; |
| 3430 |
embedded = prop_get_boolean (bundle, "B<-ss", vt_key); |
| 3431 |
offset = embedded ? taf_get_game_data_length (taf) + 1 : 0; |
| 3432 |
|
| 3433 |
|
| 3434 |
vt_key[0].string = "ResourceOffset"; |
| 3435 |
vt_value.integer = offset; |
| 3436 |
prop_put (bundle, "I->s", vt_value, vt_key); |
| 3437 |
} |
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
static void |
| 3447 |
parse_add_version (sc_prop_setref_t bundle, sc_tafref_t taf) |
| 3448 |
{ |
| 3449 |
sc_vartype_t vt_key, vt_value; |
| 3450 |
|
| 3451 |
|
| 3452 |
vt_key.string = "Version"; |
| 3453 |
vt_value.integer = taf_get_version (taf); |
| 3454 |
prop_put (bundle, "I->s", vt_value, &vt_key); |
| 3455 |
|
| 3456 |
|
| 3457 |
switch (taf_get_version (taf)) |
| 3458 |
{ |
| 3459 |
case TAF_VERSION_400: |
| 3460 |
vt_value.string = "4.00"; |
| 3461 |
break; |
| 3462 |
case TAF_VERSION_390: |
| 3463 |
vt_value.string = "3.90"; |
| 3464 |
break; |
| 3465 |
case TAF_VERSION_380: |
| 3466 |
vt_value.string = "3.80"; |
| 3467 |
break; |
| 3468 |
default: |
| 3469 |
sc_error ("parse_add_version_string: invalid TAF file version\n"); |
| 3470 |
vt_value.string = "[Unknown version]"; |
| 3471 |
break; |
| 3472 |
} |
| 3473 |
vt_key.string = "VersionString"; |
| 3474 |
prop_put (bundle, "S->s", vt_value, &vt_key); |
| 3475 |
} |
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
|
| 3484 |
sc_bool |
| 3485 |
parse_game (sc_tafref_t taf, sc_prop_setref_t bundle) |
| 3486 |
{ |
| 3487 |
assert (taf && bundle); |
| 3488 |
|
| 3489 |
|
| 3490 |
parse_taf = taf; |
| 3491 |
parse_bundle = bundle; |
| 3492 |
parse_schema = parse_select_schema (parse_taf); |
| 3493 |
parse_depth = 0; |
| 3494 |
|
| 3495 |
|
| 3496 |
if (setjmp (parse_taf_error) == 0) |
| 3497 |
{ |
| 3498 |
|
| 3499 |
taf_first_line (parse_taf); |
| 3500 |
parse_tafline = 0; |
| 3501 |
parse_class ("<_GAME_>"); |
| 3502 |
} |
| 3503 |
else |
| 3504 |
{ |
| 3505 |
|
| 3506 |
parse_clear_v400_resources_table (); |
| 3507 |
parse_taf = NULL; |
| 3508 |
parse_bundle = NULL; |
| 3509 |
parse_schema = NULL; |
| 3510 |
parse_depth = 0; |
| 3511 |
return FALSE; |
| 3512 |
} |
| 3513 |
|
| 3514 |
|
| 3515 |
parse_clear_v400_resources_table (); |
| 3516 |
|
| 3517 |
|
| 3518 |
if (taf_more_lines (parse_taf)) |
| 3519 |
sc_error ("parse_game: unexpected trailing data\n"); |
| 3520 |
|
| 3521 |
|
| 3522 |
parse_add_walkalerts (parse_bundle); |
| 3523 |
parse_add_movetimes (parse_bundle); |
| 3524 |
|
| 3525 |
|
| 3526 |
parse_add_alrs_index (parse_bundle); |
| 3527 |
parse_add_resources_offset (parse_bundle, parse_taf); |
| 3528 |
|
| 3529 |
|
| 3530 |
parse_add_version (parse_bundle, parse_taf); |
| 3531 |
|
| 3532 |
|
| 3533 |
prop_solidify (parse_bundle); |
| 3534 |
|
| 3535 |
|
| 3536 |
parse_taf = NULL; |
| 3537 |
parse_bundle = NULL; |
| 3538 |
parse_schema = NULL; |
| 3539 |
parse_depth = 0; |
| 3540 |
return TRUE; |
| 3541 |
} |
| 3542 |
|
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
void |
| 3550 |
parse_debug_trace (sc_bool flag) |
| 3551 |
{ |
| 3552 |
parse_trace = flag; |
| 3553 |
} |