| 1 | #!/usr/bin/perl -w | ||
| 2 | |||
| 3 | # Client commands for the 'convertlpc' plugin | ||
| 4 | |||
| 5 | { package Games::Axmud::Cmd::Plugin::ConvertLPC; | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | # use diagnostics; | ||
| 10 | |||
| 11 | use Glib qw(TRUE FALSE); | ||
| 12 | |||
| 13 | our @ISA = qw(Games::Axmud::Generic::Plugin::Cmd Games::Axmud::Generic::Cmd Games::Axmud); | ||
| 14 | |||
| 15 | ################## | ||
| 16 | # Constructors | ||
| 17 | |||
| 18 | sub new { | ||
| 19 | |||
| 20 | # Create a new instance of this command object (there should only be one) | ||
| 21 | # | ||
| 22 | # Expected arguments | ||
| 23 | # (none besides $class) | ||
| 24 | # | ||
| 25 | # Return values | ||
| 26 | # 'undef' if GA::Generic::Cmd->new reports an error | ||
| 27 | # Blessed reference to the new object on success | ||
| 28 | |||
| 29 | my ($class, $check) = @_; | ||
| 30 | |||
| 31 | # Setup | ||
| 32 | my $self = Games::Axmud::Generic::Cmd->new('convertlpc', FALSE, TRUE); | ||
| 33 | if (! $self) {return undef}; | ||
| 34 | |||
| 35 | $self->{defaultUserCmdList} = ['clpc', 'convertlpc']; | ||
| 36 | $self->{userCmdList} = \@{$self->{defaultUserCmdList}}; | ||
| 37 | $self->{descrip} = '(convertlpc plugin) Converts world model to ' | ||
| 38 | . $convertlpc::CONVERT_TYPE; | ||
| 39 | |||
| 40 | # Bless the object into existence | ||
| 41 | bless $self, $class; | ||
| 42 | return $self; | ||
| 43 | } | ||
| 44 | |||
| 45 | ################## | ||
| 46 | # Methods | ||
| 47 | |||
| 48 | sub do { | ||
| 49 | |||
| 50 | my ( | ||
| 51 | $self, $session, $inputString, $userCmd, $standardCmd, | ||
| 52 | $switch, | ||
| 53 | $check, | ||
| 54 | ) = @_; | ||
| 55 | |||
| 56 | # Local variables | ||
| 57 | my ( | ||
| 58 | $wmObj, $world, $noWriteFlag, $roomCount, $otherCount, $errorCount, $totalCount, $dir, | ||
| 59 | $msg, | ||
| 60 | @regionOrderList, | ||
| 61 | %regionHash, %checkHash, %tierHash, %usedHash, %convertHash, | ||
| 62 | ); | ||
| 63 | |||
| 64 | # Check for improper arguments | ||
| 65 | if (defined $check) { | ||
| 66 | |||
| 67 | return $self->improper($session, $inputString); | ||
| 68 | } | ||
| 69 | |||
| 70 | # Import the world model (which contains any maps you've drawn) and the current world's name | ||
| 71 | # (for convenience) | ||
| 72 | $wmObj = $session->worldModelObj; | ||
| 73 | $world = $session->currentWorld->name; | ||
| 74 | |||
| 75 | # Deal with the switch, if specified | ||
| 76 | if ($switch) { | ||
| 77 | |||
| 78 | if ($switch ne '-n') { | ||
| 79 | |||
| 80 | return $self->error( | ||
| 81 | $session, $inputString, | ||
| 82 | 'Invalid switch (try \';convertlpc -n\')', | ||
| 83 | ); | ||
| 84 | |||
| 85 | } else { | ||
| 86 | |||
| 87 | # Don't actually write any LPC files | ||
| 88 | $noWriteFlag = TRUE; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | # Compile a hash of regions, in the form | ||
| 93 | # $regionHash{world_model_number} = modified_region_name | ||
| 94 | # ...where 'modified_region_name' is the region's usual name, with all whitespace converted | ||
| 95 | # to underline characters, all non-alphanumeric characters removed, and everything | ||
| 96 | # converted to lower-case (NB If $NO_UNDERLINE_FLAG is set, whitespace is removed | ||
| 97 | # rather than being converted) | ||
| 98 | # %checkHash is used to make sure there are no duplicates of 'modified_region_name' | ||
| 99 | foreach my $regionObj ($wmObj->ivValues('regionModelHash')) { | ||
| 100 | |||
| 101 | my $name = $regionObj->name; | ||
| 102 | |||
| 103 | if (exists $convertlpc::SPECIAL_NAME_HASH{$name}) { | ||
| 104 | |||
| 105 | # Use the modified form specified by the global variable, e.g. use 'ndesert' rather | ||
| 106 | # than 'Northern desert' | ||
| 107 | $name = $convertlpc::SPECIAL_NAME_HASH{$name}; | ||
| 108 | |||
| 109 | } elsif (! $convertlpc::NO_UNDERLINE_FLAG) { | ||
| 110 | |||
| 111 | # Use the region name specified by the world model, but replace whitespace with | ||
| 112 | # underlines | ||
| 113 | $name =~ s/\s+/_/; | ||
| 114 | |||
| 115 | } else { | ||
| 116 | |||
| 117 | # Use the region name specified by the world model, but remove whitespace | ||
| 118 | $name =~ s/\s+//; | ||
| 119 | } | ||
| 120 | |||
| 121 | # Remove any leading whitespace | ||
| 122 | $name =~ s/[^\w]//; | ||
| 123 | $name = lc($name); | ||
| 124 | |||
| 125 | if (exists $checkHash{$name}) { | ||
| 126 | |||
| 127 | return $self->error( | ||
| 128 | $session, $inputString, | ||
| 129 | 'Command produced a duplicate region name \'' . $name . '\'', | ||
| 130 | ); | ||
| 131 | |||
| 132 | } else { | ||
| 133 | |||
| 134 | $regionHash{$regionObj->number} = $name; | ||
| 135 | $checkHash{$name} = undef; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | # Compile a parallel hash of regions, which allows us to create subdirectories for tiered | ||
| 140 | # (i.e. nested) domains, if required | ||
| 141 | # If $NEST_DIRECTORIES_FLAG is TRUE, hash in the form | ||
| 142 | # $tierHash{world_model_number} = parent_modified_region_name/modified_region_name | ||
| 143 | # $tierHash{world_model_number} = modified_region_name (for regions with no parent) | ||
| 144 | # If $NEST_DIRECTORIES_FLAG is FALSE, hash in the form | ||
| 145 | # $tierHash{world_model_number} = modified_region_name (for all regions) | ||
| 146 | if (! $convertlpc::NEST_DIRECTORIES_FLAG) { | ||
| 147 | |||
| 148 | %tierHash = %regionHash; | ||
| 149 | |||
| 150 | } else { | ||
| 151 | |||
| 152 | foreach my $regionObj ($wmObj->ivValues('regionModelHash')) { | ||
| 153 | |||
| 154 | my ($path, $parentRegionObj); | ||
| 155 | |||
| 156 | $path = $regionHash{$regionObj->number}; | ||
| 157 | $parentRegionObj = $regionObj; | ||
| 158 | |||
| 159 | if ($regionObj->parent) { | ||
| 160 | |||
| 161 | do { | ||
| 162 | |||
| 163 | my $parentModName; | ||
| 164 | |||
| 165 | $parentRegionObj | ||
| 166 | = $wmObj->ivShow('regionModelHash', $parentRegionObj->parent); | ||
| 167 | $parentModName = $regionHash{$parentRegionObj->number}; | ||
| 168 | |||
| 169 | $path = $parentModName . '/' . $path; | ||
| 170 | |||
| 171 | } until (! $parentRegionObj->parent); | ||
| 172 | |||
| 173 | } | ||
| 174 | |||
| 175 | $tierHash{$regionObj->number} = $path; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | # Perl requires us to create directories before creating sub-directories, so first compile a | ||
| 180 | # list of regions, in which child regions always appear after their parent regions | ||
| 181 | @regionOrderList = $self->compileRegionList($session); | ||
| 182 | if (! @regionOrderList) { | ||
| 183 | |||
| 184 | # (If there are no regions, then there are also no rooms) | ||
| 185 | return $self->error($session, $inputString, 'No regions or rooms found to convert'); | ||
| 186 | } | ||
| 187 | |||
| 188 | if (! $noWriteFlag) { | ||
| 189 | |||
| 190 | # Make sure the output directory exists | ||
| 191 | if (! -e $convertlpc::DIRECTORY) { | ||
| 192 | |||
| 193 | mkdir $convertlpc::DIRECTORY, 0755; | ||
| 194 | if (! -e $convertlpc::DIRECTORY) { | ||
| 195 | |||
| 196 | return $self->error( | ||
| 197 | $session, $inputString, | ||
| 198 | 'Failed to create directory ' . $convertlpc::DIRECTORY, | ||
| 199 | ); | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | # Make sure the /<world> directory exists | ||
| 204 | $dir = $convertlpc::DIRECTORY . '/' . $world; | ||
| 205 | mkdir $dir, 0755; | ||
| 206 | if (! -e $dir) { | ||
| 207 | |||
| 208 | return $self->error($session, $inputString, 'Failed to create directory ' . $dir); | ||
| 209 | } | ||
| 210 | |||
| 211 | # Make sure the /<world>/domains directory exists | ||
| 212 | $dir = $convertlpc::DIRECTORY . '/' . $world . '/domains'; | ||
| 213 | mkdir $dir, 0755; | ||
| 214 | if (! -e $dir) { | ||
| 215 | |||
| 216 | return $self->error($session, $inputString, 'Failed to create directory ' . $dir); | ||
| 217 | } | ||
| 218 | |||
| 219 | # Create a directory for each region | ||
| 220 | foreach my $regionNum (@regionOrderList) { | ||
| 221 | |||
| 222 | my $path = $tierHash{$regionNum}; | ||
| 223 | |||
| 224 | $dir = $convertlpc::DIRECTORY . '/' . $world . '/domains/' . $path; | ||
| 225 | |||
| 226 | mkdir $dir, 0755; | ||
| 227 | if (! -e $dir) { | ||
| 228 | |||
| 229 | return $self->error( | ||
| 230 | $session, $inputString, | ||
| 231 | 'Failed to create directory ' . $dir, | ||
| 232 | ); | ||
| 233 | } | ||
| 234 | |||
| 235 | # Create sub-directories for rooms and other categories of model objects (sentients, | ||
| 236 | # creatures, decorations etc), regardless of whether we're going to convert those | ||
| 237 | # objects to LPC files, or not | ||
| 238 | foreach my $type (keys %convertlpc::DIRECTORY_HASH) { | ||
| 239 | |||
| 240 | my $subDir = $convertlpc::DIRECTORY_HASH{$type}; | ||
| 241 | |||
| 242 | $dir = $convertlpc::DIRECTORY . '/' . $world . '/domains/' . $path . '/' | ||
| 243 | . $subDir; | ||
| 244 | |||
| 245 | mkdir $dir, 0755; | ||
| 246 | if (! -e $dir) { | ||
| 247 | |||
| 248 | return $self->error( | ||
| 249 | $session, $inputString, | ||
| 250 | 'Failed to create directory ' . $dir, | ||
| 251 | ); | ||
| 252 | } | ||
| 253 | } | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | # In the LPC mudlib, every room has its own file. Many objects (orcs, swords etc) also | ||
| 258 | # have their own file, though some objects (usually immovable objects) are defined in the | ||
| 259 | # room code | ||
| 260 | # Decide what the filepath will be used for each room in the world model | ||
| 261 | OUTER: foreach my $regionObj ($wmObj->ivValues('regionModelHash')) { | ||
| 262 | |||
| 263 | my ($regionmapObj, $regionPath); | ||
| 264 | |||
| 265 | $regionmapObj = $wmObj->ivShow('regionmapHash', $regionObj->name); | ||
| 266 | $regionPath = $tierHash{$regionObj->number}; | ||
| 267 | |||
| 268 | foreach my $roomNum ($regionmapObj->ivValues('gridRoomHash')) { | ||
| 269 | |||
| 270 | my ( | ||
| 271 | $roomObj, $roomPath, $fileHandle, | ||
| 272 | @list, | ||
| 273 | ); | ||
| 274 | |||
| 275 | $roomObj = $wmObj->ivShow('modelHash', $roomNum); | ||
| 276 | |||
| 277 | # Decide on the filepath of the LPC file for this room... | ||
| 278 | $roomPath = $self->allocateRoomPath( | ||
| 279 | \%usedHash, # Hash of filepaths that have already been used | ||
| 280 | $world, | ||
| 281 | $regionPath, # (The directory in which this file is stored) | ||
| 282 | $roomObj, | ||
| 283 | ); | ||
| 284 | |||
| 285 | # ...and store the filepath here | ||
| 286 | $convertHash{$roomObj->number} = $roomPath; | ||
| 287 | |||
| 288 | # Decide on the filepath for any objects in this room (any world model objects whose | ||
| 289 | # parent is this room) | ||
| 290 | foreach my $childNum ($roomObj->ivKeys('childHash')) { | ||
| 291 | |||
| 292 | my ($childObj, $childPath); | ||
| 293 | |||
| 294 | $childObj = $wmObj->ivShow('modelHash', $childNum); | ||
| 295 | |||
| 296 | # If this is one of the categories of model object we're converting to LPC... | ||
| 297 | if ( | ||
| 298 | $childObj->category ne 'room' | ||
| 299 | && exists $convertlpc::CATEGORY_HASH{$childObj->category} | ||
| 300 | ) { | ||
| 301 | # Decide on the filepath of this LPC file for this object... | ||
| 302 | $childPath = $self->allocateChildPath( | ||
| 303 | \%usedHash, # Hash of filepaths that have already been used | ||
| 304 | $world, | ||
| 305 | $regionPath, # (The directory in which this file is stored) | ||
| 306 | $childObj, | ||
| 307 | ); | ||
| 308 | |||
| 309 | # ...and store it here | ||
| 310 | $convertHash{$childObj->number} = $childPath; | ||
| 311 | } | ||
| 312 | } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | # Show an introductory message in the 'main' window | ||
| 317 | if (! $noWriteFlag) { | ||
| 318 | |||
| 319 | $self->writeText('Converting world model to ' . $convertlpc::CONVERT_TYPE . '...'); | ||
| 320 | |||
| 321 | } else { | ||
| 322 | |||
| 323 | $self->writeText( | ||
| 324 | 'Simulating conversion of world model to ' . $convertlpc::CONVERT_TYPE . '...', | ||
| 325 | ); | ||
| 326 | } | ||
| 327 | |||
| 328 | # (Display the message above right now) | ||
| 329 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->do'); | ||
| 330 | |||
| 331 | # Work out how many files will be written | ||
| 332 | $roomCount = 0; | ||
| 333 | $otherCount = 0; | ||
| 334 | $errorCount = 0; | ||
| 335 | $totalCount = 0; | ||
| 336 | |||
| 337 | OUTER: foreach my $category (@convertlpc::CATEGORY_LIST) { | ||
| 338 | |||
| 339 | my $iv = $category . 'ModelHash'; # Instance variable, e.g. '->roomModelHash' | ||
| 340 | |||
| 341 | # If we're allowed to write this type of object... | ||
| 342 | if ($convertlpc::CATEGORY_HASH{$category}) { | ||
| 343 | |||
| 344 | $totalCount += $wmObj->ivPairs($iv); | ||
| 345 | } | ||
| 346 | } | ||
| 347 | |||
| 348 | # Now write files (or simulate writing files) for each category of object in turn, starting | ||
| 349 | # with rooms | ||
| 350 | OUTER: foreach my $category (@convertlpc::CATEGORY_LIST) { | ||
| 351 | |||
| 352 | my $iv = $category . 'ModelHash'; # Instance variable, e.g. '->roomModelHash' | ||
| 353 | |||
| 354 | # If we're allowed to write this type of object... | ||
| 355 | if ($convertlpc::CATEGORY_HASH{$category}) { | ||
| 356 | |||
| 357 | INNER: foreach my $modelObj ($wmObj->ivValues($iv)) { | ||
| 358 | |||
| 359 | my ( | ||
| 360 | $path, $fullPath, $fileHandle, $currentCount, $subName, | ||
| 361 | @list, | ||
| 362 | ); | ||
| 363 | |||
| 364 | # Use the filepath that has already been allocated to this model object | ||
| 365 | $path = $convertHash{$modelObj->number}; | ||
| 366 | if (! $path) { | ||
| 367 | |||
| 368 | # This object is a region, or some other non-room object that's not | ||
| 369 | # actually contained in a room | ||
| 370 | next INNER; | ||
| 371 | } | ||
| 372 | |||
| 373 | # Prepare the file to write, before actually writing it | ||
| 374 | $subName = 'prepare' . ucfirst($category); # e.g. ->prepareRoom | ||
| 375 | |||
| 376 | @list = $self->$subName($session, \%convertHash, $modelObj); | ||
| 377 | if (! @list) { | ||
| 378 | |||
| 379 | $errorCount++; | ||
| 380 | |||
| 381 | if ($convertlpc::NO_ERROR_FLAG) { | ||
| 382 | |||
| 383 | # Give up writing files at the first error | ||
| 384 | last OUTER; | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 388 | # Add the copyright message (if any) to the top of the prepared file | ||
| 389 | unshift (@list, @convertlpc::COPYRIGHT_LIST); | ||
| 390 | |||
| 391 | if (! $noWriteFlag) { | ||
| 392 | |||
| 393 | # Now write the file | ||
| 394 | $fullPath = $convertlpc::DIRECTORY . '/' . $world . '/' . $path . '.c'; | ||
| 395 | |||
| 396 | if (! open ($fileHandle, ">$fullPath")) { | ||
| 397 | |||
| 398 | $self->writeText( | ||
| 399 | ' Failed to write ' . $category . ' #' . $modelObj->number . ': ' | ||
| 400 | . $fullPath, | ||
| 401 | ); | ||
| 402 | |||
| 403 | $errorCount++; | ||
| 404 | |||
| 405 | if ($convertlpc::NO_ERROR_FLAG) { | ||
| 406 | |||
| 407 | # Give up writing files at the first error | ||
| 408 | last OUTER; | ||
| 409 | } | ||
| 410 | |||
| 411 | } else { | ||
| 412 | |||
| 413 | # File opened for writing | ||
| 414 | foreach my $line (@list) { | ||
| 415 | |||
| 416 | print $fileHandle $line . "\n"; | ||
| 417 | } | ||
| 418 | |||
| 419 | close $fileHandle; | ||
| 420 | |||
| 421 | if ($category eq 'room') { | ||
| 422 | $roomCount++; | ||
| 423 | } else { | ||
| 424 | $otherCount++; | ||
| 425 | } | ||
| 426 | } | ||
| 427 | |||
| 428 | } else { | ||
| 429 | |||
| 430 | # Simulate writing files (actually, just keep count of the number of files | ||
| 431 | # we would have written) | ||
| 432 | if ($category eq 'room') { | ||
| 433 | $roomCount++; | ||
| 434 | } else { | ||
| 435 | $otherCount++; | ||
| 436 | } | ||
| 437 | } | ||
| 438 | |||
| 439 | # Show an update from time to time, if necessary | ||
| 440 | $currentCount = $roomCount + $otherCount; | ||
| 441 | if ( | ||
| 442 | $convertlpc::UPDATE_COUNT | ||
| 443 | && ( | ||
| 444 | ( | ||
| 445 | int ($currentCount / $convertlpc::UPDATE_COUNT) | ||
| 446 | == ($currentCount / $convertlpc::UPDATE_COUNT) | ||
| 447 | || $currentCount == $totalCount | ||
| 448 | ) | ||
| 449 | ) | ||
| 450 | ) { | ||
| 451 | $self->writeText( | ||
| 452 | ' Generated files: ' . $currentCount . '/' . $totalCount | ||
| 453 | . ', errors: ' . $errorCount, | ||
| 454 | ); | ||
| 455 | |||
| 456 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->do'); | ||
| 457 | } | ||
| 458 | |||
| 459 | if ($currentCount >= $convertlpc::MAX_FILES) { | ||
| 460 | |||
| 461 | # Don't create unlimited model objects | ||
| 462 | $self->writeText( | ||
| 463 | 'Reached file limit (' . $roomCount . '), not generating any more' | ||
| 464 | . ' files', | ||
| 465 | ); | ||
| 466 | |||
| 467 | last OUTER; | ||
| 468 | } | ||
| 469 | } | ||
| 470 | } | ||
| 471 | } | ||
| 472 | |||
| 473 | # Operation complete. Show a confirmation message | ||
| 474 | if (! $noWriteFlag) { | ||
| 475 | $msg = 'Conversion'; | ||
| 476 | } else { | ||
| 477 | $msg = 'Simulated conversion'; | ||
| 478 | } | ||
| 479 | |||
| 480 | return $self->complete( | ||
| 481 | $session, $standardCmd, | ||
| 482 | $msg . ' complete (regions: ' . scalar (keys %regionHash) . ', rooms: ' . $roomCount | ||
| 483 | . ', other objects: ' . $otherCount . ', errors: ' . $errorCount . ')', | ||
| 484 | ); | ||
| 485 | } | ||
| 486 | |||
| 487 | sub allocateRoomPath { | ||
| 488 | |||
| 489 | # Called by $self->do | ||
| 490 | # | ||
| 491 | # Every room in the world model is converted to a single LPC file. This function creates a | ||
| 492 | # unique filepath for each room (i.e. if there's already a | ||
| 493 | # '/domains/<world>/town/room/shop.c', then use a filepath like | ||
| 494 | # '/domains/<world>/town/room/shop2.c' instead) | ||
| 495 | # | ||
| 496 | # Expected arguments | ||
| 497 | # $usedHashRef - A hash in the form | ||
| 498 | # $usedHash{file_path} = undef | ||
| 499 | # $world - The current world's ->name | ||
| 500 | # $modRegionName - The parent region's (modified) name | ||
| 501 | # $roomObj - A GA::ModelObj::Room object in the world model | ||
| 502 | # | ||
| 503 | # Return values | ||
| 504 | # 'undef' on improper arguments | ||
| 505 | # 1 otherwise | ||
| 506 | |||
| 507 | my ($self, $usedHashRef, $world, $modRegionName, $roomObj, $check) = @_; | ||
| 508 | |||
| 509 | # Local variables | ||
| 510 | my ( | ||
| 511 | $title, $filePath, $modFilePath, | ||
| 512 | @wordList, @modList, | ||
| 513 | ); | ||
| 514 | |||
| 515 | # Check for improper arguments | ||
| 516 | if ( | ||
| 517 | ! defined $usedHashRef || ! defined $world || ! defined $modRegionName | ||
| 518 | || ! defined $roomObj || defined $check | ||
| 519 | ) { | ||
| 520 | return $axmud::CLIENT->writeImproper($self->_objClass . '->allocateRoomPath', @_); | ||
| 521 | } | ||
| 522 | |||
| 523 | # Convert the room title (brief description) into a suitable file-like string | ||
| 524 | $title = $roomObj->ivFirst('titleList'); | ||
| 525 | if (! $title) { | ||
| 526 | |||
| 527 | # The room's brief description is not stored in the world model | ||
| 528 | $title = 'genericroom'; | ||
| 529 | |||
| 530 | } else { | ||
| 531 | |||
| 532 | # Remove any non-alphanumeric characters | ||
| 533 | $title =~ s/[^\w\s]//; | ||
| 534 | |||
| 535 | # Split the room title into words, so that we can remove any words we don't want | ||
| 536 | @wordList = split(m/\s+/, lc($title)); | ||
| 537 | |||
| 538 | # Remove unwanted words like 'the', 'of', etc | ||
| 539 | foreach my $word (@wordList) { | ||
| 540 | |||
| 541 | if (! exists $convertlpc::REMOVE_HASH{$word}) { | ||
| 542 | |||
| 543 | push (@modList, $word); | ||
| 544 | } | ||
| 545 | } | ||
| 546 | |||
| 547 | if (! @modList) { | ||
| 548 | |||
| 549 | # Room's brief descrip inexplicably consists of nothing but articles like 'the' | ||
| 550 | @modList = ('genericroom'); | ||
| 551 | } | ||
| 552 | |||
| 553 | @wordList = @modList; | ||
| 554 | |||
| 555 | # Reduce the number of words used, if the global variable is set | ||
| 556 | if ( | ||
| 557 | $convertlpc::MAX_WORDS | ||
| 558 | && $convertlpc::MAX_WORDS < (scalar @wordList) | ||
| 559 | ) { | ||
| 560 | @modList = (); | ||
| 561 | |||
| 562 | for (my $count = 0; $count < $convertlpc::MAX_WORDS; $count++) { | ||
| 563 | |||
| 564 | push (@modList, $wordList[$count]); | ||
| 565 | } | ||
| 566 | |||
| 567 | @wordList = @modList; | ||
| 568 | } | ||
| 569 | |||
| 570 | if (! $convertlpc::NO_UNDERLINE_FLAG) { | ||
| 571 | $title = join('_', @wordList); | ||
| 572 | } else { | ||
| 573 | $title = join('', @wordList); | ||
| 574 | } | ||
| 575 | |||
| 576 | # Apply max characters to the file name | ||
| 577 | if (length ($title) > $convertlpc::MAX_FILE_NAME_SIZE) { | ||
| 578 | |||
| 579 | $title = substr($title, 0, $convertlpc::MAX_FILE_NAME_SIZE); | ||
| 580 | } | ||
| 581 | } | ||
| 582 | |||
| 583 | # Convert the filename into a filepath, e.g. convert 'start' into | ||
| 584 | # '/domains/<world>/town/room/start' | ||
| 585 | $filePath = '/domains/' . $modRegionName . '/' . $convertlpc::DIRECTORY_HASH{'room'} | ||
| 586 | . '/' . $title; | ||
| 587 | |||
| 588 | # If this file already exists, add a number to the file name to produce a unique file path | ||
| 589 | # (e.g. if 'start' is already used, try 'start2', 'start3', etc) | ||
| 590 | if (exists $$usedHashRef{$filePath}) { | ||
| 591 | |||
| 592 | $filePath = $self->modifyFilePath($usedHashRef, $filePath); | ||
| 593 | } | ||
| 594 | |||
| 595 | # Filepath generated | ||
| 596 | $$usedHashRef{$filePath} = undef; | ||
| 597 | |||
| 598 | return $filePath; | ||
| 599 | } | ||
| 600 | |||
| 601 | sub allocateChildPath { | ||
| 602 | |||
| 603 | # Called by $self->do | ||
| 604 | # | ||
| 605 | # Most objects in the world model are converted to a single LPC file. This function creates | ||
| 606 | # a unique filepath for each object (i.e. if there's already a | ||
| 607 | # '/domains/<world>/town/npc/orc.c', then use a filepath like | ||
| 608 | # '/domains/<world>/town/npc/orc2.c' instead) | ||
| 609 | # | ||
| 610 | # Expected arguments | ||
| 611 | # $usedHashRef - A hash in the form | ||
| 612 | # $usedHash{file_path} = undef | ||
| 613 | # $world - The current world's ->name | ||
| 614 | # $modRegionName - The parent region's (modified) name | ||
| 615 | # $childObj - A model object stored in one of the region's rooms (i.e. whose | ||
| 616 | # ->parent is that room) | ||
| 617 | # | ||
| 618 | # Return values | ||
| 619 | # 'undef' on improper arguments | ||
| 620 | # 1 otherwise | ||
| 621 | |||
| 622 | my ($self, $usedHashRef, $world, $modRegionName, $childObj, $check) = @_; | ||
| 623 | |||
| 624 | # Local variables | ||
| 625 | my ( | ||
| 626 | $title, $filePath, $modFilePath, | ||
| 627 | @wordList, @modList, | ||
| 628 | ); | ||
| 629 | |||
| 630 | # Check for improper arguments | ||
| 631 | if ( | ||
| 632 | ! defined $usedHashRef || ! defined $world || ! defined $modRegionName | ||
| 633 | || ! defined $childObj || defined $check | ||
| 634 | ) { | ||
| 635 | return $axmud::CLIENT->writeImproper($self->_objClass . '->allocateChildPath', @_); | ||
| 636 | } | ||
| 637 | |||
| 638 | # Convert the object's base string (e.g. 'big sword') into a suitable filename-like string | ||
| 639 | $title = $childObj->baseString; | ||
| 640 | |||
| 641 | # Remove any non-alphanumeric characters (just in case) | ||
| 642 | $title =~ s/[^\w\s]//; | ||
| 643 | |||
| 644 | # Split the title into words, so that we can remove any words we don't want | ||
| 645 | @wordList = split(m/\s+/, lc($title)); | ||
| 646 | |||
| 647 | # Remove unwanted words like 'the', 'of', etc | ||
| 648 | foreach my $word (@wordList) { | ||
| 649 | |||
| 650 | if (! exists $convertlpc::REMOVE_HASH{$word}) { | ||
| 651 | |||
| 652 | push (@modList, $word); | ||
| 653 | } | ||
| 654 | } | ||
| 655 | |||
| 656 | if (! @modList) { | ||
| 657 | |||
| 658 | # Object's base string inexplicably consists of nothing but articles like 'the' | ||
| 659 | @modList = ('genericroom'); | ||
| 660 | } | ||
| 661 | |||
| 662 | @wordList = @modList; | ||
| 663 | |||
| 664 | # Reduce the number of words used, if the global variable is set | ||
| 665 | if ( | ||
| 666 | $convertlpc::MAX_WORDS | ||
| 667 | && $convertlpc::MAX_WORDS < (scalar @wordList) | ||
| 668 | ) { | ||
| 669 | @modList = (); | ||
| 670 | |||
| 671 | for (my $count = 0; $count < $convertlpc::MAX_WORDS; $count++) { | ||
| 672 | |||
| 673 | push (@modList, $wordList[$count]); | ||
| 674 | } | ||
| 675 | |||
| 676 | @wordList = @modList; | ||
| 677 | } | ||
| 678 | |||
| 679 | if (! $convertlpc::NO_UNDERLINE_FLAG) { | ||
| 680 | $title = join('_', @wordList); | ||
| 681 | } else { | ||
| 682 | $title = join('', @wordList); | ||
| 683 | } | ||
| 684 | |||
| 685 | # Apply max characters to the file name | ||
| 686 | if (length ($title) > $convertlpc::MAX_FILE_NAME_SIZE) { | ||
| 687 | |||
| 688 | $title = substr($title, 0, $convertlpc::MAX_FILE_NAME_SIZE); | ||
| 689 | } | ||
| 690 | |||
| 691 | # Convert the filename into a filepath, e.g. convert 'orc' into | ||
| 692 | # '/domains/<world>/town/sentient/orc' | ||
| 693 | $filePath = '/domains/' . $modRegionName . '/' | ||
| 694 | . $convertlpc::DIRECTORY_HASH{$childObj->category} . '/' . $title; | ||
| 695 | |||
| 696 | # If this file already exists, add a number to the file name to produce a unique file path | ||
| 697 | # (e.g. if 'orc' is already used, try 'orc2', 'orc3', etc) | ||
| 698 | if (exists $$usedHashRef{$filePath}) { | ||
| 699 | |||
| 700 | $filePath = $self->modifyFilePath($usedHashRef, $filePath); | ||
| 701 | } | ||
| 702 | |||
| 703 | # Filepath generated | ||
| 704 | $$usedHashRef{$filePath} = undef; | ||
| 705 | |||
| 706 | return $filePath; | ||
| 707 | } | ||
| 708 | |||
| 709 | sub modifyFilePath { | ||
| 710 | |||
| 711 | # Called by $self->getFilePath | ||
| 712 | # | ||
| 713 | # The calling function generates a filepath, e.g. '/domains/town/room/start' or | ||
| 714 | # '/domains/<world>/town/npc/orc' | ||
| 715 | # If that filepath has already been allocated to another model object, modify the filepath | ||
| 716 | # by adding a unique number to it, until we find a filepath that's available (but we don't | ||
| 717 | # use random numbers: we want '.../start2', '.../start3', '.../start4'... not | ||
| 718 | # '.../start591', '.../start3819', '.../start99999' etc) | ||
| 719 | # Since there might be thousands of objects with the same title, this function uses an | ||
| 720 | # algorithm to find the first multiple of 100 ('.../start100', '.../start200', | ||
| 721 | # '.../start300' etc) that's available, and then starts checking 99 rooms before that | ||
| 722 | # ('.../start201', '.../start202' etc) | ||
| 723 | # Note that filepaths are allocated in the sequence '.../start', '.../start2', '.../start3', | ||
| 724 | # not in the sequence '.../start1', '.../start2', '.../start3' | ||
| 725 | # | ||
| 726 | # Expected arguments | ||
| 727 | # $usedHashRef - A hash in the form | ||
| 728 | # $fileHash{file_path} = undef | ||
| 729 | # $filePath - A filepath which is already in use by another object, e.g. | ||
| 730 | # '/domains/town/room/start' | ||
| 731 | # | ||
| 732 | # Return values | ||
| 733 | # 'undef' on improper arguments | ||
| 734 | # 1 otherwise | ||
| 735 | |||
| 736 | my ($self, $usedHashRef, $filePath, $check) = @_; | ||
| 737 | |||
| 738 | # Local variables | ||
| 739 | my ($count, $thisPath); | ||
| 740 | |||
| 741 | # Check for improper arguments | ||
| 742 | if (! defined $usedHashRef || ! defined $filePath || defined $check) { | ||
| 743 | |||
| 744 | return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyFilePath', @_); | ||
| 745 | } | ||
| 746 | |||
| 747 | # Find the first available multiple of 100 | ||
| 748 | $count = 0; | ||
| 749 | do { | ||
| 750 | |||
| 751 | $count += 100; | ||
| 752 | $thisPath = $filePath . $count; | ||
| 753 | |||
| 754 | } until (! exists $$usedHashRef{$thisPath}); | ||
| 755 | |||
| 756 | # Now, start checking 99 before that (but the first file after 'xxx' should be 'xxx2', | ||
| 757 | # not 'xxx1' | ||
| 758 | $count -= 100; # First do...until loop will add 1 | ||
| 759 | if (! $count) { | ||
| 760 | |||
| 761 | $count = 1; # First do...until loop will add 1 | ||
| 762 | } | ||
| 763 | |||
| 764 | do { | ||
| 765 | |||
| 766 | $count++; # So the first actual file that can ever be checked is, e.g. '.../start2' | ||
| 767 | |||
| 768 | $thisPath = $filePath . $count; | ||
| 769 | |||
| 770 | if (! exists $$usedHashRef{$thisPath}) { | ||
| 771 | |||
| 772 | # This filepath is available | ||
| 773 | return $thisPath; | ||
| 774 | } | ||
| 775 | |||
| 776 | } until (0); | ||
| 777 | } | ||
| 778 | |||
| 779 | sub compileRegionList { | ||
| 780 | |||
| 781 | # Called by $self->do | ||
| 782 | # | ||
| 783 | # Compiles a list of model region numbers, in which any child region is guaranteed to | ||
| 784 | # appear after its parent | ||
| 785 | # | ||
| 786 | # Expected arguments | ||
| 787 | # $session - The calling function's GA::Session | ||
| 788 | # | ||
| 789 | # Return values | ||
| 790 | # An empty list on improper arguments | ||
| 791 | # An ordered list of model region numbers on success (might be an empty list, if there are | ||
| 792 | # no regions in the world model) | ||
| 793 | |||
| 794 | my ($self, $session, $check) = @_; | ||
| 795 | |||
| 796 | # Local variables | ||
| 797 | my ( | ||
| 798 | @emptyList, @list, @returnList, | ||
| 799 | %parentHash, | ||
| 800 | ); | ||
| 801 | |||
| 802 | # Check for improper arguments | ||
| 803 | if (defined $check) { | ||
| 804 | |||
| 805 | $axmud::CLIENT->writeImproper($self->_objClass . '->compileRegionList', @_); | ||
| 806 | return @emptyList; | ||
| 807 | } | ||
| 808 | |||
| 809 | # Import the list of model region numbers | ||
| 810 | @list = $session->worldModelObj->ivKeys('regionModelHash'); | ||
| 811 | if (! @list) { | ||
| 812 | |||
| 813 | return @emptyList; | ||
| 814 | } | ||
| 815 | |||
| 816 | # Sort the list, so that parent regions always appear before their children | ||
| 817 | do { | ||
| 818 | |||
| 819 | my @modList; | ||
| 820 | |||
| 821 | foreach my $regionNum (@list) { | ||
| 822 | |||
| 823 | my $regionObj = $session->worldModelObj->ivShow('regionModelHash', $regionNum); | ||
| 824 | |||
| 825 | if ( | ||
| 826 | # This region has no parent | ||
| 827 | ! $regionObj->parent | ||
| 828 | # The region's parent has already been moved to @orderedList | ||
| 829 | || exists $parentHash{$regionObj->parent} | ||
| 830 | ) { | ||
| 831 | push (@returnList, $regionNum); | ||
| 832 | $parentHash{$regionNum} = undef; | ||
| 833 | |||
| 834 | } else { | ||
| 835 | |||
| 836 | # Try again on the next do.. loop, hoping that the region's parent region will | ||
| 837 | # by then have been moved to @returnList | ||
| 838 | push (@modList, $regionNum); | ||
| 839 | } | ||
| 840 | } | ||
| 841 | |||
| 842 | # Once every region has been added to @returnList, then @modList will be empty... | ||
| 843 | @list = @modList; | ||
| 844 | |||
| 845 | # ...allowing us to exit the do.. loop | ||
| 846 | } until (! @list); | ||
| 847 | |||
| 848 | return @returnList; | ||
| 849 | } | ||
| 850 | |||
| 851 | sub prepareRoom { | ||
| 852 | |||
| 853 | # Called by $self->do | ||
| 854 | # | ||
| 855 | # Prepares a list of strings for a single world model room, which will be written as a | ||
| 856 | # single LPC file | ||
| 857 | # (The code used is based on the Dead Souls room /domains/town/room/start.c) | ||
| 858 | # | ||
| 859 | # Expected arguments | ||
| 860 | # $session - The calling function's GA::Session | ||
| 861 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 862 | # in the form | ||
| 863 | # $convertHash{model_number} = file_path; | ||
| 864 | # $roomObj - The room model object to use | ||
| 865 | # | ||
| 866 | # Return values | ||
| 867 | # An empty list on improper arguments | ||
| 868 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 869 | # file | ||
| 870 | |||
| 871 | my ($self, $session, $convertHashRef, $roomObj, $check) = @_; | ||
| 872 | |||
| 873 | # Local variables | ||
| 874 | my ( | ||
| 875 | $day, $night, | ||
| 876 | @emptyList, @list, @childList, | ||
| 877 | ); | ||
| 878 | |||
| 879 | # Check for improper arguments | ||
| 880 | if ( | ||
| 881 | ! defined $session || ! defined $convertHashRef || ! defined $roomObj | ||
| 882 | || defined $check | ||
| 883 | ) { | ||
| 884 | $axmud::CLIENT->writeImproper($self->_objClass . '->prepareRoom', @_); | ||
| 885 | return @emptyList; | ||
| 886 | } | ||
| 887 | |||
| 888 | # #include <lib.h> | ||
| 889 | # #include <terrain_types.h> | ||
| 890 | # | ||
| 891 | # inherit LIB_ROOM; | ||
| 892 | # | ||
| 893 | push (@list, | ||
| 894 | '#include <lib.h>', | ||
| 895 | '#include <terrain_types.h>', | ||
| 896 | ' ', | ||
| 897 | 'inherit LIB_ROOM;', | ||
| 898 | ' ', | ||
| 899 | ); | ||
| 900 | |||
| 901 | # static void create() { | ||
| 902 | # room::create(); | ||
| 903 | # SetClimate("outdoors"); | ||
| 904 | # SetAmbientLight(30); | ||
| 905 | push (@list, | ||
| 906 | 'static void create() {', | ||
| 907 | ' room::create();', | ||
| 908 | ' SetClimate("outdoors");', | ||
| 909 | ' SetAmbientLight(30);', | ||
| 910 | ); | ||
| 911 | |||
| 912 | # SetShort("Village Road Intersection"); | ||
| 913 | if ($roomObj->titleList) { | ||
| 914 | |||
| 915 | # Use the first available room title (brief description) | ||
| 916 | push (@list, | ||
| 917 | ' SetShort("' . $roomObj->ivFirst('titleList') . '");', | ||
| 918 | ); | ||
| 919 | |||
| 920 | } else { | ||
| 921 | |||
| 922 | # Use a generic room title | ||
| 923 | push (@list, | ||
| 924 | ' SetShort("Generic room");', | ||
| 925 | ); | ||
| 926 | } | ||
| 927 | |||
| 928 | # SetNightLong("You are in the main intersection of the village, lit by..."); | ||
| 929 | # SetDayLong("You are in the main intersection of the village..."); | ||
| 930 | if ($roomObj->ivExists('descripHash', 'day')) { | ||
| 931 | $day = $roomObj->ivShow('descripHash', 'day'); | ||
| 932 | } else { | ||
| 933 | $day = 'Generic description'; | ||
| 934 | } | ||
| 935 | |||
| 936 | if ($roomObj->ivExists('descripHash', 'night')) { | ||
| 937 | |||
| 938 | $night = $roomObj->ivShow('descripHash', 'night'); | ||
| 939 | |||
| 940 | } else { | ||
| 941 | |||
| 942 | # If a separate description for night hours isn't known, use the description seen | ||
| 943 | # used in daylight hours | ||
| 944 | $night = $day; | ||
| 945 | } | ||
| 946 | |||
| 947 | push (@list, | ||
| 948 | ' SetNightLong("' . $night . '");', | ||
| 949 | ' SetDayLong("' . $night . '");', | ||
| 950 | ); | ||
| 951 | |||
| 952 | # SetItems( ([ ]) ); | ||
| 953 | push (@list, | ||
| 954 | ' SetItems( ([ ]) );', | ||
| 955 | ); | ||
| 956 | |||
| 957 | # SetExits( ([ | ||
| 958 | # "south" : "/domains/town/room/south_road1", | ||
| 959 | # "east" : "/domains/town/room/vill_road2", | ||
| 960 | # "west" : "/domains/town/room/road1", | ||
| 961 | # "north" : "/domains/town/room/road0.c", | ||
| 962 | # ]) ); | ||
| 963 | push (@list, | ||
| 964 | ' SetExits( ([', | ||
| 965 | ); | ||
| 966 | |||
| 967 | foreach my $dir ($roomObj->ivKeys('exitNumHash')) { | ||
| 968 | |||
| 969 | my ($exitNum, $exitObj, $destRoomNum, $destRoomObj, $destRoomPath); | ||
| 970 | |||
| 971 | $exitNum = $roomObj->ivShow('exitNumHash', $dir); | ||
| 972 | $exitObj = $session->worldModelObj->ivShow('exitModelHash', $exitNum); | ||
| 973 | |||
| 974 | if ($exitObj->destRoom) { | ||
| 975 | |||
| 976 | $destRoomNum = $exitObj->destRoom; | ||
| 977 | $destRoomObj = $session->worldModelObj->ivShow('modelHash', $destRoomNum); | ||
| 978 | $destRoomPath = $$convertHashRef{$destRoomNum}; | ||
| 979 | |||
| 980 | } else { | ||
| 981 | |||
| 982 | $destRoomPath = ""; # Exit goes nowhere | ||
| 983 | } | ||
| 984 | |||
| 985 | push (@list, | ||
| 986 | ' "' . $dir . '" : "' . $destRoomPath . '",', | ||
| 987 | ); | ||
| 988 | } | ||
| 989 | |||
| 990 | push (@list, | ||
| 991 | ' ]) );', | ||
| 992 | ); | ||
| 993 | |||
| 994 | # AddTerrainType(T_ROAD); | ||
| 995 | # (Use this only if the room has a room flag which marks it as a road) | ||
| 996 | if ( | ||
| 997 | $roomObj->ivExists('roomFlagHash', 'main_route') | ||
| 998 | || $roomObj->ivExists('roomFlagHash', 'minor_route') | ||
| 999 | || $roomObj->ivExists('roomFlagHash', 'cross_route') | ||
| 1000 | ) { | ||
| 1001 | push (@list, | ||
| 1002 | ' AddTerrainType(T_ROAD);', | ||
| 1003 | ); | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | # SetInventory( ([ ]) ); | ||
| 1007 | # (Not all child objects are converted to LPC files. Get a list of those that are) | ||
| 1008 | foreach my $childNum ($roomObj->ivKeys('childHash')) { | ||
| 1009 | |||
| 1010 | if (exists $$convertHashRef{$childNum}) { | ||
| 1011 | |||
| 1012 | push (@childList, $childNum); | ||
| 1013 | } | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | if (! @childList) { | ||
| 1017 | |||
| 1018 | # (No child objects to convert) | ||
| 1019 | push (@list, | ||
| 1020 | ' SetInventory( ([ ]) );', | ||
| 1021 | ); | ||
| 1022 | |||
| 1023 | } else { | ||
| 1024 | |||
| 1025 | # (Convert at least one child object) | ||
| 1026 | push (@list, | ||
| 1027 | ' SetInventory( ([', | ||
| 1028 | ); | ||
| 1029 | |||
| 1030 | foreach my $childNum (@childList) { | ||
| 1031 | |||
| 1032 | push (@list, | ||
| 1033 | ' "' . $$convertHashRef{$childNum} . '" : 1,', | ||
| 1034 | ); | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | push (@list, | ||
| 1038 | ' ]) );', | ||
| 1039 | ); | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | # SetNoModify(0); | ||
| 1043 | # SetEnters( ([ ]) ); | ||
| 1044 | # } | ||
| 1045 | # | ||
| 1046 | # void init(){ | ||
| 1047 | # ::init(); | ||
| 1048 | # } | ||
| 1049 | push (@list, | ||
| 1050 | ' SetNoModify(0);', | ||
| 1051 | ' SetEnters( ([ ]) );', | ||
| 1052 | '}', | ||
| 1053 | '', | ||
| 1054 | 'void init(){', | ||
| 1055 | ' ::init();', | ||
| 1056 | '}', | ||
| 1057 | ); | ||
| 1058 | |||
| 1059 | # Operation complete | ||
| 1060 | return @list; | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | sub prepareWeapon { | ||
| 1064 | |||
| 1065 | # Called by $self->do | ||
| 1066 | # | ||
| 1067 | # Prepares a list of strings for a single world model weapon, which will be written as a | ||
| 1068 | # single LPC file | ||
| 1069 | # (The code used is based on the Dead Souls object /domains/town/weap/sword.c) | ||
| 1070 | # | ||
| 1071 | # Expected arguments | ||
| 1072 | # $session - The calling function's GA::Session | ||
| 1073 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 1074 | # in the form | ||
| 1075 | # $convertHash{model_number} = file_path; | ||
| 1076 | # $modelObj - The weapon model object to use | ||
| 1077 | # | ||
| 1078 | # Return values | ||
| 1079 | # An empty list on improper arguments | ||
| 1080 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 1081 | # file | ||
| 1082 | |||
| 1083 | my ($self, $session, $convertHashRef, $modelObj, $check) = @_; | ||
| 1084 | |||
| 1085 | # Local variables | ||
| 1086 | my ( | ||
| 1087 | $adjString, $shortString, $longString, $weightString, $valueString, | ||
| 1088 | @emptyList, @list, | ||
| 1089 | ); | ||
| 1090 | |||
| 1091 | # Check for improper arguments | ||
| 1092 | if ( | ||
| 1093 | ! defined $session || ! defined $convertHashRef || ! defined $modelObj | ||
| 1094 | || defined $check | ||
| 1095 | ) { | ||
| 1096 | $axmud::CLIENT->writeImproper($self->_objClass . '->prepareWeapon', @_); | ||
| 1097 | return @emptyList; | ||
| 1098 | } | ||
| 1099 | |||
| 1100 | # #include <lib.h> | ||
| 1101 | # #include <damage_types.h> | ||
| 1102 | # #include <vendor_types.h> | ||
| 1103 | # | ||
| 1104 | # inherit LIB_ITEM; | ||
| 1105 | # | ||
| 1106 | push (@list, | ||
| 1107 | '#include <lib.h>', | ||
| 1108 | '#include <damage_types.h>', | ||
| 1109 | '#include <vendor_types.h>', | ||
| 1110 | ' ', | ||
| 1111 | 'inherit LIB_ITEM;', | ||
| 1112 | ' ', | ||
| 1113 | ); | ||
| 1114 | |||
| 1115 | # static void create() { | ||
| 1116 | # item::create(); | ||
| 1117 | push (@list, | ||
| 1118 | 'static void create() {', | ||
| 1119 | ' item::create();', | ||
| 1120 | ); | ||
| 1121 | |||
| 1122 | # SetKeyName("short sword"); | ||
| 1123 | # SetId( ({ "sword", "short sword" }) ); | ||
| 1124 | push (@list, | ||
| 1125 | ' SetKeyName("' . $modelObj->baseString . '");', | ||
| 1126 | ' SetId( ({ "' . $modelObj->noun . '", "' . $modelObj->baseString . '" }) );', | ||
| 1127 | ); | ||
| 1128 | |||
| 1129 | # SetAdjectives( ({ "short" }) ); | ||
| 1130 | foreach my $adj ($modelObj->adjList) { | ||
| 1131 | |||
| 1132 | if ($adjString) { | ||
| 1133 | |||
| 1134 | $adjString .= ', '; | ||
| 1135 | } | ||
| 1136 | |||
| 1137 | $adjString = '"' . $adj . '"'; | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | if (! $adjString) { | ||
| 1141 | |||
| 1142 | push (@list, | ||
| 1143 | ' SetAdjectives();', | ||
| 1144 | ); | ||
| 1145 | |||
| 1146 | } else { | ||
| 1147 | |||
| 1148 | push (@list, | ||
| 1149 | ' SetAdjectives( ({ ' . $adjString . '}) );', | ||
| 1150 | ); | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | # SetShort("a short sword"); | ||
| 1154 | if ($modelObj->baseString =~ m/^[AEIOUaeiou]/) { | ||
| 1155 | $shortString = 'an ' . $modelObj->baseString; | ||
| 1156 | } else { | ||
| 1157 | $shortString = 'a ' . $modelObj->baseString; | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | push (@list, | ||
| 1161 | ' SetShort("' . $shortString . '");', | ||
| 1162 | ); | ||
| 1163 | |||
| 1164 | # SetLong("A cheap and rather dull short sword."); | ||
| 1165 | if ($modelObj->descrip) { | ||
| 1166 | $longString = $modelObj->descrip; | ||
| 1167 | } else { | ||
| 1168 | $longString = $convertlpc::NULL_OBJ_DESCRIP; | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | push (@list, | ||
| 1172 | ' SetLong("' . $longString . '");', | ||
| 1173 | ); | ||
| 1174 | |||
| 1175 | # SetMass(300); | ||
| 1176 | if ($modelObj->weight) { | ||
| 1177 | $weightString = $modelObj->weight; | ||
| 1178 | } else { | ||
| 1179 | $weightString = $convertlpc::DEFAULT_WEIGHT; | ||
| 1180 | } | ||
| 1181 | |||
| 1182 | push (@list, | ||
| 1183 | ' SetMass(' . $weightString . ');', | ||
| 1184 | ); | ||
| 1185 | |||
| 1186 | # SetBaseCost("silver", 800); | ||
| 1187 | if ($modelObj->buyValue) { | ||
| 1188 | $valueString = $modelObj->buyValue; | ||
| 1189 | } elsif ($modelObj->sellValue) { | ||
| 1190 | $valueString = $modelObj->sellValue; | ||
| 1191 | } else { | ||
| 1192 | $valueString = $convertlpc::DEFAULT_VALUE; | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | push (@list, | ||
| 1196 | ' SetBaseCost("' . $convertlpc::DEFAULT_CURRENCY . '", ' . $valueString . ');', | ||
| 1197 | ); | ||
| 1198 | |||
| 1199 | # SetVendorType(VT_WEAPON); | ||
| 1200 | # SetClass(30); | ||
| 1201 | # SetDamageType(BLADE); | ||
| 1202 | # SetWeaponType("blade"); | ||
| 1203 | # } | ||
| 1204 | # | ||
| 1205 | # void init(){ | ||
| 1206 | # ::init(); | ||
| 1207 | # } | ||
| 1208 | push (@list, | ||
| 1209 | ' SetVendorType(VT_WEAPON);', | ||
| 1210 | ' SetClass(30);', | ||
| 1211 | ' SetDamageType(BLADE);', | ||
| 1212 | ' SetWeaponType("blade");', | ||
| 1213 | '}', | ||
| 1214 | '', | ||
| 1215 | 'void init(){', | ||
| 1216 | ' ::init();', | ||
| 1217 | '}', | ||
| 1218 | ); | ||
| 1219 | |||
| 1220 | # Operation complete | ||
| 1221 | return @list; | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | sub prepareArmour { | ||
| 1225 | |||
| 1226 | # Called by $self->do | ||
| 1227 | # | ||
| 1228 | # Prepares a list of strings for a single world model armour, which will be written as a | ||
| 1229 | # single LPC file | ||
| 1230 | # (The code used is based on the Dead Souls object /domains/town/armor/chainmail.c) | ||
| 1231 | # | ||
| 1232 | # Expected arguments | ||
| 1233 | # $session - The calling function's GA::Session | ||
| 1234 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 1235 | # in the form | ||
| 1236 | # $convertHash{model_number} = file_path; | ||
| 1237 | # $modelObj - The weapon model object to use | ||
| 1238 | # | ||
| 1239 | # Return values | ||
| 1240 | # An empty list on improper arguments | ||
| 1241 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 1242 | # file | ||
| 1243 | |||
| 1244 | my ($self, $session, $convertHashRef, $modelObj, $check) = @_; | ||
| 1245 | |||
| 1246 | # Local variables | ||
| 1247 | my ( | ||
| 1248 | $adjString, $shortString, $longString, $weightString, $valueString, | ||
| 1249 | @emptyList, @list, | ||
| 1250 | ); | ||
| 1251 | |||
| 1252 | # Check for improper arguments | ||
| 1253 | if ( | ||
| 1254 | ! defined $session || ! defined $convertHashRef || ! defined $modelObj | ||
| 1255 | || defined $check | ||
| 1256 | ) { | ||
| 1257 | $axmud::CLIENT->writeImproper($self->_objClass . '->prepareArmour', @_); | ||
| 1258 | return @emptyList; | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | # #include <lib.h> | ||
| 1262 | # #include <armor_types.h> | ||
| 1263 | # #include <damage_types.h> | ||
| 1264 | # | ||
| 1265 | # inherit LIB_ARMOR; | ||
| 1266 | # | ||
| 1267 | push (@list, | ||
| 1268 | '#include <lib.h>', | ||
| 1269 | '#include <armor_types.h>', | ||
| 1270 | '#include <damage_types.h>', | ||
| 1271 | ' ', | ||
| 1272 | 'inherit LIB_ARMOR;', | ||
| 1273 | ' ', | ||
| 1274 | ); | ||
| 1275 | |||
| 1276 | # static void create() { | ||
| 1277 | # armor::create(); | ||
| 1278 | push (@list, | ||
| 1279 | 'static void create() {', | ||
| 1280 | ' armor::create();', | ||
| 1281 | ); | ||
| 1282 | |||
| 1283 | # SetKeyName("chainmail shirt"); | ||
| 1284 | # SetId( ({ "shirt", "chainmail shirt" }) ); | ||
| 1285 | push (@list, | ||
| 1286 | ' SetKeyName("' . $modelObj->baseString . '");', | ||
| 1287 | ' SetId( ({ "' . $modelObj->noun . '", "' . $modelObj->baseString . '" }) );', | ||
| 1288 | ); | ||
| 1289 | |||
| 1290 | # SetAdjectives( ({ "chainmail" }) ); | ||
| 1291 | foreach my $adj ($modelObj->adjList) { | ||
| 1292 | |||
| 1293 | if ($adjString) { | ||
| 1294 | |||
| 1295 | $adjString .= ', '; | ||
| 1296 | } | ||
| 1297 | |||
| 1298 | $adjString = '"' . $adj . '"'; | ||
| 1299 | } | ||
| 1300 | |||
| 1301 | if (! $adjString) { | ||
| 1302 | |||
| 1303 | push (@list, | ||
| 1304 | ' SetAdjectives();', | ||
| 1305 | ); | ||
| 1306 | |||
| 1307 | } else { | ||
| 1308 | |||
| 1309 | push (@list, | ||
| 1310 | ' SetAdjectives( ({ ' . $adjString . '}) );', | ||
| 1311 | ); | ||
| 1312 | } | ||
| 1313 | |||
| 1314 | # SetShort("a chainmail shirt"); | ||
| 1315 | if ($modelObj->baseString =~ m/^[AEIOUaeiou]/) { | ||
| 1316 | $shortString = 'an ' . $modelObj->baseString; | ||
| 1317 | } else { | ||
| 1318 | $shortString = 'a ' . $modelObj->baseString; | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | push (@list, | ||
| 1322 | ' SetShort("' . $shortString . '");', | ||
| 1323 | ); | ||
| 1324 | |||
| 1325 | # SetLong("This is a shirt made of small, thin metal rings fashioned together as armor."); | ||
| 1326 | if ($modelObj->descrip) { | ||
| 1327 | $longString = $modelObj->descrip; | ||
| 1328 | } else { | ||
| 1329 | $longString = $convertlpc::NULL_OBJ_DESCRIP; | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | push (@list, | ||
| 1333 | ' SetLong("' . $longString . '");', | ||
| 1334 | ); | ||
| 1335 | |||
| 1336 | # SetMass(200); | ||
| 1337 | if ($modelObj->weight) { | ||
| 1338 | $weightString = $modelObj->weight; | ||
| 1339 | } else { | ||
| 1340 | $weightString = $convertlpc::DEFAULT_WEIGHT; | ||
| 1341 | } | ||
| 1342 | |||
| 1343 | push (@list, | ||
| 1344 | ' SetMass(' . $weightString . ');', | ||
| 1345 | ); | ||
| 1346 | |||
| 1347 | # SetBaseCost("silver", 800); | ||
| 1348 | if ($modelObj->buyValue) { | ||
| 1349 | $valueString = $modelObj->buyValue; | ||
| 1350 | } elsif ($modelObj->sellValue) { | ||
| 1351 | $valueString = $modelObj->sellValue; | ||
| 1352 | } else { | ||
| 1353 | $valueString = $convertlpc::DEFAULT_VALUE; | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | push (@list, | ||
| 1357 | ' SetBaseCost("' . $convertlpc::DEFAULT_CURRENCY . '", ' . $valueString . ');', | ||
| 1358 | ); | ||
| 1359 | |||
| 1360 | # SetProtection(BLUNT,5); | ||
| 1361 | # SetProtection(BLADE,20); | ||
| 1362 | # SetProtection(KNIFE,20); | ||
| 1363 | # SetArmorType(A_ARMOR); | ||
| 1364 | # } | ||
| 1365 | # | ||
| 1366 | # void init(){ | ||
| 1367 | # ::init(); | ||
| 1368 | # } | ||
| 1369 | push (@list, | ||
| 1370 | ' SetProtection(BLUNT,5);', | ||
| 1371 | ' SetProtection(BLADE,20);', | ||
| 1372 | ' SetProtection(KNIFE,20);', | ||
| 1373 | ' SetArmorType(A_ARMOR);', | ||
| 1374 | '}', | ||
| 1375 | '', | ||
| 1376 | 'void init(){', | ||
| 1377 | ' ::init();', | ||
| 1378 | '}', | ||
| 1379 | ); | ||
| 1380 | |||
| 1381 | # Operation complete | ||
| 1382 | return @list; | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | sub prepareGarment { | ||
| 1386 | |||
| 1387 | # Called by $self->do | ||
| 1388 | # | ||
| 1389 | # Prepares a list of strings for a single world model garment, which will be written as a | ||
| 1390 | # single LPC file | ||
| 1391 | # (The code used is based on the Dead Souls object /domains/town/armor/shirt.c) | ||
| 1392 | # | ||
| 1393 | # Expected arguments | ||
| 1394 | # $session - The calling function's GA::Session | ||
| 1395 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 1396 | # in the form | ||
| 1397 | # $convertHash{model_number} = file_path; | ||
| 1398 | # $modelObj - The weapon model object to use | ||
| 1399 | # | ||
| 1400 | # Return values | ||
| 1401 | # An empty list on improper arguments | ||
| 1402 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 1403 | # file | ||
| 1404 | |||
| 1405 | my ($self, $session, $convertHashRef, $modelObj, $check) = @_; | ||
| 1406 | |||
| 1407 | # Local variables | ||
| 1408 | my ( | ||
| 1409 | $adjString, $shortString, $longString, $weightString, $valueString, | ||
| 1410 | @emptyList, @list, | ||
| 1411 | ); | ||
| 1412 | |||
| 1413 | # Check for improper arguments | ||
| 1414 | if ( | ||
| 1415 | ! defined $session || ! defined $convertHashRef || ! defined $modelObj | ||
| 1416 | || defined $check | ||
| 1417 | ) { | ||
| 1418 | $axmud::CLIENT->writeImproper($self->_objClass . '->prepareGarment', @_); | ||
| 1419 | return @emptyList; | ||
| 1420 | } | ||
| 1421 | |||
| 1422 | # #include <lib.h> | ||
| 1423 | # #include <armor_types.h> | ||
| 1424 | # #include <damage_types.h> | ||
| 1425 | # | ||
| 1426 | # inherit LIB_ARMOR; | ||
| 1427 | # | ||
| 1428 | push (@list, | ||
| 1429 | '#include <lib.h>', | ||
| 1430 | '#include <armor_types.h>', | ||
| 1431 | '#include <damage_types.h>', | ||
| 1432 | ' ', | ||
| 1433 | 'inherit LIB_ARMOR;', | ||
| 1434 | ' ', | ||
| 1435 | ); | ||
| 1436 | |||
| 1437 | # static void create() { | ||
| 1438 | # armor::create(); | ||
| 1439 | push (@list, | ||
| 1440 | 'static void create() {', | ||
| 1441 | ' armor::create();', | ||
| 1442 | ); | ||
| 1443 | |||
| 1444 | # SetKeyName("a white t-shirt"); | ||
| 1445 | # SetId( ({ "t-shirt", "white t-shirt" }) ); | ||
| 1446 | push (@list, | ||
| 1447 | ' SetKeyName("' . $modelObj->baseString . '");', | ||
| 1448 | ' SetId( ({ "' . $modelObj->noun . '", "' . $modelObj->baseString . '" }) );', | ||
| 1449 | ); | ||
| 1450 | |||
| 1451 | # SetAdjectives( ({ "white" }) ); | ||
| 1452 | foreach my $adj ($modelObj->adjList) { | ||
| 1453 | |||
| 1454 | if ($adjString) { | ||
| 1455 | |||
| 1456 | $adjString .= ', '; | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | $adjString = '"' . $adj . '"'; | ||
| 1460 | } | ||
| 1461 | |||
| 1462 | if (! $adjString) { | ||
| 1463 | |||
| 1464 | push (@list, | ||
| 1465 | ' SetAdjectives();', | ||
| 1466 | ); | ||
| 1467 | |||
| 1468 | } else { | ||
| 1469 | |||
| 1470 | push (@list, | ||
| 1471 | ' SetAdjectives( ({ ' . $adjString . '}) );', | ||
| 1472 | ); | ||
| 1473 | } | ||
| 1474 | |||
| 1475 | # SetShort("a white t-shirt"); | ||
| 1476 | if ($modelObj->baseString =~ m/^[AEIOUaeiou]/) { | ||
| 1477 | $shortString = 'an ' . $modelObj->baseString; | ||
| 1478 | } else { | ||
| 1479 | $shortString = 'a ' . $modelObj->baseString; | ||
| 1480 | } | ||
| 1481 | |||
| 1482 | push (@list, | ||
| 1483 | ' SetShort("' . $shortString . '");', | ||
| 1484 | ); | ||
| 1485 | |||
| 1486 | # SetLong("An ordinary white t-shirt."); | ||
| 1487 | if ($modelObj->descrip) { | ||
| 1488 | $longString = $modelObj->descrip; | ||
| 1489 | } else { | ||
| 1490 | $longString = $convertlpc::NULL_OBJ_DESCRIP; | ||
| 1491 | } | ||
| 1492 | |||
| 1493 | push (@list, | ||
| 1494 | ' SetLong("' . $longString . '");', | ||
| 1495 | ); | ||
| 1496 | |||
| 1497 | # SetMass(2); | ||
| 1498 | if ($modelObj->weight) { | ||
| 1499 | $weightString = $modelObj->weight; | ||
| 1500 | } else { | ||
| 1501 | $weightString = $convertlpc::DEFAULT_WEIGHT; | ||
| 1502 | } | ||
| 1503 | |||
| 1504 | push (@list, | ||
| 1505 | ' SetMass(' . $weightString . ');', | ||
| 1506 | ); | ||
| 1507 | |||
| 1508 | # SetBaseCost("silver", 1); | ||
| 1509 | if ($modelObj->buyValue) { | ||
| 1510 | $valueString = $modelObj->buyValue; | ||
| 1511 | } elsif ($modelObj->sellValue) { | ||
| 1512 | $valueString = $modelObj->sellValue; | ||
| 1513 | } else { | ||
| 1514 | $valueString = $convertlpc::DEFAULT_VALUE; | ||
| 1515 | } | ||
| 1516 | |||
| 1517 | push (@list, | ||
| 1518 | ' SetBaseCost("' . $convertlpc::DEFAULT_CURRENCY . '", ' . $valueString . ');', | ||
| 1519 | ); | ||
| 1520 | |||
| 1521 | # SetArmorType(A_SHIRT); | ||
| 1522 | # } | ||
| 1523 | # | ||
| 1524 | # void init(){ | ||
| 1525 | # ::init(); | ||
| 1526 | # } | ||
| 1527 | push (@list, | ||
| 1528 | ' SetArmorType(A_SHIRT);', | ||
| 1529 | '}', | ||
| 1530 | '', | ||
| 1531 | 'void init(){', | ||
| 1532 | ' ::init();', | ||
| 1533 | '}', | ||
| 1534 | ); | ||
| 1535 | |||
| 1536 | # Operation complete | ||
| 1537 | return @list; | ||
| 1538 | } | ||
| 1539 | |||
| 1540 | sub prepareSentient { | ||
| 1541 | |||
| 1542 | # Called by $self->do | ||
| 1543 | # | ||
| 1544 | # Prepares a list of strings for a single world model sentient, which will be written as a | ||
| 1545 | # single LPC file | ||
| 1546 | # (The code used is based on the Dead Souls object /domains/town/npc/beggar.c) | ||
| 1547 | # | ||
| 1548 | # Expected arguments | ||
| 1549 | # $session - The calling function's GA::Session | ||
| 1550 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 1551 | # in the form | ||
| 1552 | # $convertHash{model_number} = file_path; | ||
| 1553 | # $modelObj - The weapon model object to use | ||
| 1554 | # | ||
| 1555 | # Return values | ||
| 1556 | # An empty list on improper arguments | ||
| 1557 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 1558 | # file | ||
| 1559 | |||
| 1560 | my ($self, $session, $convertHashRef, $modelObj, $check) = @_; | ||
| 1561 | |||
| 1562 | # Local variables | ||
| 1563 | my ( | ||
| 1564 | $adjString, $shortString, $longString, $raceString, | ||
| 1565 | @emptyList, @list, | ||
| 1566 | ); | ||
| 1567 | |||
| 1568 | # Check for improper arguments | ||
| 1569 | if ( | ||
| 1570 | ! defined $session || ! defined $convertHashRef || ! defined $modelObj | ||
| 1571 | || defined $check | ||
| 1572 | ) { | ||
| 1573 | $axmud::CLIENT->writeImproper($self->_objClass . '->prepareSentient', @_); | ||
| 1574 | return @emptyList; | ||
| 1575 | } | ||
| 1576 | |||
| 1577 | # #include <lib.h> | ||
| 1578 | # | ||
| 1579 | # inherit LIB_SENTIENT; | ||
| 1580 | # | ||
| 1581 | push (@list, | ||
| 1582 | '#include <lib.h>', | ||
| 1583 | ' ', | ||
| 1584 | 'inherit LIB_SENTIENT;', | ||
| 1585 | ' ', | ||
| 1586 | ); | ||
| 1587 | |||
| 1588 | # static void create() { | ||
| 1589 | # sentient::create(); | ||
| 1590 | push (@list, | ||
| 1591 | 'static void create() {', | ||
| 1592 | ' sentient::create();', | ||
| 1593 | ); | ||
| 1594 | |||
| 1595 | # SetKeyName("beggar"); | ||
| 1596 | # SetId( ({ "beggar" }) ); | ||
| 1597 | push (@list, | ||
| 1598 | ' SetKeyName("' . $modelObj->baseString . '");', | ||
| 1599 | ' SetId( ({ "' . $modelObj->noun . '", "' . $modelObj->baseString . '" }) );', | ||
| 1600 | ); | ||
| 1601 | |||
| 1602 | # SetAdjectives( ({ "dirty" }) ); | ||
| 1603 | foreach my $adj ($modelObj->adjList) { | ||
| 1604 | |||
| 1605 | if ($adjString) { | ||
| 1606 | |||
| 1607 | $adjString .= ', '; | ||
| 1608 | } | ||
| 1609 | |||
| 1610 | $adjString = '"' . $adj . '"'; | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | if (! $adjString) { | ||
| 1614 | |||
| 1615 | push (@list, | ||
| 1616 | ' SetAdjectives();', | ||
| 1617 | ); | ||
| 1618 | |||
| 1619 | } else { | ||
| 1620 | |||
| 1621 | push (@list, | ||
| 1622 | ' SetAdjectives( ({ ' . $adjString . '}) );', | ||
| 1623 | ); | ||
| 1624 | } | ||
| 1625 | |||
| 1626 | # SetShort("a dirty beggar"); | ||
| 1627 | if ($modelObj->baseString =~ m/^[AEIOUaeiou]/) { | ||
| 1628 | $shortString = 'an ' . $modelObj->baseString; | ||
| 1629 | } else { | ||
| 1630 | $shortString = 'a ' . $modelObj->baseString; | ||
| 1631 | } | ||
| 1632 | |||
| 1633 | push (@list, | ||
| 1634 | ' SetShort("' . $shortString . '");', | ||
| 1635 | ); | ||
| 1636 | |||
| 1637 | # SetLong("This beggar has something strangely noble about his aspect."); | ||
| 1638 | if ($modelObj->descrip) { | ||
| 1639 | $longString = $modelObj->descrip; | ||
| 1640 | } else { | ||
| 1641 | $longString = $convertlpc::NULL_OBJ_DESCRIP; | ||
| 1642 | } | ||
| 1643 | |||
| 1644 | push (@list, | ||
| 1645 | ' SetLong("' . $longString . '");', | ||
| 1646 | ); | ||
| 1647 | |||
| 1648 | # SetClass("fighter"); | ||
| 1649 | # SetLevel(1); | ||
| 1650 | # SetWimpy(0); | ||
| 1651 | # SetInventory( ([ ]) ); | ||
| 1652 | push (@list, | ||
| 1653 | ' SetClass("fighter");', | ||
| 1654 | ' SetLevel(' . $modelObj->level . ');', | ||
| 1655 | ' SetWimpy(0);', | ||
| 1656 | ' SetInventory( ([ ]) );', | ||
| 1657 | ); | ||
| 1658 | |||
| 1659 | # SetRace("human"); | ||
| 1660 | # SetGender("male"); | ||
| 1661 | if ($modelObj->race) { | ||
| 1662 | $raceString = $modelObj->race; | ||
| 1663 | } else { | ||
| 1664 | $raceString = $convertlpc::SENTIENT_DEFAULT_RACE; | ||
| 1665 | } | ||
| 1666 | |||
| 1667 | push (@list, | ||
| 1668 | ' SetRace("' . $raceString . '");', | ||
| 1669 | ' SetGender("' . $convertlpc::DEFAULT_GENDER . '");', | ||
| 1670 | ); | ||
| 1671 | |||
| 1672 | # SetPolyglot(1); | ||
| 1673 | # SetLanguage("common", 100); | ||
| 1674 | # SetDefaultLanguage("common"); | ||
| 1675 | push (@list, | ||
| 1676 | ' SetPolyglot(1);', | ||
| 1677 | ' SetLanguage("common", 100);', | ||
| 1678 | ' SetDefaultLanguage("common");', | ||
| 1679 | ); | ||
| 1680 | |||
| 1681 | # } | ||
| 1682 | # | ||
| 1683 | # void init(){ | ||
| 1684 | # ::init(); | ||
| 1685 | # } | ||
| 1686 | push (@list, | ||
| 1687 | '}', | ||
| 1688 | '', | ||
| 1689 | 'void init(){', | ||
| 1690 | ' ::init();', | ||
| 1691 | '}', | ||
| 1692 | ); | ||
| 1693 | |||
| 1694 | # Operation complete | ||
| 1695 | return @list; | ||
| 1696 | } | ||
| 1697 | |||
| 1698 | sub prepareCreature { | ||
| 1699 | |||
| 1700 | # Called by $self->do | ||
| 1701 | # | ||
| 1702 | # Prepares a list of strings for a single world model creature, which will be written as a | ||
| 1703 | # single LPC file | ||
| 1704 | # (The code used is based on the Dead Souls object /domains/town/npc/bear.c) | ||
| 1705 | # | ||
| 1706 | # Expected arguments | ||
| 1707 | # $session - The calling function's GA::Session | ||
| 1708 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 1709 | # in the form | ||
| 1710 | # $convertHash{model_number} = file_path; | ||
| 1711 | # $modelObj - The weapon model object to use | ||
| 1712 | # | ||
| 1713 | # Return values | ||
| 1714 | # An empty list on improper arguments | ||
| 1715 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 1716 | # file | ||
| 1717 | |||
| 1718 | my ($self, $session, $convertHashRef, $modelObj, $check) = @_; | ||
| 1719 | |||
| 1720 | # Local variables | ||
| 1721 | my ( | ||
| 1722 | $adjString, $shortString, $longString, $raceString, | ||
| 1723 | @emptyList, @list, | ||
| 1724 | ); | ||
| 1725 | |||
| 1726 | # Check for improper arguments | ||
| 1727 | if ( | ||
| 1728 | ! defined $session || ! defined $convertHashRef || ! defined $modelObj | ||
| 1729 | || defined $check | ||
| 1730 | ) { | ||
| 1731 | $axmud::CLIENT->writeImproper($self->_objClass . '->prepareCreature', @_); | ||
| 1732 | return @emptyList; | ||
| 1733 | } | ||
| 1734 | |||
| 1735 | # #include <lib.h> | ||
| 1736 | # | ||
| 1737 | # inherit LIB_SENTIENT; | ||
| 1738 | # | ||
| 1739 | push (@list, | ||
| 1740 | '#include <lib.h>', | ||
| 1741 | ' ', | ||
| 1742 | 'inherit LIB_SENTIENT;', | ||
| 1743 | ' ', | ||
| 1744 | ); | ||
| 1745 | |||
| 1746 | # static void create() { | ||
| 1747 | # sentient::create(); | ||
| 1748 | push (@list, | ||
| 1749 | 'static void create() {', | ||
| 1750 | ' sentient::create();', | ||
| 1751 | ); | ||
| 1752 | |||
| 1753 | # SetKeyName("bear"); | ||
| 1754 | # SetId( ({ "bear" }) ); | ||
| 1755 | push (@list, | ||
| 1756 | ' SetKeyName("' . $modelObj->baseString . '");', | ||
| 1757 | ' SetId( ({ "' . $modelObj->noun . '", "' . $modelObj->baseString . '" }) );', | ||
| 1758 | ); | ||
| 1759 | |||
| 1760 | # SetAdjectives( ({ "brown" }) ); | ||
| 1761 | foreach my $adj ($modelObj->adjList) { | ||
| 1762 | |||
| 1763 | if ($adjString) { | ||
| 1764 | |||
| 1765 | $adjString .= ', '; | ||
| 1766 | } | ||
| 1767 | |||
| 1768 | $adjString = '"' . $adj . '"'; | ||
| 1769 | } | ||
| 1770 | |||
| 1771 | if (! $adjString) { | ||
| 1772 | |||
| 1773 | push (@list, | ||
| 1774 | ' SetAdjectives();', | ||
| 1775 | ); | ||
| 1776 | |||
| 1777 | } else { | ||
| 1778 | |||
| 1779 | push (@list, | ||
| 1780 | ' SetAdjectives( ({ ' . $adjString . '}) );', | ||
| 1781 | ); | ||
| 1782 | } | ||
| 1783 | |||
| 1784 | # SetShort("a brown bear"); | ||
| 1785 | if ($modelObj->baseString =~ m/^[AEIOUaeiou]/) { | ||
| 1786 | $shortString = 'an ' . $modelObj->baseString; | ||
| 1787 | } else { | ||
| 1788 | $shortString = 'a ' . $modelObj->baseString; | ||
| 1789 | } | ||
| 1790 | |||
| 1791 | push (@list, | ||
| 1792 | ' SetShort("' . $shortString . '");', | ||
| 1793 | ); | ||
| 1794 | |||
| 1795 | # SetLong("A large brown bear. Not as huge as a grizzly."); | ||
| 1796 | if ($modelObj->descrip) { | ||
| 1797 | $longString = $modelObj->descrip; | ||
| 1798 | } else { | ||
| 1799 | $longString = $convertlpc::NULL_OBJ_DESCRIP; | ||
| 1800 | } | ||
| 1801 | |||
| 1802 | push (@list, | ||
| 1803 | ' SetLong("' . $longString . '");', | ||
| 1804 | ); | ||
| 1805 | |||
| 1806 | # SetClass("fighter"); | ||
| 1807 | # SetLevel(1); | ||
| 1808 | # SetWimpy(0); | ||
| 1809 | # SetInventory( ([ ]) ); | ||
| 1810 | push (@list, | ||
| 1811 | ' SetClass("fighter");', | ||
| 1812 | ' SetLevel(' . $modelObj->level . ');', | ||
| 1813 | ' SetWimpy(0);', | ||
| 1814 | ' SetInventory( ([ ]) );', | ||
| 1815 | ); | ||
| 1816 | |||
| 1817 | # SetRace("bear"); | ||
| 1818 | # SetGender("male"); | ||
| 1819 | if ($modelObj->race) { | ||
| 1820 | $raceString = $modelObj->race; | ||
| 1821 | } else { | ||
| 1822 | $raceString = $convertlpc::CREATURE_DEFAULT_RACE; | ||
| 1823 | } | ||
| 1824 | |||
| 1825 | push (@list, | ||
| 1826 | ' SetRace("' . $raceString . '");', | ||
| 1827 | ' SetGender("' . $convertlpc::DEFAULT_GENDER . '");', | ||
| 1828 | ); | ||
| 1829 | |||
| 1830 | # } | ||
| 1831 | # | ||
| 1832 | # void init(){ | ||
| 1833 | # ::init(); | ||
| 1834 | # } | ||
| 1835 | push (@list, | ||
| 1836 | '}', | ||
| 1837 | '', | ||
| 1838 | 'void init(){', | ||
| 1839 | ' ::init();', | ||
| 1840 | '}', | ||
| 1841 | ); | ||
| 1842 | |||
| 1843 | # Operation complete | ||
| 1844 | return @list; | ||
| 1845 | } | ||
| 1846 | |||
| 1847 | sub preparePortable { | ||
| 1848 | |||
| 1849 | # Called by $self->do | ||
| 1850 | # | ||
| 1851 | # Prepares a list of strings for a single world model portable, which will be written as a | ||
| 1852 | # single LPC file | ||
| 1853 | # (The code used is based on the Dead Souls object /domains/town/obj/maglite.c) | ||
| 1854 | # | ||
| 1855 | # Expected arguments | ||
| 1856 | # $session - The calling function's GA::Session | ||
| 1857 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 1858 | # in the form | ||
| 1859 | # $convertHash{model_number} = file_path; | ||
| 1860 | # $modelObj - The weapon model object to use | ||
| 1861 | # | ||
| 1862 | # Return values | ||
| 1863 | # An empty list on improper arguments | ||
| 1864 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 1865 | # file | ||
| 1866 | |||
| 1867 | my ($self, $session, $convertHashRef, $modelObj, $check) = @_; | ||
| 1868 | |||
| 1869 | # Local variables | ||
| 1870 | my ( | ||
| 1871 | $adjString, $shortString, $longString, $weightString, $valueString, | ||
| 1872 | @emptyList, @list, | ||
| 1873 | ); | ||
| 1874 | |||
| 1875 | # Check for improper arguments | ||
| 1876 | if ( | ||
| 1877 | ! defined $session || ! defined $convertHashRef || ! defined $modelObj | ||
| 1878 | || defined $check | ||
| 1879 | ) { | ||
| 1880 | $axmud::CLIENT->writeImproper($self->_objClass . '->preparePortable', @_); | ||
| 1881 | return @emptyList; | ||
| 1882 | } | ||
| 1883 | |||
| 1884 | # #include <lib.h> | ||
| 1885 | # | ||
| 1886 | # inherit LIB_ITEM; | ||
| 1887 | # | ||
| 1888 | push (@list, | ||
| 1889 | '#include <lib.h>', | ||
| 1890 | ' ', | ||
| 1891 | 'inherit LIB_ITEM;', | ||
| 1892 | ' ', | ||
| 1893 | ); | ||
| 1894 | |||
| 1895 | # static void create() { | ||
| 1896 | # item::create(); | ||
| 1897 | push (@list, | ||
| 1898 | 'static void create() {', | ||
| 1899 | ' item::create();', | ||
| 1900 | ); | ||
| 1901 | |||
| 1902 | # SetKeyName("match"); | ||
| 1903 | # SetId( ({ "wooden match" }) ); | ||
| 1904 | push (@list, | ||
| 1905 | ' SetKeyName("' . $modelObj->baseString . '");', | ||
| 1906 | ' SetId( ({ "' . $modelObj->noun . '", "' . $modelObj->baseString . '" }) );', | ||
| 1907 | ); | ||
| 1908 | |||
| 1909 | # SetAdjectives( ({ "wooden" }) ); | ||
| 1910 | foreach my $adj ($modelObj->adjList) { | ||
| 1911 | |||
| 1912 | if ($adjString) { | ||
| 1913 | |||
| 1914 | $adjString .= ', '; | ||
| 1915 | } | ||
| 1916 | |||
| 1917 | $adjString = '"' . $adj . '"'; | ||
| 1918 | } | ||
| 1919 | |||
| 1920 | if (! $adjString) { | ||
| 1921 | |||
| 1922 | push (@list, | ||
| 1923 | ' SetAdjectives();', | ||
| 1924 | ); | ||
| 1925 | |||
| 1926 | } else { | ||
| 1927 | |||
| 1928 | push (@list, | ||
| 1929 | ' SetAdjectives( ({ ' . $adjString . '}) );', | ||
| 1930 | ); | ||
| 1931 | } | ||
| 1932 | |||
| 1933 | # SetShort("a wooden match"); | ||
| 1934 | if ($modelObj->baseString =~ m/^[AEIOUaeiou]/) { | ||
| 1935 | $shortString = 'an ' . $modelObj->baseString; | ||
| 1936 | } else { | ||
| 1937 | $shortString = 'a ' . $modelObj->baseString; | ||
| 1938 | } | ||
| 1939 | |||
| 1940 | push (@list, | ||
| 1941 | ' SetShort("' . $shortString . '");', | ||
| 1942 | ); | ||
| 1943 | |||
| 1944 | # SetLong("A wooden match that might light if you strike it."); | ||
| 1945 | if ($modelObj->descrip) { | ||
| 1946 | $longString = $modelObj->descrip; | ||
| 1947 | } else { | ||
| 1948 | $longString = $convertlpc::NULL_OBJ_DESCRIP; | ||
| 1949 | } | ||
| 1950 | |||
| 1951 | push (@list, | ||
| 1952 | ' SetLong("' . $longString . '");', | ||
| 1953 | ); | ||
| 1954 | |||
| 1955 | # SetMass(10); | ||
| 1956 | if ($modelObj->weight) { | ||
| 1957 | $weightString = $modelObj->weight; | ||
| 1958 | } else { | ||
| 1959 | $weightString = $convertlpc::DEFAULT_WEIGHT; | ||
| 1960 | } | ||
| 1961 | |||
| 1962 | push (@list, | ||
| 1963 | ' SetMass(' . $weightString . ');', | ||
| 1964 | ); | ||
| 1965 | |||
| 1966 | # SetDollarCost(10); | ||
| 1967 | if ($modelObj->buyValue) { | ||
| 1968 | $valueString = $modelObj->buyValue; | ||
| 1969 | } elsif ($modelObj->sellValue) { | ||
| 1970 | $valueString = $modelObj->sellValue; | ||
| 1971 | } else { | ||
| 1972 | $valueString = $convertlpc::DEFAULT_VALUE; | ||
| 1973 | } | ||
| 1974 | |||
| 1975 | push (@list, | ||
| 1976 | ' SetDollarCost(' . $valueString . ');', | ||
| 1977 | ); | ||
| 1978 | |||
| 1979 | # } | ||
| 1980 | # | ||
| 1981 | # void init(){ | ||
| 1982 | # ::init(); | ||
| 1983 | # } | ||
| 1984 | push (@list, | ||
| 1985 | '}', | ||
| 1986 | '', | ||
| 1987 | 'void init(){', | ||
| 1988 | ' ::init();', | ||
| 1989 | '}', | ||
| 1990 | ); | ||
| 1991 | |||
| 1992 | # Operation complete | ||
| 1993 | return @list; | ||
| 1994 | } | ||
| 1995 | |||
| 1996 | sub prepareDecoration { | ||
| 1997 | |||
| 1998 | # Called by $self->do | ||
| 1999 | # | ||
| 2000 | # Prepares a list of strings for a single world model decoration, which will be written as a | ||
| 2001 | # single LPC file | ||
| 2002 | # (The code used is based on the Dead Souls object /domains/town/obj/clocktower.c) | ||
| 2003 | # | ||
| 2004 | # Expected arguments | ||
| 2005 | # $session - The calling function's GA::Session | ||
| 2006 | # $convertHashRef - Reference to the hash of file paths created by the calling function, | ||
| 2007 | # in the form | ||
| 2008 | # $convertHash{model_number} = file_path; | ||
| 2009 | # $modelObj - The weapon model object to use | ||
| 2010 | # | ||
| 2011 | # Return values | ||
| 2012 | # An empty list on improper arguments | ||
| 2013 | # Otherwise returns a list of strings, which the calling function can write as an LPC | ||
| 2014 | # file | ||
| 2015 | |||
| 2016 | my ($self, $session, $convertHashRef, $modelObj, $check) = @_; | ||
| 2017 | |||
| 2018 | # Local variables | ||
| 2019 | my ( | ||
| 2020 | $adjString, $shortString, $longString, $weightString, $valueString, | ||
| 2021 | @emptyList, @list, | ||
| 2022 | ); | ||
| 2023 | |||
| 2024 | # Check for improper arguments | ||
| 2025 | if ( | ||
| 2026 | ! defined $session || ! defined $convertHashRef || ! defined $modelObj | ||
| 2027 | || defined $check | ||
| 2028 | ) { | ||
| 2029 | $axmud::CLIENT->writeImproper($self->_objClass . '->prepareDecoration', @_); | ||
| 2030 | return @emptyList; | ||
| 2031 | } | ||
| 2032 | |||
| 2033 | # #include <lib.h> | ||
| 2034 | # | ||
| 2035 | # inherit LIB_ITEM; | ||
| 2036 | # | ||
| 2037 | push (@list, | ||
| 2038 | '#include <lib.h>', | ||
| 2039 | ' ', | ||
| 2040 | 'inherit LIB_ITEM;', | ||
| 2041 | ' ', | ||
| 2042 | ); | ||
| 2043 | |||
| 2044 | # static void create() { | ||
| 2045 | # item::create(); | ||
| 2046 | push (@list, | ||
| 2047 | 'static void create() {', | ||
| 2048 | ' item::create();', | ||
| 2049 | ); | ||
| 2050 | |||
| 2051 | # SetKeyName("clock tower"); | ||
| 2052 | # SetId( ({ "great clock tower rising majestically into the sky", "tower" }) ); | ||
| 2053 | push (@list, | ||
| 2054 | ' SetKeyName("' . $modelObj->baseString . '");', | ||
| 2055 | ' SetId( ({ "' . $modelObj->noun . '", "' . $modelObj->baseString . '" }) );', | ||
| 2056 | ); | ||
| 2057 | |||
| 2058 | # SetAdjectives( ({ "great", "large" }) ); | ||
| 2059 | foreach my $adj ($modelObj->adjList) { | ||
| 2060 | |||
| 2061 | if ($adjString) { | ||
| 2062 | |||
| 2063 | $adjString .= ', '; | ||
| 2064 | } | ||
| 2065 | |||
| 2066 | $adjString = '"' . $adj . '"'; | ||
| 2067 | } | ||
| 2068 | |||
| 2069 | if (! $adjString) { | ||
| 2070 | |||
| 2071 | push (@list, | ||
| 2072 | ' SetAdjectives();', | ||
| 2073 | ); | ||
| 2074 | |||
| 2075 | } else { | ||
| 2076 | |||
| 2077 | push (@list, | ||
| 2078 | ' SetAdjectives( ({ ' . $adjString . '}) );', | ||
| 2079 | ); | ||
| 2080 | } | ||
| 2081 | |||
| 2082 | # SetShort("a great clock tower rising majestically into the sky"); | ||
| 2083 | if ($modelObj->baseString =~ m/^[AEIOUaeiou]/) { | ||
| 2084 | $shortString = 'an ' . $modelObj->baseString; | ||
| 2085 | } else { | ||
| 2086 | $shortString = 'a ' . $modelObj->baseString; | ||
| 2087 | } | ||
| 2088 | |||
| 2089 | push (@list, | ||
| 2090 | ' SetShort("' . $shortString . '");', | ||
| 2091 | ); | ||
| 2092 | |||
| 2093 | # SetLong("his is a large clock tower, rising magestically into the sky."); | ||
| 2094 | if ($modelObj->descrip) { | ||
| 2095 | $longString = $modelObj->descrip; | ||
| 2096 | } else { | ||
| 2097 | $longString = $convertlpc::NULL_OBJ_DESCRIP; | ||
| 2098 | } | ||
| 2099 | |||
| 2100 | push (@list, | ||
| 2101 | ' SetLong("' . $longString . '");', | ||
| 2102 | ); | ||
| 2103 | |||
| 2104 | # SetMass(1000000); | ||
| 2105 | # (ignore the model object's mass for something that no character could pick up) | ||
| 2106 | push (@list, | ||
| 2107 | ' SetMass(1000000);', | ||
| 2108 | ); | ||
| 2109 | |||
| 2110 | # SetBaseCost("silver", 100); | ||
| 2111 | if ($modelObj->buyValue) { | ||
| 2112 | $valueString = $modelObj->buyValue; | ||
| 2113 | } elsif ($modelObj->sellValue) { | ||
| 2114 | $valueString = $modelObj->sellValue; | ||
| 2115 | } else { | ||
| 2116 | $valueString = $convertlpc::DEFAULT_VALUE; | ||
| 2117 | } | ||
| 2118 | |||
| 2119 | push (@list, | ||
| 2120 | ' SetBaseCost("' . $convertlpc::DEFAULT_CURRENCY . '", ' . $valueString . ');', | ||
| 2121 | ); | ||
| 2122 | |||
| 2123 | # } | ||
| 2124 | # | ||
| 2125 | # void init(){ | ||
| 2126 | # ::init(); | ||
| 2127 | # } | ||
| 2128 | push (@list, | ||
| 2129 | '}', | ||
| 2130 | '', | ||
| 2131 | 'void init(){', | ||
| 2132 | ' ::init();', | ||
| 2133 | '}', | ||
| 2134 | ); | ||
| 2135 | |||
| 2136 | # Operation complete | ||
| 2137 | return @list; | ||
| 2138 | } | ||
| 2139 | |||
| 2140 | ################## | ||
| 2141 | # Accessors - set | ||
| 2142 | |||
| 2143 | ################## | ||
| 2144 | # Accessors - get | ||
| 2145 | } | ||
| 2146 | |||
| 2147 | # Package must return a true value | ||
| 2148 | 1 |