| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "agility.h" |
| 16 |
#include <ctype.h> |
| 17 |
#include <assert.h> |
| 18 |
#include <stddef.h> |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
const char trans_ibm[]= |
| 34 |
"CueaaaaceeeiiiAA" |
| 35 |
"E@@ooouuyOUc$$pf" |
| 36 |
"aiounNao?....!<>" |
| 37 |
"###|++|+++|\\/++\\" |
| 38 |
"\\+++-+||\\/+++=+=" |
| 39 |
"+=+++++++//@@@@@" |
| 40 |
"abGpSsmtFTOd.fe^" |
| 41 |
"=+><fj/=***/n2# "; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#define rnc(p) {#p,offsetof(room_rec,p),offsetof(noun_rec,p), \ |
| 49 |
offsetof(creat_rec,p)} |
| 50 |
#define rn(p) {#p,offsetof(room_rec,p),offsetof(noun_rec,p),-1} |
| 51 |
#define nc(p) {#p,-1,offsetof(noun_rec,p),offsetof(creat_rec,p)} |
| 52 |
#define rc(p) {#p,offsetof(room_rec,p),-1,offsetof(creat_rec,p)} |
| 53 |
#define r(p) {#p, offsetof(room_rec,p), -1, -1} |
| 54 |
#define n(p) {#p, -1, offsetof(noun_rec,p),-1} |
| 55 |
#define c(p) {#p, -1, -1, offsetof(creat_rec,p)} |
| 56 |
|
| 57 |
const prop_struct proplist[NUM_PROP]={ |
| 58 |
|
| 59 |
rnc(oclass),rnc(points),r(light), |
| 60 |
n(num_shots),n(weight),n(size), |
| 61 |
c(counter),c(timecounter), |
| 62 |
|
| 63 |
nc(location),rn(key),c(weapon),c(threshold),c(timethresh), |
| 64 |
nc(flagnum) |
| 65 |
}; |
| 66 |
|
| 67 |
const prop_struct attrlist[NUM_ATTR]={ |
| 68 |
|
| 69 |
n(on),n(open),n(locked),n(movable), |
| 70 |
c(groupmemb), c(hostile), |
| 71 |
|
| 72 |
r(end),rn(win),r(killplayer),n(plural), |
| 73 |
n(pushable),n(pullable),n(turnable),n(playable),n(readable),n(closable), |
| 74 |
n(lockable),n(edible),n(wearable),n(drinkable),n(poisonous),n(light), |
| 75 |
n(shootable),nc(isglobal), |
| 76 |
|
| 77 |
rnc(seen), |
| 78 |
nc(proper) |
| 79 |
}; |
| 80 |
|
| 81 |
#undef rnc |
| 82 |
#undef rn |
| 83 |
#undef rc |
| 84 |
#undef cn |
| 85 |
#undef r |
| 86 |
#undef c |
| 87 |
#undef n |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
#define n AGT_NUM |
| 101 |
#define v AGT_VAR |
| 102 |
#define r AGT_ROOM |
| 103 |
#define i AGT_ITEM |
| 104 |
|
| 105 |
#define o (AGT_ITEM|AGT_CREAT) |
| 106 |
#define l (r|o|AGT_NONE|AGT_SELF|AGT_WORN) |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
#ifdef LOWMEM |
| 112 |
#define a(s) {"",0,0,0} |
| 113 |
#define b(s,a1) {"",1,(a1),0} |
| 114 |
#define c(s,a1,a2) {"",2,(a1),(a2)} |
| 115 |
#else |
| 116 |
#define a(s) {#s,0,0,0} |
| 117 |
#define b(s,a1) {#s,1,(a1),0} |
| 118 |
#define c(s,a1,a2) {#s,2,(a1),(a2)} |
| 119 |
#endif |
| 120 |
|
| 121 |
const opdef cond_def[]= |
| 122 |
{ |
| 123 |
b(AtLocation,r),b(AtLocationGT,n), b(AtLocationLT,n), |
| 124 |
a(SongPlaying),a(SoundIsOn),a(DirectionOK),b(DirectionIs,AGT_DIR), |
| 125 |
c(BetweenRooms,n,n),b(HasVisitedRoom,r), |
| 126 |
a(EnteredObject),b(TimeGT,n),b(TimeLT,n), |
| 127 |
a(FirstVisitToRoom), |
| 128 |
a(NewLife), |
| 129 |
a(IsCarryingSomething),a(IsCarryingNothing), |
| 130 |
a(IsWearingSomething), |
| 131 |
b(IsCarryingTreasure,n), |
| 132 |
a(IsWearingNothing), |
| 133 |
b(LoadWeightEquals,n),b(LoadWeightGT,n),b(LoadWeightLT,n), |
| 134 |
b(Present,o),b(IsWearing,o),b(IsCarrying,o), |
| 135 |
b(IsNowhere,o),b(IsSomewhere,o), |
| 136 |
b(InRoom,o),c(IsLocated,o,l),c(Together,o,o), |
| 137 |
b(IsON,o),b(IsOFF,o), |
| 138 |
b(IsGroupMember,AGT_CREAT), |
| 139 |
b(IsOpen,o),b(IsClosed,o),b(IsLocked,o),b(IsUnLocked,o), |
| 140 |
b(IsEdible,o),b(IsDrinkable,o),b(IsPoisonous,o), |
| 141 |
b(IsMovable,o), |
| 142 |
a(NOUNPresent),a(NOUNIsWearing),a(NOUNIsCarrying), |
| 143 |
a(NOUNIsNowhere),a(NOUNIsSomewhere), |
| 144 |
a(NOUNInRoom),b(NOUNIsLocated,l), |
| 145 |
a(NOUNIsOn),a(NOUNIsOff), |
| 146 |
a(NOUNIsOpen),a(NOUNIsClosed),a(NOUNIsLocked),a(NOUNIsUnLocked), |
| 147 |
a(NOUNIsEdible),a(NOUNIsDrinkable),a(NOUNIsPoisonous), |
| 148 |
a(NOUNIsMovable), |
| 149 |
b(NOUNpointsEquals,n),b(NOUNpointsGT,n),b(NOUNpointsLT,n), |
| 150 |
b(NOUNweightEquals,n),b(NOUNweightGT,n),b(NOUNweightLT,n), |
| 151 |
a(LightPresent),a(RoomNeedsLight), |
| 152 |
b(FlagON,AGT_FLAG),b(FlagOFF,AGT_FLAG), |
| 153 |
b(RoomFlagOn,AGT_ROOMFLAG),b(Room_PixHere,AGT_PIX), |
| 154 |
b(RoomFlagOff,AGT_ROOMFLAG), |
| 155 |
b(ScoreEquals,n),b(ScoreGT,n),b(ScoreLT,n), |
| 156 |
b(NumberEquals,n),b(NumberGT,n),b(NumberLT,n), |
| 157 |
a(AnswerIsCorrect),a(AnswerIsWrong), |
| 158 |
b(TurnsEquals,n),b(TurnsGT,n),b(TurnsLT,n), |
| 159 |
c(CounterEquals,AGT_CNT,n),c(CounterGT,AGT_CNT,n),c(CounterLT,AGT_CNT,n), |
| 160 |
c(VariableEquals,v|n,n),c(VariableGT,v|n,n),c(VariableLT,v|n,n), |
| 161 |
c(CompareVariables,v,v),c(VariableChance,v|n,n), |
| 162 |
a(NamePresent),b(NameIsNumber,o|AGT_NONE), |
| 163 |
b(NOUNIsNumber,o|AGT_NONE),b(ObjectIsNumber,o|AGT_NONE), |
| 164 |
b(SomethingInside,r|o|AGT_SELF), |
| 165 |
b(Chance,n), |
| 166 |
a(PromptForYES),a(PromptForNO), |
| 167 |
a(VerbIsDirection), |
| 168 |
a(NOUNIsCreature), |
| 169 |
a(NOUNIsMan),a(NOUNIsWoman),a(NOUNIsThing), |
| 170 |
a(OBJECTIsMan),a(OBJECTIsWoman),a(OBJECTIsThing), |
| 171 |
a(ObjectIsCreature), |
| 172 |
a(ObjectPresent), |
| 173 |
a(NOT),a(OR), |
| 174 |
a(BeforeCommand),a(AfterCommand), |
| 175 |
b(HourEquals,n),b(HourGT,n),b(HourLT,n), |
| 176 |
b(MinuteEq,n),b(MinuteGT,n),b(MinuteLT,n), |
| 177 |
a(IsAM), |
| 178 |
|
| 179 |
a(OnDisambig), |
| 180 |
b(IsHostile,o), a(HostilePresent), |
| 181 |
a(NameWasPresent), a(OncePerTurn), |
| 182 |
c(IsClass,r|o,AGT_NONE|r|o), |
| 183 |
c(AttrOn,r|o,AGT_ATTR), |
| 184 |
a(NumericNOUN),a(NumericOBJECT), |
| 185 |
c(Equal,n,n),c(GT,n,n),c(LT,n,n),c(GE,n,n),c(LE,n,n), |
| 186 |
c(CaseCompareStrings,AGT_STR,AGT_STR), c(CaseStringBefore,AGT_STR,AGT_STR), |
| 187 |
c(CaseStringAfter,AGT_STR,AGT_STR), |
| 188 |
c(CompareStrings,AGT_STR,AGT_STR), c(StringBefore,AGT_STR,AGT_STR), |
| 189 |
c(StringAfter,AGT_STR,AGT_STR), |
| 190 |
c(StringIsAnswer,AGT_STR,AGT_QUEST), |
| 191 |
b(HasSeen,r|o), |
| 192 |
c(ObjFlagON,r|o,AGT_OBJFLAG), |
| 193 |
c(ObjFlagOFF,r|o,AGT_OBJFLAG), |
| 194 |
c(CanGo,r|o|AGT_SELF,AGT_DIR) |
| 195 |
}; |
| 196 |
|
| 197 |
|
| 198 |
const opdef act_def[]= |
| 199 |
{ |
| 200 |
b(GoToRoom,r),c(GoToRandomRoom,r,r), |
| 201 |
b(MakeVarRoomNum,v),b(MakeVarNounNum,v),b(MakeVarObjectNum,v), |
| 202 |
b(GoToVariableRoom,v|r),c(SendToVariableRoom,o,v|l), |
| 203 |
b(GetVariableIt,v|o),b(PrintVariableMessage,v|AGT_MSG), |
| 204 |
b(GetIt,o),b(WearIt,o),b(DropIt,o),b(RemoveIt,o), |
| 205 |
b(LoadFont,AGT_FONT),b(ShowPicture,AGT_PIC),c(ChangePicture,AGT_PIC,AGT_PIC), |
| 206 |
b(IfYShowPicture,AGT_PIC), |
| 207 |
b(ShowRoom_Pix,AGT_PIX),b(IfYShowRoom_Pix,AGT_PIX), |
| 208 |
b(PlaySong,AGT_SONG),c(PlayRandom,n,n),b(RepeatSong,AGT_SONG), |
| 209 |
a(EndRepeatSong),a(StopSong),a(SuspendSong),a(ResumeSong), |
| 210 |
b(ToggleMovable,i),c(ChangeDescr,r|o,AGT_MSG),c(ChangePoints,r|o,n), |
| 211 |
a(DestroyOBJECT),b(GetString,AGT_STR), |
| 212 |
b(GetVariable,v),b(SetVariableToTime,v),b(SetTimeToVariable,v|n), |
| 213 |
b(SetTime,n),b(AddToTime,n),b(SetDeltaTime,n), |
| 214 |
b(DoSubroutine,AGT_SUB),a(Return), |
| 215 |
a(GetNOUN),a(WearNOUN),a(DropNOUN),a(RemoveNOUN), |
| 216 |
a(DropEverything),a(RemoveEverything),a(KillPlayer), |
| 217 |
b(PutInCurrentRoom,o),c(SendToRoom,o,l), |
| 218 |
c(RePosition,o,l), |
| 219 |
a(PutNOUNInCurrentRoom),b(SendNOUNToRoom,l), |
| 220 |
b(SendAllToRoom,l),c(SendTreasuresToRoom,l,n), |
| 221 |
c(RelocateAll,l,l), |
| 222 |
b(Destroy,o),a(DestroyNOUN), |
| 223 |
c(SwapLocations,o,o),c(SendToItem,o,o),b(SendNOUNtoItem,o), |
| 224 |
b(AddToGroup,AGT_CREAT),b(RemoveFromGroup,AGT_CREAT),b(MoveTheGroup,l), |
| 225 |
a(RedirectTo), |
| 226 |
c(RandomMessage,AGT_MSG,AGT_MSG), b(ShowContents,r|o|AGT_SELF|AGT_WORN), |
| 227 |
b(OpenIt,i),b(CloseIt,i),b(LockIt,i),b(UnlockIt,i), |
| 228 |
a(OpenNOUN),a(CloseNOUN),a(LockNOUN),a(UnlockNOUN), |
| 229 |
a(ShowScore),b(PlusScore,n),b(MinusScore,n), |
| 230 |
a(ShowInventory),a(WaitForReturn),a(TimePasses), |
| 231 |
b(Delay,n), |
| 232 |
a(ClearScreen), |
| 233 |
b(DescribeThing,r|o),a(LookAtRoom), |
| 234 |
b(PrintMessage,AGT_MSG),a(BlankLine),c(Tone,n,n), |
| 235 |
c(GetNumberInput,n,n),b(AskQuestion,AGT_QUEST), |
| 236 |
c(ChangePassageway,AGT_DIR,AGT_EXIT), |
| 237 |
b(TurnFlagOn,AGT_FLAG),b(TurnFlagOff,AGT_FLAG),b(ToggleFlag,AGT_FLAG), |
| 238 |
b(TurnRoomFlagOn,AGT_ROOMFLAG),b(TurnRoomFlagOff,AGT_ROOMFLAG), |
| 239 |
b(ToggleRoomFlag,AGT_ROOMFLAG), |
| 240 |
b(TurnCounterOn,AGT_CNT),b(TurnCounterOff,AGT_CNT), |
| 241 |
c(SetVariableTo,v,n),c(AddToVariable,v|n,n),c(SubtractFromVariable,v|n,n), |
| 242 |
c(AddVariables,v,v),c(SubtractVariables,v,v), |
| 243 |
c(RandomVariable,v,n), |
| 244 |
b(NounToVariable,v),b(ObjectToVariable,v), |
| 245 |
b(Quote,AGT_MSG), |
| 246 |
b(TimePlus,n),b(TimeMinus,n),b(SetHour,n),b(SetMinute,n), |
| 247 |
b(TimePlusVariable,v|n),b(TimeMinusVariable,v|n), |
| 248 |
b(SetHourToVariable,v|n),b(SetMinutesToVariable,v|n), |
| 249 |
|
| 250 |
b(SubtractFromTime,n), b(SetDisambigPriority,n), |
| 251 |
b(SetVariableToDeltaTime,v),b(ChangeStatus,n), |
| 252 |
c(MultiplyVariable,v|n,n),c(DivideVariable,v|n,n), |
| 253 |
c(ComputeRemainder,v|n,n), |
| 254 |
a(WaitForKey), |
| 255 |
b(SetHE,o),b(SetSHE,o),b(SetIT,o),b(SetTHEY,o), |
| 256 |
b(PrintMessageNoNL,AGT_MSG), |
| 257 |
b(StandardMessage,AGT_ERR), |
| 258 |
b(FailMessage,AGT_MSG), b(FailStdMessage,AGT_ERR), |
| 259 |
c(ErrMessage,n,AGT_MSG), c(ErrStdMessage,n,AGT_ERR), |
| 260 |
a(AND), |
| 261 |
c(SetClass,r|o,AGT_NONE|r|o), |
| 262 |
c(SetVariableToClass,v,r|o), |
| 263 |
b(PushStack,n), b(PopStack,v), |
| 264 |
a(AddStack),a(SubStack),a(MultStack),a(DivStack),a(ModStack), |
| 265 |
a(DupStack),a(DiscardStack), |
| 266 |
b(SetVariableToInput,v), |
| 267 |
c(TurnAttrOn,r|o,AGT_ATTR), c(TurnAttrOff,r|o,AGT_ATTR), |
| 268 |
c(PushProp,r|o,AGT_PROP), c(PopProp,r|o,AGT_PROP), |
| 269 |
b(Goto,n), b(OnFailGoto,n), |
| 270 |
b(EndDisambig,n), |
| 271 |
b(XRedirect,n), |
| 272 |
c(CopyString,AGT_STR,AGT_STR), |
| 273 |
b(UpcaseString,AGT_STR), b(DowncaseString,AGT_STR), |
| 274 |
c(TurnObjFlagON,r|o,AGT_OBJFLAG), c(TurnObjFlagOFF,r|o,AGT_OBJFLAG), |
| 275 |
c(ToggleObjFlag,r|o,AGT_OBJFLAG), |
| 276 |
c(PushObjProp,r|o,AGT_OBJPROP), |
| 277 |
c(PopObjProp,r|o,AGT_OBJPROP), |
| 278 |
c(MoveInDirection,o|AGT_SELF,AGT_DIR) |
| 279 |
}; |
| 280 |
|
| 281 |
const opdef end_def[]={ |
| 282 |
a(WinGame),a(EndGame), |
| 283 |
a(QuitThisCMD),a(QuitAllCMDs),a(DoneWithTurn) |
| 284 |
}; |
| 285 |
|
| 286 |
const opdef illegal_def=a(ILLEGAL); |
| 287 |
|
| 288 |
#undef a |
| 289 |
#undef b |
| 290 |
#undef c |
| 291 |
|
| 292 |
#undef n |
| 293 |
#undef v |
| 294 |
#undef r |
| 295 |
#undef i |
| 296 |
#undef o |
| 297 |
#undef l |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
static const cmd_fix_rec FIX_ME[]= |
| 326 |
{ {0,0}, |
| 327 |
{110,1000}, |
| 328 |
{215,WIN_ACT}, |
| 329 |
{220,-1}}; |
| 330 |
|
| 331 |
static const cmd_fix_rec FIX_ME0[]= |
| 332 |
|
| 333 |
{ {0,0}, |
| 334 |
{110,1000}, |
| 335 |
{136,1028}, |
| 336 |
{156,1049}, |
| 337 |
{212,WIN_ACT}, |
| 338 |
{217,-1}}; |
| 339 |
|
| 340 |
static const cmd_fix_rec FIX_ME0A[]= |
| 341 |
|
| 342 |
{ {0,0}, |
| 343 |
{110,1000}, |
| 344 |
{130,1021}, |
| 345 |
{135,1028}, |
| 346 |
{155,1049}, |
| 347 |
{211,WIN_ACT}, |
| 348 |
{216,-1}}; |
| 349 |
|
| 350 |
static const cmd_fix_rec FIX_ME15[]= |
| 351 |
{ {0,0}, |
| 352 |
{110,1000}, |
| 353 |
{158,1049}, |
| 354 |
{214,WIN_ACT}, |
| 355 |
{219,-1}}; |
| 356 |
|
| 357 |
static const cmd_fix_rec FIX_135[]= |
| 358 |
{ {0,0}, |
| 359 |
{3,12}, |
| 360 |
{59,71}, |
| 361 |
{88,106}, |
| 362 |
{92,1000}, |
| 363 |
{105,1039}, |
| 364 |
{114,1049}, |
| 365 |
{157,1095}, |
| 366 |
{167,WIN_ACT}, |
| 367 |
{172,-1}}; |
| 368 |
|
| 369 |
static const cmd_fix_rec FIX_118[]= |
| 370 |
{ {0,0}, |
| 371 |
{3,12}, |
| 372 |
{59,71}, |
| 373 |
{88,106}, |
| 374 |
{92,1000}, |
| 375 |
{105,1039}, |
| 376 |
{114,1049}, |
| 377 |
{118,1054}, |
| 378 |
{156,1095}, |
| 379 |
{166,WIN_ACT}, |
| 380 |
{171,-1}}; |
| 381 |
|
| 382 |
|
| 383 |
static const cmd_fix_rec FIX_182[]= |
| 384 |
{ {0,0}, |
| 385 |
{3,12}, |
| 386 |
{53,110}, |
| 387 |
{55,62}, |
| 388 |
{61,71}, |
| 389 |
{90,106}, |
| 390 |
{94,1000}, |
| 391 |
{107,1039}, |
| 392 |
{116,1049}, |
| 393 |
{143,1105}, |
| 394 |
{144,1076}, |
| 395 |
{160,1095}, |
| 396 |
{170,WIN_ACT}, |
| 397 |
{175,-1}}; |
| 398 |
|
| 399 |
|
| 400 |
static const cmd_fix_rec FIX_183[]= |
| 401 |
{ {0,0}, |
| 402 |
{3,12}, |
| 403 |
{55,110}, |
| 404 |
{57,64}, |
| 405 |
{61,71}, |
| 406 |
{90,106}, |
| 407 |
{94,112}, |
| 408 |
{101,1000}, |
| 409 |
{114,1039}, |
| 410 |
{123,1049}, |
| 411 |
{158,1105}, |
| 412 |
{159,1084}, |
| 413 |
{167,1095}, |
| 414 |
{169,1106}, |
| 415 |
{177,1097}, |
| 416 |
{185,WIN_ACT}, |
| 417 |
{190,-1}}; |
| 418 |
|
| 419 |
static const cmd_fix_rec FIX_10[]= |
| 420 |
{ {0,0}, |
| 421 |
{3,12}, |
| 422 |
{59,71}, |
| 423 |
{80,95}, |
| 424 |
{84,108}, |
| 425 |
{86,1000}, |
| 426 |
{88,1009}, |
| 427 |
{92,1039}, |
| 428 |
{101,1049}, |
| 429 |
{105,1054}, |
| 430 |
{115,1065}, |
| 431 |
{142,1095}, |
| 432 |
{152,WIN_ACT}, |
| 433 |
{157,-1}}; |
| 434 |
|
| 435 |
static const cmd_fix_rec FIX_15[]= |
| 436 |
{ {0,0}, |
| 437 |
{3,12}, |
| 438 |
{60,70}, |
| 439 |
|
| 440 |
{90,106}, |
| 441 |
{94,1000}, |
| 442 |
{107,1039}, |
| 443 |
{116,1049}, |
| 444 |
{172,WIN_ACT}, |
| 445 |
{177,-1}}; |
| 446 |
|
| 447 |
const fix_array FIX_LIST[]= |
| 448 |
{FIX_135, |
| 449 |
FIX_10, FIX_118, FIX_135, FIX_135, FIX_135, FIX_182, FIX_183, |
| 450 |
FIX_15, FIX_15, FIX_15, FIX_ME0, FIX_ME0A, FIX_ME15, FIX_ME15, FIX_ME}; |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
const char* verstr[]={"????","SMALL","BIG","MASTER","SOGGY"}; |
| 458 |
const char* averstr[]={"????","1.0","1.18", |
| 459 |
"1.2","1.32/COS","Classic", |
| 460 |
"1.82","1.83", |
| 461 |
"1.5/H","1.5/F","1.6", |
| 462 |
"ME/1.0b","ME/1.0a", |
| 463 |
"ME/1.5","ME/1.55","ME/1.6", |
| 464 |
"Magx"}; |
| 465 |
|
| 466 |
const char *portstr=PORTSTR; |
| 467 |
const char *version_str="version 1.1.2"; |
| 468 |
|
| 469 |
const char nonestr[5]={4,'n','o','n','e'}; |
| 470 |
static const char NONEstr[5]={4,'N','O','N','E'}; |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
const char* exitname[13]= |
| 475 |
{"N","S","E","W","NE","NW","SE","SW","U","D","IN","OUT","SPC"}; |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
static const char verbdef[]= |
| 489 |
"north n. south s. east e. west w." |
| 490 |
"northeast ne. northwest nw. southeast se. southwest sw." |
| 491 |
"up u. down d." |
| 492 |
"enter in inside go&in go&into go&in&to get&in get&into get&in&to." |
| 493 |
"exit leave out go&out get&out get&out&of. special." |
| 494 |
"throw cast dump, at to in into across inside;" |
| 495 |
"open , with; close shut; lock, with; unlock, with;" |
| 496 |
"look l. examine x ex check inspect look&at look∈" |
| 497 |
"change_locations change_location;" |
| 498 |
"read; eat; drink; score! attack kill fight hit, with;" |
| 499 |
"wait z. yell shout scream." |
| 500 |
"put place, in with inside into near behind over under on;" |
| 501 |
"quit q! tell talk talk&to talk&with, to about;" |
| 502 |
"inventory inv i. get take pick pick&up; ask, about for;" |
| 503 |
"turn, on off; push touch press, with; pull; play;" |
| 504 |
"list. show, to; drop;" |
| 505 |
"listexit listexits list_exits list&exits show&exits." |
| 506 |
"brief! verbose! save! restore!" |
| 507 |
"light; extinguish ext put&out; fire shoot, at with;" |
| 508 |
"help h. wear put&on; remove take&off;" |
| 509 |
"script script&on! unscript script&off! magic_word. view; after." |
| 510 |
"instructions ins!" |
| 511 |
|
| 512 |
"again g. restart! oops; undo. notify!" |
| 513 |
"listexit_on listexit&on listexits&on!" |
| 514 |
"listexit_off listexit&off listexits&off!" |
| 515 |
"agildebug agtdebug! log! logoff log&off log&close! replay!" |
| 516 |
"replay_step replay&step! menu! replay_fast replay&fast." |
| 517 |
"sound sound_on sound&on! sound_off sound&off! introduction intro!" |
| 518 |
"dir_addr."; |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
char *old_agt_verb_str[]={ |
| 538 |
"n","s","e","w","ne","nw","se","sw","u","d","in","inside","leave", |
| 539 |
"cast","dump","shut","l","ex","inspect","check","kill","fight","hit", |
| 540 |
"shout","scream","place","q","talk","i","take","touch","ext", |
| 541 |
"shoot","h","ins",NULL}; |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
#define HASHSIZE (1<<HASHBITS) |
| 550 |
#define HASHMASK (HASHSIZE-1) |
| 551 |
|
| 552 |
#ifdef DOHASH |
| 553 |
static word DOSFARDATA hash[HASHSIZE]; |
| 554 |
#endif |
| 555 |
|
| 556 |
static int hashfunc(const char *s) |
| 557 |
{ |
| 558 |
unsigned long n, i; |
| 559 |
|
| 560 |
n=0; |
| 561 |
for(;*s!=0;s++) { |
| 562 |
n+=(n<<2)+(uchar)*s; |
| 563 |
i=n & ~HASHMASK; |
| 564 |
if (i) |
| 565 |
n=(n^(i>>HASHBITS))&HASHMASK; |
| 566 |
} |
| 567 |
return (n & HASHMASK); |
| 568 |
} |
| 569 |
|
| 570 |
static word search0_dict(const char *s) |
| 571 |
{ |
| 572 |
int i; |
| 573 |
|
| 574 |
#ifdef DOHASH |
| 575 |
for(i=hashfunc(s); |
| 576 |
hash[i]!=-1 && strcmp(s,dict[hash[i]])!=0; |
| 577 |
i=(i+1)&HASHMASK); |
| 578 |
return hash[i]; |
| 579 |
#else |
| 580 |
for(i=0; strcmp(s,dict[i])!=0 && i<dp; i++); |
| 581 |
if (i<dp) return i; |
| 582 |
return -1; |
| 583 |
#endif |
| 584 |
} |
| 585 |
|
| 586 |
word search_dict(const char *s) |
| 587 |
|
| 588 |
{ |
| 589 |
word w; |
| 590 |
char *t,*p; |
| 591 |
|
| 592 |
t=rstrdup(s); |
| 593 |
for(p=t;*p;p++) *p=tolower(*p); |
| 594 |
w=search0_dict(t); |
| 595 |
rfree(t); |
| 596 |
return w; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
static word add0_dict(const char *s) |
| 602 |
{ |
| 603 |
int i; |
| 604 |
long newptr; |
| 605 |
char *newstr; |
| 606 |
|
| 607 |
i=search0_dict(s); |
| 608 |
if (i!=-1) return i; |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
dict=rrealloc(dict,sizeof(char*)*(dp+1)); |
| 613 |
newptr=dictstrptr+strlen(s)+1; |
| 614 |
if (newptr>dictstrsize) { |
| 615 |
if (dictstrsize==0) dictstrsize=DICT_INIT; |
| 616 |
while(newptr>dictstrsize) |
| 617 |
dictstrsize+=DICT_GRAN; |
| 618 |
newstr=rrealloc(dictstr,dictstrsize); |
| 619 |
|
| 620 |
for(i=0;i<dp;i++) |
| 621 |
dict[i]=(dict[i]-dictstr)+newstr; |
| 622 |
dictstr=newstr; |
| 623 |
} |
| 624 |
strcpy(dictstr+dictstrptr,s); |
| 625 |
dict[dp]=dictstr+dictstrptr; |
| 626 |
dictstrptr=newptr; |
| 627 |
|
| 628 |
#ifdef DOHASH |
| 629 |
if (dp>HASHSIZE) fatal("Hash table overflow"); |
| 630 |
for(i=hashfunc(s);hash[i]!=-1;i=(i+1)&HASHMASK); |
| 631 |
hash[i]=dp; |
| 632 |
#endif |
| 633 |
return dp++; |
| 634 |
} |
| 635 |
|
| 636 |
#ifdef DOHASH |
| 637 |
|
| 638 |
static void init_hash(void) |
| 639 |
{ |
| 640 |
int i; |
| 641 |
|
| 642 |
for(i=0;i<HASHSIZE;i++) hash[i]=-1; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
static void rebuild_hash(void) |
| 650 |
{ |
| 651 |
int i,j; |
| 652 |
|
| 653 |
if (dp>HASHSIZE) fatal("Hash table overflow"); |
| 654 |
init_hash(); |
| 655 |
|
| 656 |
for(i=0;i<dp;i++) { |
| 657 |
for(j=hashfunc(dict[i]);hash[j]!=-1;j=(j+1)&HASHMASK); |
| 658 |
hash[j]=i; |
| 659 |
} |
| 660 |
} |
| 661 |
#endif |
| 662 |
|
| 663 |
|
| 664 |
static void init0_dict(void) |
| 665 |
|
| 666 |
|
| 667 |
{ |
| 668 |
#ifdef DOHASH |
| 669 |
init_hash(); |
| 670 |
hash[hashfunc("any")]=0; |
| 671 |
#endif |
| 672 |
|
| 673 |
dict=rmalloc(sizeof(char*)); |
| 674 |
dictstr=rmalloc(DICT_GRAN); |
| 675 |
strcpy(dictstr,"any"); |
| 676 |
dict[0]=dictstr; |
| 677 |
|
| 678 |
dictstrptr=4; |
| 679 |
dictstrsize=DICT_GRAN; |
| 680 |
dp=1; |
| 681 |
syntbl=NULL;synptr=0;syntbl_size=0; |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
static rbool no_syn; |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
slist add_multi_word(word w) |
| 699 |
{ |
| 700 |
slist start_list; |
| 701 |
rbool end_found; |
| 702 |
char *curr; |
| 703 |
char *s,*t; |
| 704 |
|
| 705 |
for(s=dict[w];*s!=0 && *s!=' ';s++); |
| 706 |
if (*s!=' ') return 0; |
| 707 |
|
| 708 |
start_list=synptr; |
| 709 |
curr=t=rstrdup(dict[w]); |
| 710 |
s=t+(s-dict[w]); |
| 711 |
|
| 712 |
addsyn(w); |
| 713 |
while(1) { |
| 714 |
end_found=(*s==0); |
| 715 |
*s=0; |
| 716 |
addsyn(add0_dict(curr)); |
| 717 |
if (end_found) break; |
| 718 |
curr=++s; |
| 719 |
while(*s!=0 && *s!=' ') s++; |
| 720 |
} |
| 721 |
addsyn(-1); |
| 722 |
rfree(t); |
| 723 |
return start_list; |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
static void verb_multiword(int vp) |
| 730 |
{ |
| 731 |
int i; |
| 732 |
slist ptr; |
| 733 |
|
| 734 |
if (no_syn) return; |
| 735 |
for(i=auxsyn[vp];syntbl[i]!=0;i++) { |
| 736 |
ptr=add_multi_word(syntbl[i]); |
| 737 |
if (ptr!=0) { |
| 738 |
num_auxcomb+=1; |
| 739 |
auxcomb=rrealloc(auxcomb,num_auxcomb*sizeof(slist)); |
| 740 |
auxcomb[num_auxcomb-1]=ptr; |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
static void enter_verbs(int vp, const char *s) |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
{ |
| 751 |
const char *p; |
| 752 |
words curr; |
| 753 |
int n; |
| 754 |
rbool have_multiword; |
| 755 |
|
| 756 |
n=0; |
| 757 |
have_multiword=0; |
| 758 |
auxsyn[vp]=synptr; |
| 759 |
for(p=s;*p!=0;p++) |
| 760 |
if (*p==';' || *p==',' || *p=='.' || *p=='!' || isspace(*p)) { |
| 761 |
if (n>0) { |
| 762 |
curr[n]=0;n=0; |
| 763 |
addsyn(add0_dict(curr)); |
| 764 |
} |
| 765 |
if (!isspace(*p)) |
| 766 |
addsyn(-1); |
| 767 |
if (*p==';' || *p=='.' || *p=='!') { |
| 768 |
if (*p==';') verbflag[vp]|=VERB_TAKEOBJ; |
| 769 |
if (*p=='!') verbflag[vp]|=VERB_META; |
| 770 |
if (have_multiword) |
| 771 |
verb_multiword(vp); |
| 772 |
have_multiword=0; |
| 773 |
vp++; |
| 774 |
if (vp>=TOTAL_VERB) break; |
| 775 |
auxsyn[vp]=synptr; |
| 776 |
} |
| 777 |
else if (*p==',') |
| 778 |
preplist[vp]=synptr; |
| 779 |
} |
| 780 |
else if (*p=='&') { |
| 781 |
curr[n++]=' '; |
| 782 |
have_multiword=1; |
| 783 |
} |
| 784 |
else curr[n++]=*p; |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
void init_dict(void) |
| 791 |
{ |
| 792 |
dict=NULL;verblist=NULL;syntbl=NULL;no_syn=0; |
| 793 |
auxsyn=NULL;preplist=NULL;verbflag=NULL; |
| 794 |
auxcomb=NULL; |
| 795 |
old_agt_verb=NULL; |
| 796 |
num_auxcomb=0; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
void build_verblist(void) |
| 801 |
{ |
| 802 |
int i; |
| 803 |
|
| 804 |
verblist=rmalloc(sizeof(words)*TOTAL_VERB); |
| 805 |
for(i=0;i<TOTAL_VERB;i++) |
| 806 |
strncpy(verblist[i],dict[syntbl[auxsyn[i]]],sizeof(words)); |
| 807 |
#ifdef DUMP_VLIST |
| 808 |
{ |
| 809 |
int j; |
| 810 |
rprintf("VERB LIST:\n"); |
| 811 |
for(i=0;i<TOTAL_VERB;i++) { |
| 812 |
rprintf("%2d %s:",i,verblist[i]); |
| 813 |
for(j=auxsyn[i];syntbl[j]!=0;j++) |
| 814 |
rprintf(" %s",dict[syntbl[auxsyn[i]]]); |
| 815 |
rprintf(" ==> "); |
| 816 |
for(j=preplist[i];syntbl[j]!=0;j++) |
| 817 |
rprintf(" %s",dict[ syntbl[preplist[i]]] ); |
| 818 |
writeln(""); |
| 819 |
} |
| 820 |
} |
| 821 |
#endif |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
void set_verbflag(void) |
| 827 |
{ |
| 828 |
verbflag[14]|=VERB_MULTI; |
| 829 |
verbflag[29]|=VERB_MULTI; |
| 830 |
verbflag[33]|=VERB_MULTI; |
| 831 |
verbflag[41]|=VERB_MULTI; |
| 832 |
verbflag[51]|=VERB_MULTI; |
| 833 |
verbflag[52]|=VERB_MULTI; |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
void reinit_dict(void) |
| 838 |
|
| 839 |
|
| 840 |
{ |
| 841 |
char buff[16]; |
| 842 |
|
| 843 |
int i; |
| 844 |
|
| 845 |
no_syn=no_auxsyn; |
| 846 |
|
| 847 |
auxsyn=rmalloc(sizeof(slist)*TOTAL_VERB); |
| 848 |
auxcomb=NULL; num_auxcomb=0; |
| 849 |
preplist=rmalloc(sizeof(slist)*TOTAL_VERB); |
| 850 |
verbflag=rmalloc(sizeof(uchar)*TOTAL_VERB); |
| 851 |
|
| 852 |
if (!agx_file) |
| 853 |
init0_dict(); |
| 854 |
#ifdef DOHASH |
| 855 |
else |
| 856 |
rebuild_hash(); |
| 857 |
#endif |
| 858 |
|
| 859 |
for(i=0;i<TOTAL_VERB;i++) |
| 860 |
verbflag[i]=0; |
| 861 |
|
| 862 |
auxsyn[0]=synptr; |
| 863 |
addsyn(-1); |
| 864 |
|
| 865 |
enter_verbs(1,verbdef); |
| 866 |
set_verbflag(); |
| 867 |
|
| 868 |
for(i=0;i<DVERB;i++) |
| 869 |
{ |
| 870 |
sprintf(buff,"dummy_verb%d",i+1); |
| 871 |
auxsyn[i+BASE_VERB]=synptr; |
| 872 |
addsyn(add0_dict(buff)); |
| 873 |
addsyn(-1); |
| 874 |
} |
| 875 |
for(i=0;i<MAX_SUB;i++) |
| 876 |
{ |
| 877 |
sprintf(buff,"subroutine%d",i+1); |
| 878 |
auxsyn[i+BASE_VERB+DVERB]=synptr; |
| 879 |
addsyn( sub_name[i]=add0_dict(buff) ); |
| 880 |
addsyn(-1); |
| 881 |
} |
| 882 |
no_syn=0; |
| 883 |
verblist=NULL; |
| 884 |
|
| 885 |
|
| 886 |
for(i=0;old_agt_verb_str[i]!=NULL;i++); |
| 887 |
rfree(old_agt_verb); |
| 888 |
old_agt_verb=rmalloc(sizeof(word)*(i+1)); |
| 889 |
for(i=0;old_agt_verb_str[i]!=NULL;i++) { |
| 890 |
old_agt_verb[i]=search_dict(old_agt_verb_str[i]); |
| 891 |
assert(old_agt_verb[i]!=-1); |
| 892 |
} |
| 893 |
old_agt_verb[i]=-1; |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
void free_dict(void) |
| 900 |
{ |
| 901 |
rfree(dict);rfree(verblist);rfree(syntbl); |
| 902 |
rfree(auxsyn);rfree(preplist);rfree(verbflag); |
| 903 |
} |
| 904 |
|
| 905 |
word add_dict(const char *str) |
| 906 |
{ |
| 907 |
int i, j; |
| 908 |
char s[50]; |
| 909 |
|
| 910 |
strncpy(s,str,48); |
| 911 |
for(i=0;s[i]!=0 && rspace(s[i]);i++); |
| 912 |
if (s[i]==0) return 0; |
| 913 |
|
| 914 |
|
| 915 |
for(j=0;s[j+i]!=0;j++) s[j]=tolower(s[j+i]); |
| 916 |
s[j]=0; |
| 917 |
|
| 918 |
for(j--;rspace(s[j]) && j>0; j--); |
| 919 |
s[j+1]=0; |
| 920 |
|
| 921 |
if (strcmp(s,"none")==0) return 0; |
| 922 |
|
| 923 |
return add0_dict(s); |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
void addsyn(word w) |
| 932 |
{ |
| 933 |
if (no_syn) return; |
| 934 |
if (w==0) return; |
| 935 |
if (w==-1) w=0; |
| 936 |
if (synptr>=syntbl_size) { |
| 937 |
syntbl_size+=SYN_GRAIN; |
| 938 |
if (syntbl_size>0x7FFF) |
| 939 |
fatal("Too many synonyms."); |
| 940 |
syntbl=rrealloc(syntbl,((long)syntbl_size)*sizeof(word)); } |
| 941 |
syntbl[synptr++]=w; |
| 942 |
} |
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
const char *gdict(word w) |
| 947 |
{ |
| 948 |
assert(w>=-1 && w<dp); |
| 949 |
if (w==-1) return "___"; |
| 950 |
return dict[w]; |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
int verb_builtin(word w) |
| 963 |
{ |
| 964 |
int i,j; |
| 965 |
|
| 966 |
for(i=1;i<TOTAL_VERB;i++) |
| 967 |
for(j=auxsyn[i];syntbl[j]!=0;j++) |
| 968 |
if (syntbl[j]==w) return i; |
| 969 |
|
| 970 |
|
| 971 |
return 0; |
| 972 |
} |
| 973 |
|
| 974 |
int verb_authorsyn(word w) |
| 975 |
{ |
| 976 |
int i,j; |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
if (aver<AGX00) { |
| 981 |
for(i=MAX_SUB-1;i>=0;i--) |
| 982 |
for(j=synlist[BASE_VERB+DVERB+i];syntbl[j]!=0;j++) |
| 983 |
if (w==syntbl[j]) return BASE_VERB+DVERB+i; |
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
for(i=DVERB-1;i>=0;i--) { |
| 995 |
int ii=((i%2)==0) ? i/2 : (i+DVERB-1)/2; |
| 996 |
for(j=synlist[BASE_VERB+ii];syntbl[j]!=0;j++) |
| 997 |
if (w==syntbl[j]) return BASE_VERB+ii; |
| 998 |
} |
| 999 |
for(i=BASE_VERB-1;i>0;i--) |
| 1000 |
for(j=synlist[i];syntbl[j]!=0;j++) |
| 1001 |
if (w==syntbl[j]) return i; |
| 1002 |
} else { |
| 1003 |
for(i=TOTAL_VERB-1;i>0;i--) |
| 1004 |
for(j=synlist[i];syntbl[j]!=0;j++) |
| 1005 |
if (w==syntbl[j]) return i; |
| 1006 |
} |
| 1007 |
return 0; |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
int verb_code(word w) |
| 1012 |
|
| 1013 |
{ |
| 1014 |
int canon, tmp; |
| 1015 |
|
| 1016 |
|
| 1017 |
tmp=verb_authorsyn(w); |
| 1018 |
if (tmp!=0) return tmp; |
| 1019 |
|
| 1020 |
|
| 1021 |
canon=verb_builtin(w); |
| 1022 |
if (canon!=0) { |
| 1023 |
|
| 1024 |
tmp=verb_authorsyn(syntbl[auxsyn[canon]]); |
| 1025 |
if (tmp!=0) return tmp; |
| 1026 |
} |
| 1027 |
|
| 1028 |
return canon; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
static int cmdverb_code(word w) |
| 1036 |
{ |
| 1037 |
int i,j; |
| 1038 |
|
| 1039 |
for(i=0;i<TOTAL_VERB;i++) |
| 1040 |
if (syntbl[auxsyn[i]]==w) return i; |
| 1041 |
|
| 1042 |
|
| 1043 |
agtwarn("Header verb not in canonical form.",1); |
| 1044 |
for(i=1;i<TOTAL_VERB;i++) |
| 1045 |
for(j=auxsyn[i];syntbl[j]!=0;j++) |
| 1046 |
if (syntbl[j]==w) return i; |
| 1047 |
agtwarn("Header verb not in internal list.",1); |
| 1048 |
return verb_code(w); |
| 1049 |
} |
| 1050 |
|
| 1051 |
char *objname(int i) |
| 1052 |
{ |
| 1053 |
char *s; |
| 1054 |
|
| 1055 |
if (i<0) |
| 1056 |
return rstrdup(dict[-i]); |
| 1057 |
if (i==0) |
| 1058 |
return rstrdup("...."); |
| 1059 |
if (i==1) return rstrdup("*Self*"); |
| 1060 |
if (i==1000) return rstrdup("*Worn*"); |
| 1061 |
if (i>=first_room && i<=maxroom) |
| 1062 |
return rstrdup(room[i-first_room].name); |
| 1063 |
if ( (i>=first_noun && i<=maxnoun) || (i>=first_creat && i<=maxcreat) ) |
| 1064 |
{ |
| 1065 |
word adjw,nounw; |
| 1066 |
if (i>=first_noun && i<=maxnoun) { |
| 1067 |
adjw=noun[i-first_noun].adj; |
| 1068 |
nounw=noun[i-first_noun].name; |
| 1069 |
} |
| 1070 |
else { |
| 1071 |
adjw=creature[i-first_creat].adj; |
| 1072 |
nounw=creature[i-first_creat].name; |
| 1073 |
} |
| 1074 |
if (adjw==0 || !strcmp(dict[adjw],"no_adjective")) |
| 1075 |
return rstrdup(dict[nounw]); |
| 1076 |
return concdup(dict[adjw],dict[nounw]); |
| 1077 |
} |
| 1078 |
|
| 1079 |
s=rmalloc(3+1+(5*sizeof(int))/2+1); |
| 1080 |
|
| 1081 |
sprintf(s,"ILL%d",i); |
| 1082 |
return s; |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
#define SORT_META |
| 1092 |
|
| 1093 |
#ifdef SORT_META |
| 1094 |
|
| 1095 |
#define ch1 ((const cmd_rec*)cmd1) |
| 1096 |
#define ch2 ((const cmd_rec*)cmd2) |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
#define s_verb(cmd) ( (cmd)->actor<0 ? (cmd)->data[0] : (cmd)->verbcmd) |
| 1105 |
|
| 1106 |
static int cmp_cmd(const void *cmd1, const void *cmd2) |
| 1107 |
{ |
| 1108 |
word v1,v2; |
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
v1=s_verb(ch1); |
| 1115 |
v2=s_verb(ch2); |
| 1116 |
|
| 1117 |
if (v1<v2) return -1; |
| 1118 |
if (v1>v2) return +1; |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
if ( abs(ch1->actor) < abs(ch2->actor) ) |
| 1124 |
return -1; |
| 1125 |
else if (abs(ch1->actor) == abs(ch2->actor) ) |
| 1126 |
return 0; |
| 1127 |
else return 1; |
| 1128 |
|
| 1129 |
} |
| 1130 |
|
| 1131 |
#undef ch1 |
| 1132 |
#undef ch2 |
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
static void rsort(void) |
| 1148 |
{ |
| 1149 |
long i; |
| 1150 |
integer *save_actor; |
| 1151 |
word *save_verb; |
| 1152 |
|
| 1153 |
save_actor=rmalloc(last_cmd*sizeof(integer)); |
| 1154 |
save_verb=rmalloc(last_cmd*sizeof(word)); |
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
for(i=0;i<last_cmd;i++) { |
| 1165 |
save_verb[i]=command[i].verbcmd; |
| 1166 |
if (command[i].actor>1) |
| 1167 |
command[i].verbcmd=syntbl[auxsyn[DIR_ADDR_CODE]]; |
| 1168 |
save_actor[i]=command[i].actor; |
| 1169 |
command[i].actor=i; |
| 1170 |
if (save_actor[i]<0) { |
| 1171 |
int j; |
| 1172 |
|
| 1173 |
command[i].actor=-i; |
| 1174 |
rfree(command[i].data); |
| 1175 |
command[i].data=rmalloc(sizeof(integer)); |
| 1176 |
for(j=i;j>0 && save_actor[j]<0;j--); |
| 1177 |
if (save_actor[j]>0) |
| 1178 |
command[i].data[0]=command[j].verbcmd; |
| 1179 |
else { |
| 1180 |
command[i].data[0]=0; |
| 1181 |
agtwarn("First command header is REDIRECT object!",0); |
| 1182 |
} |
| 1183 |
} |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
qsort(command,last_cmd,sizeof(cmd_rec),cmp_cmd); |
| 1188 |
|
| 1189 |
#if 0 |
| 1190 |
for(i=0;i<last_command;i++) |
| 1191 |
if (command[i].actor<0) |
| 1192 |
assert(i==0 || command[i].data[0]==command[i-1].verbcmd); |
| 1193 |
#endif |
| 1194 |
|
| 1195 |
|
| 1196 |
for(i=0;i<last_cmd;i++) { |
| 1197 |
command[i].verbcmd=save_verb[abs(command[i].actor)]; |
| 1198 |
command[i].actor=save_actor[abs(command[i].actor)]; |
| 1199 |
if (command[i].actor<0) { |
| 1200 |
rfree(command[i].data); |
| 1201 |
command[i].cmdsize=0; |
| 1202 |
} |
| 1203 |
} |
| 1204 |
rfree(save_actor); |
| 1205 |
rfree(save_verb); |
| 1206 |
} |
| 1207 |
|
| 1208 |
#endif |
| 1209 |
|
| 1210 |
void sort_cmd(void) |
| 1211 |
{ |
| 1212 |
int i; |
| 1213 |
word curr_vb; |
| 1214 |
word all_word, global_word; |
| 1215 |
|
| 1216 |
verbptr=rmalloc(sizeof(short)*TOTAL_VERB); |
| 1217 |
verbend=rmalloc(sizeof(short)*TOTAL_VERB); |
| 1218 |
|
| 1219 |
if (mars_fix) { |
| 1220 |
for(i=0;i<TOTAL_VERB;i++) { |
| 1221 |
verbptr[i]=0; |
| 1222 |
verbend[i]=last_cmd;} |
| 1223 |
return; |
| 1224 |
} |
| 1225 |
|
| 1226 |
#ifdef SORT_META |
| 1227 |
rsort(); |
| 1228 |
#endif |
| 1229 |
|
| 1230 |
if (no_auxsyn) return; |
| 1231 |
|
| 1232 |
for(i=0;i<TOTAL_VERB;i++) { |
| 1233 |
verbptr[i]=last_cmd; |
| 1234 |
verbend[i]=0; |
| 1235 |
} |
| 1236 |
|
| 1237 |
all_word=search_dict("all"); |
| 1238 |
if (all_word==0) all_word=-1; |
| 1239 |
|
| 1240 |
global_word=search_dict("global_scope"); |
| 1241 |
if (global_word==0) global_word=-1; |
| 1242 |
|
| 1243 |
|
| 1244 |
for(i=0;i<last_cmd;i++) { |
| 1245 |
if (command[i].actor<0) continue; |
| 1246 |
if (command[i].nouncmd==all_word) |
| 1247 |
|
| 1248 |
verbflag[cmdverb_code(command[i].verbcmd)]|=VERB_MULTI; |
| 1249 |
if (command[i].actor>1) |
| 1250 |
curr_vb=DIR_ADDR_CODE; |
| 1251 |
else |
| 1252 |
curr_vb=cmdverb_code(command[i].verbcmd); |
| 1253 |
if (i<verbptr[curr_vb]) verbptr[curr_vb]=i; |
| 1254 |
if (i>verbend[curr_vb]) verbend[curr_vb]=i; |
| 1255 |
} |
| 1256 |
|
| 1257 |
for(i=0;i<TOTAL_VERB;i++) |
| 1258 |
if (verbptr[i]==last_cmd) |
| 1259 |
verbend[i]=last_cmd; |
| 1260 |
else verbend[i]++; |
| 1261 |
|
| 1262 |
for(i=0;i<TOTAL_VERB;i++) { |
| 1263 |
int j; |
| 1264 |
|
| 1265 |
j=synlist[i]; |
| 1266 |
if (syntbl[j]==0) continue; |
| 1267 |
while(syntbl[j]!=0) j++; |
| 1268 |
j--; |
| 1269 |
if (syntbl[j]==global_word) { |
| 1270 |
verbflag[i]|=VERB_GLOBAL; |
| 1271 |
syntbl[j]=0; |
| 1272 |
} |
| 1273 |
} |
| 1274 |
} |
| 1275 |
|
| 1276 |
static word check_comb(int combptr, int verb, int noun) |
| 1277 |
{ |
| 1278 |
word w; |
| 1279 |
|
| 1280 |
if (combptr==0) return 0; |
| 1281 |
w=syntbl[combptr]; |
| 1282 |
if (syntbl[combptr+1]!=verb) return 0; |
| 1283 |
if (syntbl[combptr+2]!=noun) return 0; |
| 1284 |
if (syntbl[combptr+3]==0) return w; |
| 1285 |
return 0; |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
void cmds_syns_canon(void) |
| 1291 |
{ |
| 1292 |
int i, j, vb; |
| 1293 |
word w; |
| 1294 |
|
| 1295 |
for(i=0;i<last_cmd;i++) { |
| 1296 |
|
| 1297 |
if(command[i].verbcmd>0 && command[i].nouncmd>0 && |
| 1298 |
command[i].prep==0 && command[i].objcmd==0) { |
| 1299 |
for(j=0;j<num_auxcomb;j++) { |
| 1300 |
w=check_comb(auxcomb[j],command[i].verbcmd,command[i].nouncmd); |
| 1301 |
if (w>0) { |
| 1302 |
vb = verb_builtin(w); |
| 1303 |
if(vb>0) { |
| 1304 |
command[i].verbcmd=syntbl[auxsyn[vb]]; |
| 1305 |
command[i].nouncmd=0; |
| 1306 |
} |
| 1307 |
} |
| 1308 |
} |
| 1309 |
} |
| 1310 |
} |
| 1311 |
} |
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
const opdef *get_opdef(integer op) |
| 1322 |
{ |
| 1323 |
op=op%2048; |
| 1324 |
if (op<0 || (op>MAX_COND && op<START_ACT) || (op>PREWIN_ACT && op<WIN_ACT) |
| 1325 |
|| (op>MAX_ACT) ) { |
| 1326 |
return &illegal_def; |
| 1327 |
} |
| 1328 |
if (op>=2000) |
| 1329 |
return &end_def[op-2000]; |
| 1330 |
if (op>=1000) |
| 1331 |
return &act_def[op-1000]; |
| 1332 |
return &cond_def[op]; |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
long new_str(char *buff,int max_leng,rbool pasc) |
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
{ |
| 1349 |
int leng, i; |
| 1350 |
long p; |
| 1351 |
|
| 1352 |
if (pasc) { |
| 1353 |
leng=buff[0]; |
| 1354 |
if (leng>max_leng) leng=max_leng; |
| 1355 |
} else |
| 1356 |
leng=strlen(buff); |
| 1357 |
|
| 1358 |
if (ss_size<ss_end+leng+1) { |
| 1359 |
while (ss_size<ss_end+leng+1) ss_size+=SS_GRAIN; |
| 1360 |
static_str=rrealloc(static_str,sizeof(char)*ss_size); |
| 1361 |
} |
| 1362 |
|
| 1363 |
if (pasc) |
| 1364 |
if (memcmp(buff,nonestr,5)==0 || memcmp(buff,NONEstr,5)==0) { |
| 1365 |
|
| 1366 |
if (ss_end!=0) return (ss_end-1); |
| 1367 |
else { |
| 1368 |
static_str[0]=0;ss_end=1; |
| 1369 |
return 0; |
| 1370 |
} |
| 1371 |
} |
| 1372 |
|
| 1373 |
p=ss_end; |
| 1374 |
for(i=0;i<leng;) |
| 1375 |
static_str[ss_end++]=fixchar[(uchar)buff[pasc+(i++)]]; |
| 1376 |
static_str[ss_end++]=0; |
| 1377 |
|
| 1378 |
return p; |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
descr_line *read_descr(long start,long size) |
| 1389 |
{ |
| 1390 |
if (agx_file) |
| 1391 |
return agx_read_descr(start,size); |
| 1392 |
else |
| 1393 |
return agt_read_descr(start,size); |
| 1394 |
} |
| 1395 |
|
| 1396 |
void free_descr(descr_line *txt) |
| 1397 |
{ |
| 1398 |
if (txt==NULL) return; |
| 1399 |
if (mem_descr==NULL) |
| 1400 |
rfree(txt[0]); |
| 1401 |
rfree(txt); |
| 1402 |
} |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
long objextsize(char op) |
| 1411 |
{ |
| 1412 |
|
| 1413 |
|
| 1414 |
if (op==0) |
| 1415 |
return num_rflags*rangefix(maxroom-first_room+1) |
| 1416 |
+num_nflags*rangefix(maxnoun-first_noun+1) |
| 1417 |
+num_cflags*rangefix(maxcreat-first_creat+1); |
| 1418 |
else |
| 1419 |
return num_rprops*rangefix(maxroom-first_room+1) |
| 1420 |
+num_nprops*rangefix(maxnoun-first_noun+1) |
| 1421 |
+num_cprops*rangefix(maxcreat-first_creat+1); |
| 1422 |
} |
| 1423 |
|
| 1424 |
long lookup_objflag(int id, int t, char *ofs) |
| 1425 |
{ |
| 1426 |
if (id<0 || id>=oflag_cnt) return -1; |
| 1427 |
switch (t) |
| 1428 |
{ |
| 1429 |
case 0: *ofs=attrtable[id].rbit; return attrtable[id].r; |
| 1430 |
case 1: *ofs=attrtable[id].nbit; return attrtable[id].n; |
| 1431 |
case 2: *ofs=attrtable[id].cbit; return attrtable[id].c; |
| 1432 |
default: rprintf("INT ERROR: Invalid object type.\n"); |
| 1433 |
return -1; |
| 1434 |
} |
| 1435 |
} |
| 1436 |
|
| 1437 |
long lookup_objprop(int id, int t) |
| 1438 |
{ |
| 1439 |
if (id<0 || id>=oprop_cnt) return -1; |
| 1440 |
switch (t) |
| 1441 |
{ |
| 1442 |
case 0: return proptable[id].r; |
| 1443 |
case 1: return proptable[id].n; |
| 1444 |
case 2: return proptable[id].c; |
| 1445 |
default: rprintf("INT ERROR: Invalid object type.\n"); |
| 1446 |
return -1; |
| 1447 |
} |
| 1448 |
} |
| 1449 |
|
| 1450 |
int num_oattrs(int t, rbool isflag) |
| 1451 |
{ |
| 1452 |
switch(t) |
| 1453 |
{ |
| 1454 |
case 0: return isflag ? num_rflags : num_rprops; |
| 1455 |
case 1: return isflag ? num_nflags : num_nprops; |
| 1456 |
case 2: return isflag ? num_cflags : num_cprops; |
| 1457 |
default: rprintf("INT ERROR: Invalid object type.\n"); |
| 1458 |
return 0; |
| 1459 |
} |
| 1460 |
} |
| 1461 |
|
| 1462 |
rbool op_simpflag(uchar *pf, char ofs, int op) |
| 1463 |
|
| 1464 |
{ |
| 1465 |
unsigned char mask, amask, bmask; |
| 1466 |
|
| 1467 |
mask=1<<ofs; |
| 1468 |
amask=~mask | ( (op>>1) << ofs ); |
| 1469 |
bmask=(op&1)<<ofs; |
| 1470 |
|
| 1471 |
*pf=(*pf & amask)^bmask; |
| 1472 |
|
| 1473 |
return (*pf & mask)!=0; |
| 1474 |
} |
| 1475 |
|
| 1476 |
static long calcindex(integer obj, integer objbase, int ocnt, int base) |
| 1477 |
{ |
| 1478 |
int rval; |
| 1479 |
|
| 1480 |
if (base==-1) rval=-1; |
| 1481 |
else rval=(obj-objbase)*ocnt + base; |
| 1482 |
|
| 1483 |
return rval; |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
rbool have_objattr(rbool prop,integer obj,int id) |
| 1488 |
{ |
| 1489 |
int t; |
| 1490 |
char ofs; |
| 1491 |
|
| 1492 |
if (troom(obj)) t=0; |
| 1493 |
else if (tnoun(obj)) t=1; |
| 1494 |
else if (tcreat(obj)) t=2; |
| 1495 |
else return 0; |
| 1496 |
if (prop) |
| 1497 |
return (lookup_objprop(id,t)>=0); |
| 1498 |
else |
| 1499 |
return (lookup_objflag(id,t,&ofs)>=0); |
| 1500 |
} |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
rbool op_objflag(int op, integer obj, int id) |
| 1505 |
{ |
| 1506 |
|
| 1507 |
|
| 1508 |
int index; |
| 1509 |
int t, firstobj; |
| 1510 |
char ofs; |
| 1511 |
|
| 1512 |
if (troom(obj)) {t=0;firstobj=first_room;} |
| 1513 |
else if (tnoun(obj)) {t=1;firstobj=first_noun;} |
| 1514 |
else if (tcreat(obj)) {t=2;firstobj=first_creat;} |
| 1515 |
else return 0; |
| 1516 |
|
| 1517 |
index=calcindex(obj,firstobj,num_oattrs(t,1),lookup_objflag(id,t,&ofs)); |
| 1518 |
if (index==-1) return 0; |
| 1519 |
|
| 1520 |
return op_simpflag(&objflag[index],ofs,op); |
| 1521 |
} |
| 1522 |
|
| 1523 |
long op_objprop(int op, int obj, int id, long val) |
| 1524 |
{ |
| 1525 |
|
| 1526 |
int index, t, firstobj; |
| 1527 |
|
| 1528 |
if (troom(obj)) {t=0;firstobj=first_room;} |
| 1529 |
else if (tnoun(obj)) {t=1;firstobj=first_noun;} |
| 1530 |
else if (tcreat(obj)) {t=2;firstobj=first_creat;} |
| 1531 |
else return 0; |
| 1532 |
|
| 1533 |
index=calcindex(obj,firstobj,num_oattrs(t,0),lookup_objprop(id,t)); |
| 1534 |
if (index==-1) return 0; |
| 1535 |
|
| 1536 |
if (op==2) return objprop[index]; |
| 1537 |
else objprop[index]=val; |
| 1538 |
return val; |
| 1539 |
} |
| 1540 |
|
| 1541 |
const char *get_objattr_str(int dtype,int id,long val) |
| 1542 |
{ |
| 1543 |
int max_val; |
| 1544 |
|
| 1545 |
if (dtype==AGT_OBJPROP) { |
| 1546 |
if (!proptable || !propstr || id<0 || id>=oprop_cnt) return ""; |
| 1547 |
max_val=proptable[id].str_cnt; |
| 1548 |
if (val<0) val=0; |
| 1549 |
if (val>=max_val) val=max_val-1; |
| 1550 |
if (max_val>0) |
| 1551 |
return propstr[ proptable[id].str_list + val ]; |
| 1552 |
return ""; |
| 1553 |
} else if (dtype==AGT_VAR) { |
| 1554 |
if (!vartable || !propstr || id<0 || id>VAR_NUM) return ""; |
| 1555 |
max_val=vartable[id].str_cnt; |
| 1556 |
if (val<0) val=0; |
| 1557 |
if (val>=max_val) val=max_val-1; |
| 1558 |
if (max_val>0) |
| 1559 |
return propstr[ vartable[id].str_list + val ]; |
| 1560 |
return ""; |
| 1561 |
} else if (dtype==AGT_OBJFLAG) { |
| 1562 |
if (attrtable && id>=0 && id<oflag_cnt) |
| 1563 |
return (val ? attrtable[id].ystr : attrtable[id].nstr); |
| 1564 |
else |
| 1565 |
return (val ? "yes" : "no"); |
| 1566 |
} else if (dtype==AGT_FLAG) { |
| 1567 |
|
| 1568 |
if (flagtable && id>=0 && id<=FLAG_NUM) |
| 1569 |
return val ? flagtable[id].ystr : flagtable[id].nstr; |
| 1570 |
else |
| 1571 |
return val ? "on" : "off"; |
| 1572 |
} else |
| 1573 |
rprintf("INTERNAL ERROR: Invalid data type for get_objattr_str()."); |
| 1574 |
return ""; |
| 1575 |
} |
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
void agtwarn(const char *s,int elev) |
| 1582 |
{ |
| 1583 |
if (ERR_LEVEL>=elev) |
| 1584 |
rprintf("Warning: %s\n",s); |
| 1585 |
} |
| 1586 |
|
| 1587 |
void agtnwarn(const char *s,int n,int elev) |
| 1588 |
{ |
| 1589 |
if (ERR_LEVEL>=elev) |
| 1590 |
rprintf("Warning: %s%d.\n",s,n); |
| 1591 |
} |
| 1592 |
|
| 1593 |
void fatal(const char *s) |
| 1594 |
{ |
| 1595 |
|
| 1596 |
|
| 1597 |
rprintf("Fatal error: %s\n",s); |
| 1598 |
close_interface(); |
| 1599 |
exit(EXIT_FAILURE); |
| 1600 |
} |
| 1601 |
|
| 1602 |
void init_flags(void) |
| 1603 |
{ |
| 1604 |
rm_trap=1; |
| 1605 |
DIAG=def_DIAG; interp_arg=def_interp_arg; |
| 1606 |
debug_da1=def_debug_da1; RAW_CMD_OUT=def_RAW_CMD_OUT; |
| 1607 |
ERR_LEVEL=def_ERR_LEVEL; |
| 1608 |
irun_mode=0; |
| 1609 |
fix_ascii_flag=fix_ascii; |
| 1610 |
descr_maxmem=DESCR_BUFFSIZE; |
| 1611 |
bold_mode=0; |
| 1612 |
dbg_nomsg=0; |
| 1613 |
debug_mode=0; |
| 1614 |
dbgflagptr=NULL; |
| 1615 |
dbgvarptr=NULL; |
| 1616 |
dbgcntptr=NULL; |
| 1617 |
no_auxsyn=0; |
| 1618 |
text_file=0; |
| 1619 |
#ifdef PATH_SEP |
| 1620 |
gamepath=NULL; |
| 1621 |
#endif |
| 1622 |
BATCH_MODE=make_test=0; |
| 1623 |
font_status=0; |
| 1624 |
#ifdef OPEN_AS_TEXT |
| 1625 |
open_as_binary=0; |
| 1626 |
#endif |
| 1627 |
} |
| 1628 |
|