| 1 | # Copyright (C) 2011-2024 A S Lewis | ||
| 2 | # | ||
| 3 | # This program is free software: you can redistribute it and/or modify it under the terms of the GNU | ||
| 4 | # Lesser Public License as published by the Free Software Foundation, either version 3 of the | ||
| 5 | # License, or (at your option) any later version. | ||
| 6 | # | ||
| 7 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| 8 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 9 | # Lesser Public License for more details. | ||
| 10 | # | ||
| 11 | # You should have received a copy of the GNU Lesser Public License along with this program. If not, | ||
| 12 | # see <http://www.gnu.org/licenses/>. | ||
| 13 | # | ||
| 14 | # | ||
| 15 | # Language::Axbasic::Function, based on Language::Basic by Amir Karger | ||
| 16 | |||
| 17 | { package Language::Axbasic::Function; | ||
| 18 | |||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | # use diagnostics; | ||
| 22 | |||
| 23 | use Glib qw(TRUE FALSE); | ||
| 24 | |||
| 25 | @Language::Axbasic::Function::ISA = qw( | ||
| 26 | Language::Axbasic | ||
| 27 | ); | ||
| 28 | |||
| 29 | # Sub-classes | ||
| 30 | { | ||
| 31 | package Language::Axbasic::Function::Intrinsic; | ||
| 32 | package Language::Axbasic::Function::Defined; | ||
| 33 | } | ||
| 34 | |||
| 35 | ################## | ||
| 36 | # Constructors | ||
| 37 | |||
| 38 | sub new { | ||
| 39 | |||
| 40 | # Called by LA::Expression::Function->new | ||
| 41 | # | ||
| 42 | # Paraphrased from Language::Basic: | ||
| 43 | # The class that handles user-defined and intrinsic functions in Axbasic | ||
| 44 | # | ||
| 45 | # A Function can be either an intrinsic Axbasic function, like int() or chr$(), or a | ||
| 46 | # user-defined function, defined with the 'def' command (NB Unlike Language::Basic, | ||
| 47 | # user-defined functions don't have to begin with the letters FN) | ||
| 48 | # The ->checkArgs method checks that the right number and type of function arguments were | ||
| 49 | # specified | ||
| 50 | # The ->evaluate method actually calculates the value of the function, using any specified | ||
| 51 | # aguments | ||
| 52 | # | ||
| 53 | # ->new puts the function into LA::Script's function lookup table, as well as blessing the | ||
| 54 | # subclass into existence | ||
| 55 | # | ||
| 56 | # Expected arguments | ||
| 57 | # $scriptObj - Blessed reference of the parent LA::Script | ||
| 58 | # $funcName - The function's name | ||
| 59 | # | ||
| 60 | # Optional arguments | ||
| 61 | # $argTypeString - (When called by LA::Function::Intrinsic->initialise) the value for | ||
| 62 | # $self->argTypeString | ||
| 63 | # | ||
| 64 | # Return values | ||
| 65 | # 'undef' on improper arguments | ||
| 66 | # Blessed reference to the newly-created object (blessed into the function subclass) on | ||
| 67 | # success | ||
| 68 | |||
| 69 | my ($class, $scriptObj, $funcName, $argTypeString, $check) = @_; | ||
| 70 | |||
| 71 | # Local variables | ||
| 72 | my ($type, $subClass); | ||
| 73 | |||
| 74 | # Check for improper arguments | ||
| 75 | if (! defined $class || ! defined $scriptObj || ! defined $funcName || defined $check) { | ||
| 76 | |||
| 77 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 78 | } | ||
| 79 | |||
| 80 | # Setup | ||
| 81 | my $self = { | ||
| 82 | _objName => $class, # Name Axbasic objects after their class | ||
| 83 | _objClass => $class, | ||
| 84 | _parentFile => undef, # No parent file object | ||
| 85 | _parentWorld => undef, # No parent file object | ||
| 86 | _privFlag => TRUE, # All IVs are private | ||
| 87 | |||
| 88 | # Perl object components | ||
| 89 | # ---------------------- | ||
| 90 | |||
| 91 | # The parent LA::Script | ||
| 92 | scriptObj => $scriptObj, | ||
| 93 | |||
| 94 | # IVs | ||
| 95 | # --- | ||
| 96 | |||
| 97 | # Name of the function | ||
| 98 | funcName => $funcName, | ||
| 99 | # What type of function this is: 'string' or 'numeric' | ||
| 100 | funcType => undef, # Set below | ||
| 101 | # A string, listing the number and type of arguments the function takes. If a function | ||
| 102 | # takes a String and two Numeric arguments, the string will be 'SNN'. A semicolon | ||
| 103 | # separates required from optional arguments | ||
| 104 | # For intrinsic functions, set by ->initialise. For user-defined functions, set by | ||
| 105 | # ->declare | ||
| 106 | argTypeString => $argTypeString, | ||
| 107 | # For user-defined functions, a list of LA::Variable::Lvalues (set by ->declare); an | ||
| 108 | # empty list for intrinsic functions | ||
| 109 | argList => [], | ||
| 110 | # For user-defined functions, an expression which defines the function ('undef' for | ||
| 111 | # intrinsic functions). Set by LA::Statement::def->parse | ||
| 112 | defFuncExp => undef, | ||
| 113 | }; | ||
| 114 | |||
| 115 | # Put this function in LA::Script's lookup table. (If a function with the same name already | ||
| 116 | # exists - even if it is an intrinsic function - the old function is overwritten) | ||
| 117 | $scriptObj->add_funcName($funcName, $self); | ||
| 118 | |||
| 119 | # If the function name ends with a $, it's a string function, otherwise it's a numeric | ||
| 120 | # function | ||
| 121 | if ($funcName =~ /\$$/) { | ||
| 122 | $type = 'String'; | ||
| 123 | } else { | ||
| 124 | $type = 'Numeric'; | ||
| 125 | } | ||
| 126 | |||
| 127 | $self->{'funcType'} = lc($type); | ||
| 128 | |||
| 129 | # Create the subclass object and return it | ||
| 130 | if ($class =~ m/Language::Axbasic::Function::Defined/) { | ||
| 131 | |||
| 132 | # User-defined functions | ||
| 133 | $subClass = $class . '::' . $type; | ||
| 134 | bless $self, $subClass; | ||
| 135 | |||
| 136 | } else { | ||
| 137 | |||
| 138 | # Intrinsic functions | ||
| 139 | bless $self, $class; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | ################## | ||
| 144 | # Methods | ||
| 145 | |||
| 146 | sub checkArgs { | ||
| 147 | |||
| 148 | # Called by LA::Expression::Function->new | ||
| 149 | # Given an LA::Expression::ArgList object, checks the arguments to make sure they are of the | ||
| 150 | # correct number and type | ||
| 151 | # NB unlike the original Language::Basic, we give up at the first error | ||
| 152 | # | ||
| 153 | # Expected arguments | ||
| 154 | # $argListObj - A LA::Expression::ArgList object containing the argument list | ||
| 155 | # | ||
| 156 | # Return values | ||
| 157 | # 'undef' on improper arguments, or if there's an error | ||
| 158 | # 1 if the arguments check out | ||
| 159 | |||
| 160 | my ($self, $argListObj, $check) = @_; | ||
| 161 | |||
| 162 | # Local variables | ||
| 163 | my ( | ||
| 164 | $typeString, $min, $max, | ||
| 165 | @args, | ||
| 166 | ); | ||
| 167 | |||
| 168 | # Check for improper arguments | ||
| 169 | if (! defined $argListObj || defined $check) { | ||
| 170 | |||
| 171 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkArgs', @_); | ||
| 172 | } | ||
| 173 | |||
| 174 | # Import the argument list from the LA::Expression::ArgList object | ||
| 175 | @args = $argListObj->argList; | ||
| 176 | |||
| 177 | # Import this function's argument type string | ||
| 178 | $typeString = $self->argTypeString; | ||
| 179 | # From the type string, set the minimum and maximum number of arguments | ||
| 180 | if ($typeString =~ s/(.*);/$1/) { | ||
| 181 | $min = length($1); # Optional arguments | ||
| 182 | } else { | ||
| 183 | $min = length($typeString); # No optional arguments | ||
| 184 | } | ||
| 185 | |||
| 186 | $max = length($typeString); | ||
| 187 | |||
| 188 | if (scalar @args < $min || scalar @args > $max) { | ||
| 189 | |||
| 190 | return $self->scriptObj->setError( | ||
| 191 | 'wrong_number_of_arguments', | ||
| 192 | $self->_objClass . '->checkArgs', | ||
| 193 | ); | ||
| 194 | } | ||
| 195 | |||
| 196 | # Check each argument type in turn | ||
| 197 | OUTER: foreach my $type (split (m//, $typeString)) { | ||
| 198 | |||
| 199 | my ($arg, $argType); | ||
| 200 | |||
| 201 | $arg = shift @args; | ||
| 202 | if (! defined $arg) { | ||
| 203 | |||
| 204 | # There may not be any optional args | ||
| 205 | last OUTER; | ||
| 206 | } | ||
| 207 | |||
| 208 | if (! (ref($arg) =~ m/(String|Numeric)$/)) { | ||
| 209 | |||
| 210 | return $self->scriptObj->setDebug( | ||
| 211 | 'Improbable error in Language::Axbasic::Function::Defined->checkArgs', | ||
| 212 | $self->_objClass . '->checkArgs', | ||
| 213 | ); | ||
| 214 | |||
| 215 | } else { | ||
| 216 | |||
| 217 | $argType = substr($1, 0, 1); | ||
| 218 | } | ||
| 219 | |||
| 220 | if ($argType ne $type) { | ||
| 221 | |||
| 222 | if ($type eq 'N') { | ||
| 223 | |||
| 224 | return $self->scriptObj->setError( | ||
| 225 | 'function_expected_numeric_argument_but_received_string', | ||
| 226 | $self->_objClass . '->checkArgs', | ||
| 227 | ); | ||
| 228 | |||
| 229 | } else { | ||
| 230 | |||
| 231 | return $self->scriptObj->setError( | ||
| 232 | 'function_expected_string_argument_but_received_numeric', | ||
| 233 | $self->_objClass . '->checkArgs', | ||
| 234 | ); | ||
| 235 | } | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | # All the arguments check out | ||
| 240 | return 1; | ||
| 241 | } | ||
| 242 | |||
| 243 | ################## | ||
| 244 | # Accessors - set | ||
| 245 | |||
| 246 | sub set_defFuncExp { | ||
| 247 | |||
| 248 | # Returns 'undef' on improper arguments | ||
| 249 | # Returns 1 on success | ||
| 250 | |||
| 251 | my ($self, $expression, $check) = @_; | ||
| 252 | |||
| 253 | # Check for improper arguments | ||
| 254 | if (! defined $expression || defined $check) { | ||
| 255 | |||
| 256 | return $axmud::CLIENT->writeImproper( | ||
| 257 | $self->_objClass . '->set_defFuncExp', | ||
| 258 | @_, | ||
| 259 | ); | ||
| 260 | } | ||
| 261 | |||
| 262 | # Update IVs | ||
| 263 | $self->ivPoke('defFuncExp', $expression); | ||
| 264 | |||
| 265 | return 1; | ||
| 266 | } | ||
| 267 | |||
| 268 | ################## | ||
| 269 | # Accessors - get | ||
| 270 | |||
| 271 | sub scriptObj | ||
| 272 | { $_[0]->{scriptObj} } | ||
| 273 | |||
| 274 | sub funcName | ||
| 275 | { $_[0]->{funcName} } | ||
| 276 | sub funcType | ||
| 277 | { $_[0]->{funcType} } | ||
| 278 | sub argTypeString | ||
| 279 | { $_[0]->{argTypeString} } | ||
| 280 | sub argList | ||
| 281 | { my $self = shift; return @{$self->{argList}}; } | ||
| 282 | sub defFuncExp | ||
| 283 | { $_[0]->{defFuncExp} } | ||
| 284 | } | ||
| 285 | |||
| 286 | { package Language::Axbasic::Function::Intrinsic; | ||
| 287 | |||
| 288 | use strict; | ||
| 289 | use warnings; | ||
| 290 | # use diagnostics; | ||
| 291 | |||
| 292 | use Glib qw(TRUE FALSE); | ||
| 293 | |||
| 294 | @Language::Axbasic::Function::Intrinsic::ISA = qw( | ||
| 295 | Language::Axbasic::Function | ||
| 296 | ); | ||
| 297 | |||
| 298 | ################## | ||
| 299 | # Constructors | ||
| 300 | |||
| 301 | sub initialise { | ||
| 302 | |||
| 303 | # Called by LA::Script->new | ||
| 304 | # Sets up Axbasic's intrinsic (pre-defined) functions and creates entries for each function | ||
| 305 | # in LA::Script's function lookup table | ||
| 306 | # | ||
| 307 | # Expected arguments: | ||
| 308 | # $scriptObj - Blessed reference of the parent LA::Script | ||
| 309 | # | ||
| 310 | # Return values: | ||
| 311 | # 'undef' on improper arguments, or if there is an error | ||
| 312 | # 1 otherwise | ||
| 313 | |||
| 314 | my ($class, $scriptObj, $check) = @_; | ||
| 315 | |||
| 316 | # Local variables | ||
| 317 | my ( | ||
| 318 | $subClass, $string, | ||
| 319 | @funcList, | ||
| 320 | %funcHash, | ||
| 321 | ); | ||
| 322 | |||
| 323 | # Check for improper arguments | ||
| 324 | if (! defined $scriptObj || defined $check) { | ||
| 325 | |||
| 326 | return $axmud::CLIENT->writeImproper($class . '->initialise', @_); | ||
| 327 | } | ||
| 328 | |||
| 329 | # Import the pre-defined function hash, which states which arguments are required for each | ||
| 330 | # function | ||
| 331 | %funcHash = $scriptObj->funcArgHash; | ||
| 332 | |||
| 333 | # Create each function in turn | ||
| 334 | foreach my $funcName (keys %funcHash) { | ||
| 335 | |||
| 336 | if (! ($funcName =~ m/\$$/)) { | ||
| 337 | |||
| 338 | $subClass = 'Language::Axbasic::Function::Intrinsic::Numeric::' . $funcName; | ||
| 339 | |||
| 340 | } else { | ||
| 341 | |||
| 342 | $string = $funcName; | ||
| 343 | $string =~ s/\$$//; | ||
| 344 | $subClass = 'Language::Axbasic::Function::Intrinsic::String::' . $string; | ||
| 345 | } | ||
| 346 | |||
| 347 | if (! $subClass->new($scriptObj, $funcName, $funcHash{$funcName})) { | ||
| 348 | |||
| 349 | return $scriptObj->setDebug( | ||
| 350 | 'Can\'t set up intrinsic function ' . $funcName . '\'', | ||
| 351 | $class . '->initialise', | ||
| 352 | ); | ||
| 353 | } | ||
| 354 | } | ||
| 355 | |||
| 356 | # Initialisation complete | ||
| 357 | return 1; | ||
| 358 | } | ||
| 359 | |||
| 360 | ################## | ||
| 361 | # Methods | ||
| 362 | |||
| 363 | ################## | ||
| 364 | # Accessors - set | ||
| 365 | |||
| 366 | ################## | ||
| 367 | # Accessors - get | ||
| 368 | } | ||
| 369 | |||
| 370 | { package Language::Axbasic::Function::Intrinsic::String; | ||
| 371 | |||
| 372 | use strict; | ||
| 373 | use warnings; | ||
| 374 | # use diagnostics; | ||
| 375 | |||
| 376 | use Glib qw(TRUE FALSE); | ||
| 377 | |||
| 378 | @Language::Axbasic::Function::Intrinsic::String::ISA = qw( | ||
| 379 | Language::Axbasic::Function::Intrinsic | ||
| 380 | Language::Axbasic::Function::String | ||
| 381 | ); | ||
| 382 | } | ||
| 383 | |||
| 384 | { package Language::Axbasic::Function::Intrinsic::Numeric; | ||
| 385 | |||
| 386 | use strict; | ||
| 387 | use warnings; | ||
| 388 | # use diagnostics; | ||
| 389 | |||
| 390 | use Glib qw(TRUE FALSE); | ||
| 391 | |||
| 392 | @Language::Axbasic::Function::Intrinsic::Numeric::ISA = qw( | ||
| 393 | Language::Axbasic::Function::Intrinsic | ||
| 394 | Language::Axbasic::Function::Numeric | ||
| 395 | ); | ||
| 396 | } | ||
| 397 | |||
| 398 | { package Language::Axbasic::Function::Defined; | ||
| 399 | |||
| 400 | use strict; | ||
| 401 | use warnings; | ||
| 402 | # use diagnostics; | ||
| 403 | |||
| 404 | use Glib qw(TRUE FALSE); | ||
| 405 | |||
| 406 | @Language::Axbasic::Function::Defined::ISA = qw( | ||
| 407 | Language::Axbasic::Function | ||
| 408 | ); | ||
| 409 | |||
| 410 | # Paraphrased from Language::Basic | ||
| 411 | # This class handles functions defined by the user in 'def' statements | ||
| 412 | |||
| 413 | ################## | ||
| 414 | # Constructors | ||
| 415 | |||
| 416 | ################## | ||
| 417 | # Methods | ||
| 418 | |||
| 419 | sub declare { | ||
| 420 | |||
| 421 | # Called by LA::Expression::Function->new | ||
| 422 | # Declares how many arguments, and of which type, the newly-defined function should expect. | ||
| 423 | # Sets the IVs $self->argTypeString and $self->argListObj | ||
| 424 | # | ||
| 425 | # Expected arguments | ||
| 426 | # @argList - A list of LA::Variable::Lvalue objects which are the arguments to the | ||
| 427 | # function (e.g., x in 'def myfunc(x)') | ||
| 428 | # | ||
| 429 | # Return values | ||
| 430 | # 'undef' on improper arguments | ||
| 431 | # 1 on success | ||
| 432 | |||
| 433 | my ($self, @argList) = @_; | ||
| 434 | |||
| 435 | # Local variables | ||
| 436 | my $argTypeString; | ||
| 437 | |||
| 438 | # (No improper arguments to check) | ||
| 439 | |||
| 440 | foreach my $arg (@argList) { | ||
| 441 | |||
| 442 | my $class = ref($arg); | ||
| 443 | |||
| 444 | if (! ($class =~ /(String|Numeric)$/)) { | ||
| 445 | |||
| 446 | return $self->scriptObj->setDebug('Type error', $self->_objClass . '->declare'); | ||
| 447 | |||
| 448 | } else { | ||
| 449 | |||
| 450 | # $argTypeString is a string made up of S (for String) or N (Numeric) characters in | ||
| 451 | # sequence, showing the Axbasic function's expected argument types | ||
| 452 | $argTypeString .= substr($1, 0, 1); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | # Set IVs | ||
| 457 | $self->ivPoke('argTypeString', $argTypeString); | ||
| 458 | $self->ivPoke('argList', @argList); | ||
| 459 | |||
| 460 | return 1; | ||
| 461 | } | ||
| 462 | |||
| 463 | sub evaluate { | ||
| 464 | |||
| 465 | # Called by LA::Expression::Function->evaluate | ||
| 466 | # Actually evaluate the function with the specified arguments | ||
| 467 | # | ||
| 468 | # Paraphrased from Language::Basic: | ||
| 469 | # Set each parameter (in the ->variables IV) to the value given in the arguments, then | ||
| 470 | # evaluate the expression | ||
| 471 | # Just in case the user has a fn(x) and uses x elsewhere in the script, save the value of x | ||
| 472 | # just before we set x based on the argument (this is a poor man's version of variable | ||
| 473 | # scoping) | ||
| 474 | # | ||
| 475 | # Expected arguments | ||
| 476 | # @args - The arguments with which to evaluate the function | ||
| 477 | # | ||
| 478 | # Return values | ||
| 479 | # 'undef' on improper arguments, or if the ->defFuncExp IV is not defined | ||
| 480 | # Otherwise returns the value of the function | ||
| 481 | |||
| 482 | my ($self, @args) = @_; | ||
| 483 | |||
| 484 | # Local variables | ||
| 485 | my ( | ||
| 486 | $varObj, $returnValue, | ||
| 487 | @lvalueList, @saveVars, | ||
| 488 | ); | ||
| 489 | |||
| 490 | # (No improper arguments to check) | ||
| 491 | |||
| 492 | # Check the function has been defined (no reason why it shouldn't have been) | ||
| 493 | if (! defined $self->defFuncExp) { | ||
| 494 | |||
| 495 | return $self->scriptObj->setError( | ||
| 496 | 'function_not_defined', | ||
| 497 | $self->_objClass . '->evaluate', | ||
| 498 | ); | ||
| 499 | } | ||
| 500 | |||
| 501 | # Import the list of LA::Variable::Lvalues objects, which are the arguments to the function | ||
| 502 | # (e.g., x in 'def myfunc(x)') | ||
| 503 | @lvalueList = $self->argList; | ||
| 504 | |||
| 505 | # Process the list of LA::Variable::Lvalues objects, which are the arguments to the function | ||
| 506 | # (e.g., x in 'def myfunc(x)') | ||
| 507 | foreach my $lvalue (@lvalueList) { | ||
| 508 | |||
| 509 | # Get a blessed reference to a variable object. If it's a scalar, returns that object; | ||
| 510 | # if it's an array, returns the object specified by the argument list (e.g. the value | ||
| 511 | # of array(5,6) ) | ||
| 512 | $varObj = $lvalue->variable; | ||
| 513 | |||
| 514 | # Save the value of the variable, so we can give the variable a temporary value, and | ||
| 515 | # restore the old value afterwards | ||
| 516 | push (@saveVars, $varObj->value); | ||
| 517 | $varObj->set(shift @args); | ||
| 518 | } | ||
| 519 | |||
| 520 | # Evaluate the expression that defines the function | ||
| 521 | $returnValue = $self->defFuncExp->evaluate(); | ||
| 522 | if (! defined $returnValue) { | ||
| 523 | |||
| 524 | return undef; | ||
| 525 | } | ||
| 526 | |||
| 527 | # Now restore the values of the variable objects that we changed a few moments ago | ||
| 528 | foreach my $lvalue (@lvalueList) { | ||
| 529 | |||
| 530 | $varObj = $lvalue->variable; | ||
| 531 | $varObj->set(shift @saveVars); | ||
| 532 | } | ||
| 533 | |||
| 534 | # Return the value of the function | ||
| 535 | return $returnValue; | ||
| 536 | } | ||
| 537 | |||
| 538 | ################## | ||
| 539 | # Accessors - set | ||
| 540 | |||
| 541 | ################## | ||
| 542 | # Accessors - get | ||
| 543 | } | ||
| 544 | |||
| 545 | { package Language::Axbasic::Function::Defined::String; | ||
| 546 | |||
| 547 | use strict; | ||
| 548 | use warnings; | ||
| 549 | # use diagnostics; | ||
| 550 | |||
| 551 | use Glib qw(TRUE FALSE); | ||
| 552 | |||
| 553 | @Language::Axbasic::Function::Defined::String::ISA = qw( | ||
| 554 | Language::Axbasic::Function::Defined | ||
| 555 | Language::Axbasic::Function::String | ||
| 556 | ); | ||
| 557 | } | ||
| 558 | |||
| 559 | { package Language::Axbasic::Function::Defined::Numeric; | ||
| 560 | |||
| 561 | use strict; | ||
| 562 | use warnings; | ||
| 563 | # use diagnostics; | ||
| 564 | |||
| 565 | use Glib qw(TRUE FALSE); | ||
| 566 | |||
| 567 | @Language::Axbasic::Function::Defined::Numeric::ISA = qw( | ||
| 568 | Language::Axbasic::Function::Defined | ||
| 569 | Language::Axbasic::Function::Numeric | ||
| 570 | ); | ||
| 571 | } | ||
| 572 | |||
| 573 | { package Language::Axbasic::Function::String; | ||
| 574 | |||
| 575 | use strict; | ||
| 576 | use warnings; | ||
| 577 | # use diagnostics; | ||
| 578 | |||
| 579 | use Glib qw(TRUE FALSE); | ||
| 580 | |||
| 581 | @Language::Axbasic::Function::String::ISA = qw( | ||
| 582 | Language::Axbasic::Function | ||
| 583 | Language::Axbasic::String | ||
| 584 | ); | ||
| 585 | } | ||
| 586 | |||
| 587 | { package Language::Axbasic::Function::Numeric; | ||
| 588 | |||
| 589 | use strict; | ||
| 590 | use warnings; | ||
| 591 | # use diagnostics; | ||
| 592 | |||
| 593 | use Glib qw(TRUE FALSE); | ||
| 594 | |||
| 595 | @Language::Axbasic::Function::Numeric::ISA = qw( | ||
| 596 | Language::Axbasic::Function | ||
| 597 | Language::Axbasic::Numeric | ||
| 598 | ); | ||
| 599 | } | ||
| 600 | |||
| 601 | ### Pure BASIC functions (numeric) ### | ||
| 602 | |||
| 603 | { package Language::Axbasic::Function::Intrinsic::Numeric::abs; | ||
| 604 | |||
| 605 | use strict; | ||
| 606 | use warnings; | ||
| 607 | # use diagnostics; | ||
| 608 | |||
| 609 | use Glib qw(TRUE FALSE); | ||
| 610 | |||
| 611 | @Language::Axbasic::Function::Intrinsic::Numeric::abs::ISA = qw( | ||
| 612 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 613 | ); | ||
| 614 | |||
| 615 | # Abs (x) | ||
| 616 | |||
| 617 | ################## | ||
| 618 | # Methods | ||
| 619 | |||
| 620 | sub evaluate { | ||
| 621 | |||
| 622 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 623 | # | ||
| 624 | # Expected arguments | ||
| 625 | # $arg - The first (and only) argument in the argument list | ||
| 626 | # | ||
| 627 | # Return values | ||
| 628 | # The return value of the function | ||
| 629 | |||
| 630 | my ($self, $arg) = @_; | ||
| 631 | |||
| 632 | # (No improper arguments to check) | ||
| 633 | |||
| 634 | # Evaluate the function and return the value | ||
| 635 | return abs($arg); | ||
| 636 | } | ||
| 637 | } | ||
| 638 | |||
| 639 | { package Language::Axbasic::Function::Intrinsic::Numeric::acos; | ||
| 640 | |||
| 641 | use strict; | ||
| 642 | use warnings; | ||
| 643 | # use diagnostics; | ||
| 644 | |||
| 645 | use Glib qw(TRUE FALSE); | ||
| 646 | |||
| 647 | @Language::Axbasic::Function::Intrinsic::Numeric::acos::ISA = qw( | ||
| 648 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 649 | ); | ||
| 650 | |||
| 651 | # Acos (x) | ||
| 652 | |||
| 653 | ################## | ||
| 654 | # Methods | ||
| 655 | |||
| 656 | sub evaluate { | ||
| 657 | |||
| 658 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 659 | # | ||
| 660 | # Expected arguments | ||
| 661 | # $arg - The first (and only) argument in the argument list | ||
| 662 | # | ||
| 663 | # Return values | ||
| 664 | # The return value of the function | ||
| 665 | |||
| 666 | my ($self, $arg) = @_; | ||
| 667 | |||
| 668 | # Local variables | ||
| 669 | my $value; | ||
| 670 | |||
| 671 | # (No improper arguments to check) | ||
| 672 | |||
| 673 | # Evaluate the function and return the value | ||
| 674 | $value = Math::Trig::acos($arg); | ||
| 675 | |||
| 676 | # $value is in radians by default. Convert to degrees, if required | ||
| 677 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 678 | |||
| 679 | $value = Math::Trig::rad2deg($value); | ||
| 680 | } | ||
| 681 | |||
| 682 | return $value; | ||
| 683 | } | ||
| 684 | } | ||
| 685 | |||
| 686 | { package Language::Axbasic::Function::Intrinsic::Numeric::angle; | ||
| 687 | |||
| 688 | use strict; | ||
| 689 | use warnings; | ||
| 690 | # use diagnostics; | ||
| 691 | |||
| 692 | use Glib qw(TRUE FALSE); | ||
| 693 | |||
| 694 | @Language::Axbasic::Function::Intrinsic::Numeric::angle::ISA = qw( | ||
| 695 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 696 | ); | ||
| 697 | |||
| 698 | # Angle (x, y) | ||
| 699 | |||
| 700 | ################## | ||
| 701 | # Methods | ||
| 702 | |||
| 703 | sub evaluate { | ||
| 704 | |||
| 705 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN') | ||
| 706 | # | ||
| 707 | # Expected arguments | ||
| 708 | # @args - The list of arguments supplied to the function | ||
| 709 | # | ||
| 710 | # Return values | ||
| 711 | # The return value of the function | ||
| 712 | |||
| 713 | my ($self, @args) = @_; | ||
| 714 | |||
| 715 | # Local variables | ||
| 716 | my ($arctan, $value); | ||
| 717 | |||
| 718 | # (No improper arguments to check) | ||
| 719 | |||
| 720 | # Evaluate the function and return the value | ||
| 721 | |||
| 722 | # Check that both arguments are non-zero numbers | ||
| 723 | if (! $args[0] && ! $args[1]) { | ||
| 724 | |||
| 725 | return $self->scriptObj->setError( | ||
| 726 | 'invalid_matching_arguments', | ||
| 727 | $self->_objClass . '->evaluate', | ||
| 728 | ); | ||
| 729 | } | ||
| 730 | |||
| 731 | # We give a range of angles, in radians, equivalent to -180o < @ <= 180 | ||
| 732 | # Use the arctan function to find the angle of the tangent, since we have both the opposite | ||
| 733 | # ($args[1]) and the adjacent ($args[0]) | ||
| 734 | |||
| 735 | # First deal with special cases (so we don't divide by 0) | ||
| 736 | if (! $args[0]) { | ||
| 737 | |||
| 738 | if ($args[1] > 0) { | ||
| 739 | $value = Math::Trig::deg2rad(90); | ||
| 740 | } else { | ||
| 741 | $value = Math::Trig::deg2rad(-90); | ||
| 742 | } | ||
| 743 | |||
| 744 | } elsif (! $args[1]) { | ||
| 745 | |||
| 746 | if ($args[0] > 0) { | ||
| 747 | $value = Math::Trig::deg2rad(0); | ||
| 748 | } else { | ||
| 749 | $value = Math::Trig::deg2rad(180); | ||
| 750 | } | ||
| 751 | |||
| 752 | } else { | ||
| 753 | |||
| 754 | $arctan = Math::Trig::atan($args[1] / $args[0]); | ||
| 755 | |||
| 756 | # Otherwise, tan is opposite / adjacent... | ||
| 757 | if ($args[0] > 0 && $args[1] > 0) { | ||
| 758 | |||
| 759 | $value = $arctan; | ||
| 760 | |||
| 761 | } elsif ($args[0] < 0 && $args[1] > 0) { | ||
| 762 | |||
| 763 | $value = Math::Trig::deg2rad(180) + $arctan; | ||
| 764 | |||
| 765 | } elsif ($args[0] < 0 && $args[1] < 0) { | ||
| 766 | |||
| 767 | $value = Math::Trig::deg2rad(-180) + $arctan; | ||
| 768 | |||
| 769 | } else { | ||
| 770 | |||
| 771 | $value = $arctan; | ||
| 772 | } | ||
| 773 | } | ||
| 774 | |||
| 775 | # Convert from radians to degrees, if required | ||
| 776 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 777 | |||
| 778 | $value = Math::Trig::rad2deg($value); | ||
| 779 | } | ||
| 780 | |||
| 781 | return $value; | ||
| 782 | } | ||
| 783 | } | ||
| 784 | |||
| 785 | { package Language::Axbasic::Function::Intrinsic::Numeric::asc; | ||
| 786 | |||
| 787 | use strict; | ||
| 788 | use warnings; | ||
| 789 | # use diagnostics; | ||
| 790 | |||
| 791 | use Glib qw(TRUE FALSE); | ||
| 792 | |||
| 793 | @Language::Axbasic::Function::Intrinsic::Numeric::asc::ISA = qw( | ||
| 794 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 795 | ); | ||
| 796 | |||
| 797 | # Asc (string) | ||
| 798 | |||
| 799 | ################## | ||
| 800 | # Methods | ||
| 801 | |||
| 802 | sub evaluate { | ||
| 803 | |||
| 804 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 805 | # | ||
| 806 | # Expected arguments | ||
| 807 | # $arg - The first (and only) argument in the argument list | ||
| 808 | # | ||
| 809 | # Return values | ||
| 810 | # The return value of the function | ||
| 811 | |||
| 812 | my ($self, $arg) = @_; | ||
| 813 | |||
| 814 | # Local variables | ||
| 815 | my $value; | ||
| 816 | |||
| 817 | # (No improper arguments to check) | ||
| 818 | |||
| 819 | # Evaluate the function and return the value | ||
| 820 | $value = ord($arg); | ||
| 821 | |||
| 822 | if ($value < 0 || $value > 127) { | ||
| 823 | |||
| 824 | return $self->scriptObj->setError( | ||
| 825 | 'character_STRING_out_of_range', | ||
| 826 | $self->_objClass . '->evaluate', | ||
| 827 | 'STRING', $arg, | ||
| 828 | ); | ||
| 829 | |||
| 830 | } else { | ||
| 831 | |||
| 832 | return $value; | ||
| 833 | } | ||
| 834 | } | ||
| 835 | } | ||
| 836 | |||
| 837 | { package Language::Axbasic::Function::Intrinsic::Numeric::asin; | ||
| 838 | |||
| 839 | use strict; | ||
| 840 | use warnings; | ||
| 841 | # use diagnostics; | ||
| 842 | |||
| 843 | use Glib qw(TRUE FALSE); | ||
| 844 | |||
| 845 | @Language::Axbasic::Function::Intrinsic::Numeric::asin::ISA = qw( | ||
| 846 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 847 | ); | ||
| 848 | |||
| 849 | # Asin (x) | ||
| 850 | |||
| 851 | ################## | ||
| 852 | # Methods | ||
| 853 | |||
| 854 | sub evaluate { | ||
| 855 | |||
| 856 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 857 | # | ||
| 858 | # Expected arguments | ||
| 859 | # $arg - The first (and only) argument in the argument list | ||
| 860 | # | ||
| 861 | # Return values | ||
| 862 | # The return value of the function | ||
| 863 | |||
| 864 | my ($self, $arg) = @_; | ||
| 865 | |||
| 866 | # Local variables | ||
| 867 | my $value; | ||
| 868 | |||
| 869 | # (No improper arguments to check) | ||
| 870 | |||
| 871 | # Evaluate the function and return the value | ||
| 872 | $value = Math::Trig::asin($arg); | ||
| 873 | |||
| 874 | # $value is in radians by default. Convert to degrees, if required | ||
| 875 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 876 | |||
| 877 | $value = Math::Trig::rad2deg($value); | ||
| 878 | } | ||
| 879 | |||
| 880 | return $value; | ||
| 881 | } | ||
| 882 | } | ||
| 883 | |||
| 884 | { package Language::Axbasic::Function::Intrinsic::Numeric::atn; | ||
| 885 | |||
| 886 | use strict; | ||
| 887 | use warnings; | ||
| 888 | # use diagnostics; | ||
| 889 | |||
| 890 | use Glib qw(TRUE FALSE); | ||
| 891 | |||
| 892 | @Language::Axbasic::Function::Intrinsic::Numeric::atn::ISA = qw( | ||
| 893 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 894 | ); | ||
| 895 | |||
| 896 | # Atn (x) | ||
| 897 | |||
| 898 | ################## | ||
| 899 | # Methods | ||
| 900 | |||
| 901 | sub evaluate { | ||
| 902 | |||
| 903 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 904 | # | ||
| 905 | # Expected arguments | ||
| 906 | # $arg - The first (and only) argument in the argument list | ||
| 907 | # | ||
| 908 | # Return values | ||
| 909 | # The return value of the function | ||
| 910 | |||
| 911 | my ($self, $arg) = @_; | ||
| 912 | |||
| 913 | # Local variables | ||
| 914 | my $value; | ||
| 915 | |||
| 916 | # (No improper arguments to check) | ||
| 917 | |||
| 918 | # Evaluate the function and return the value | ||
| 919 | $value = Math::Trig::atan($arg); | ||
| 920 | |||
| 921 | # $value is in radians by default. Convert to degrees, if required | ||
| 922 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 923 | |||
| 924 | $value = Math::Trig::rad2deg($value); | ||
| 925 | } | ||
| 926 | |||
| 927 | return $value; | ||
| 928 | } | ||
| 929 | } | ||
| 930 | |||
| 931 | { package Language::Axbasic::Function::Intrinsic::Numeric::ceil; | ||
| 932 | |||
| 933 | use strict; | ||
| 934 | use warnings; | ||
| 935 | # use diagnostics; | ||
| 936 | |||
| 937 | use Glib qw(TRUE FALSE); | ||
| 938 | |||
| 939 | @Language::Axbasic::Function::Intrinsic::Numeric::ceil::ISA = qw( | ||
| 940 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 941 | ); | ||
| 942 | |||
| 943 | # Ceil (x) | ||
| 944 | |||
| 945 | ################## | ||
| 946 | # Methods | ||
| 947 | |||
| 948 | sub evaluate { | ||
| 949 | |||
| 950 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 951 | # | ||
| 952 | # Expected arguments | ||
| 953 | # $arg - The first (and only) argument in the argument list | ||
| 954 | # | ||
| 955 | # Return values | ||
| 956 | # The return value of the function | ||
| 957 | |||
| 958 | my ($self, $arg) = @_; | ||
| 959 | |||
| 960 | # (No improper arguments to check) | ||
| 961 | |||
| 962 | # Evaluate the function and return the value | ||
| 963 | return POSIX::ceil($arg); | ||
| 964 | } | ||
| 965 | } | ||
| 966 | |||
| 967 | { package Language::Axbasic::Function::Intrinsic::Numeric::cos; | ||
| 968 | |||
| 969 | use strict; | ||
| 970 | use warnings; | ||
| 971 | # use diagnostics; | ||
| 972 | |||
| 973 | use Glib qw(TRUE FALSE); | ||
| 974 | |||
| 975 | @Language::Axbasic::Function::Intrinsic::Numeric::cos::ISA = qw( | ||
| 976 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 977 | ); | ||
| 978 | |||
| 979 | # Cos (x) | ||
| 980 | |||
| 981 | ################## | ||
| 982 | # Methods | ||
| 983 | |||
| 984 | sub evaluate { | ||
| 985 | |||
| 986 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 987 | # | ||
| 988 | # Expected arguments | ||
| 989 | # $arg - The first (and only) argument in the argument list | ||
| 990 | # | ||
| 991 | # Return values | ||
| 992 | # The return value of the function | ||
| 993 | |||
| 994 | my ($self, $arg) = @_; | ||
| 995 | |||
| 996 | # (No improper arguments to check) | ||
| 997 | |||
| 998 | # Evaluate the function and return the value | ||
| 999 | |||
| 1000 | # Use radians (default) or degrees? | ||
| 1001 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 1002 | |||
| 1003 | # Convert to radians | ||
| 1004 | $arg = Math::Trig::deg2rad($arg); | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | # Evaluate the function and return the value | ||
| 1008 | return cos($arg); | ||
| 1009 | } | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | { package Language::Axbasic::Function::Intrinsic::Numeric::cosh; | ||
| 1013 | |||
| 1014 | use strict; | ||
| 1015 | use warnings; | ||
| 1016 | # use diagnostics; | ||
| 1017 | |||
| 1018 | use Glib qw(TRUE FALSE); | ||
| 1019 | |||
| 1020 | @Language::Axbasic::Function::Intrinsic::Numeric::cosh::ISA = qw( | ||
| 1021 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1022 | ); | ||
| 1023 | |||
| 1024 | # Cosh (x) | ||
| 1025 | |||
| 1026 | ################## | ||
| 1027 | # Methods | ||
| 1028 | |||
| 1029 | sub evaluate { | ||
| 1030 | |||
| 1031 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1032 | # | ||
| 1033 | # Expected arguments | ||
| 1034 | # $arg - The first (and only) argument in the argument list | ||
| 1035 | # | ||
| 1036 | # Return values | ||
| 1037 | # The return value of the function | ||
| 1038 | |||
| 1039 | my ($self, $arg) = @_; | ||
| 1040 | |||
| 1041 | # (No improper arguments to check) | ||
| 1042 | |||
| 1043 | # Evaluate the function and return the value | ||
| 1044 | return Math::Trig::cosh($arg); | ||
| 1045 | } | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | { package Language::Axbasic::Function::Intrinsic::Numeric::cot; | ||
| 1049 | |||
| 1050 | use strict; | ||
| 1051 | use warnings; | ||
| 1052 | # use diagnostics; | ||
| 1053 | |||
| 1054 | use Glib qw(TRUE FALSE); | ||
| 1055 | |||
| 1056 | @Language::Axbasic::Function::Intrinsic::Numeric::cot::ISA = qw( | ||
| 1057 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1058 | ); | ||
| 1059 | |||
| 1060 | # Cot (x) | ||
| 1061 | |||
| 1062 | ################## | ||
| 1063 | # Methods | ||
| 1064 | |||
| 1065 | sub evaluate { | ||
| 1066 | |||
| 1067 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1068 | # | ||
| 1069 | # Expected arguments | ||
| 1070 | # $arg - The first (and only) argument in the argument list | ||
| 1071 | # | ||
| 1072 | # Return values | ||
| 1073 | # The return value of the function | ||
| 1074 | |||
| 1075 | my ($self, $arg) = @_; | ||
| 1076 | |||
| 1077 | # Local variables | ||
| 1078 | my $value; | ||
| 1079 | |||
| 1080 | # (No improper arguments to check) | ||
| 1081 | |||
| 1082 | # Evaluate the function and return the value | ||
| 1083 | |||
| 1084 | # The value of $arg cannot be 0 (because this would cause division by 0) | ||
| 1085 | if (! $arg) { | ||
| 1086 | |||
| 1087 | return $self->scriptObj->setError( | ||
| 1088 | 'number_NUM_out_of_range', | ||
| 1089 | $self->_objClass . '->evaluate', | ||
| 1090 | 'NUM', $arg, | ||
| 1091 | ); | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | # Use radians (default) or degrees? | ||
| 1095 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 1096 | |||
| 1097 | # Convert to radians | ||
| 1098 | $arg = Math::Trig::deg2rad($arg); | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | # Evaluate the function and return the value | ||
| 1102 | return Math::Trig::cot($arg); | ||
| 1103 | } | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | { package Language::Axbasic::Function::Intrinsic::Numeric::cpos; | ||
| 1107 | |||
| 1108 | use strict; | ||
| 1109 | use warnings; | ||
| 1110 | # use diagnostics; | ||
| 1111 | |||
| 1112 | use Glib qw(TRUE FALSE); | ||
| 1113 | |||
| 1114 | @Language::Axbasic::Function::Intrinsic::Numeric::cpos::ISA = qw( | ||
| 1115 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1116 | ); | ||
| 1117 | |||
| 1118 | # Cpos (string, substring) | ||
| 1119 | # Cpos (string, substring, n) | ||
| 1120 | |||
| 1121 | ################## | ||
| 1122 | # Methods | ||
| 1123 | |||
| 1124 | sub evaluate { | ||
| 1125 | |||
| 1126 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N') | ||
| 1127 | # | ||
| 1128 | # Expected arguments | ||
| 1129 | # $string, $subString, $position | ||
| 1130 | # - The list of arguments supplied to the function | ||
| 1131 | # | ||
| 1132 | # Return values | ||
| 1133 | # The return value of the function | ||
| 1134 | |||
| 1135 | my ($self, $string, $subString, $posn) = @_; | ||
| 1136 | |||
| 1137 | # Local variables | ||
| 1138 | my ( | ||
| 1139 | $result, | ||
| 1140 | @charList, | ||
| 1141 | ); | ||
| 1142 | |||
| 1143 | # (No improper arguments to check) | ||
| 1144 | |||
| 1145 | # Evaluate the function and return the value | ||
| 1146 | if (defined $posn) { | ||
| 1147 | |||
| 1148 | # $posn must not be zero or a negative number | ||
| 1149 | if ($posn < 1) { | ||
| 1150 | |||
| 1151 | return $self->scriptObj->setError( | ||
| 1152 | 'number_NUM_out_of_range', | ||
| 1153 | $self->_objClass . '->evaluate', | ||
| 1154 | 'NUM', $posn, | ||
| 1155 | ); | ||
| 1156 | } | ||
| 1157 | |||
| 1158 | # $posn must be rounded | ||
| 1159 | $posn = substr( | ||
| 1160 | $posn + 0.5, | ||
| 1161 | 0, | ||
| 1162 | length(int($posn + 0.5)), | ||
| 1163 | ); | ||
| 1164 | |||
| 1165 | # Finally, Perl's index() function uses the number 0 for the first character in the | ||
| 1166 | # string, but True BASIC uses the number 1 | ||
| 1167 | $posn--; | ||
| 1168 | } | ||
| 1169 | |||
| 1170 | # If either string is a null string, True BASIC returns 0 | ||
| 1171 | if (! $string || ! $subString) { | ||
| 1172 | |||
| 1173 | return 0; | ||
| 1174 | } | ||
| 1175 | |||
| 1176 | # Evaluate the function for each character in $subString | ||
| 1177 | @charList = split(//, $subString); | ||
| 1178 | foreach my $char (@charList) { | ||
| 1179 | |||
| 1180 | if (defined $posn) { | ||
| 1181 | $result = index($string, $char, $posn); | ||
| 1182 | } else { | ||
| 1183 | $result = index($string, $char); | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | if ($result != -1) { | ||
| 1187 | |||
| 1188 | # Look for 'g' in 'disgust' - Perl returns 3, but True BASIC returns 4 | ||
| 1189 | return ($result + 1); | ||
| 1190 | } | ||
| 1191 | } | ||
| 1192 | |||
| 1193 | # No character in the substring was found in the string | ||
| 1194 | return 0; | ||
| 1195 | } | ||
| 1196 | } | ||
| 1197 | |||
| 1198 | { package Language::Axbasic::Function::Intrinsic::Numeric::cposr; | ||
| 1199 | |||
| 1200 | use strict; | ||
| 1201 | use warnings; | ||
| 1202 | # use diagnostics; | ||
| 1203 | |||
| 1204 | use Glib qw(TRUE FALSE); | ||
| 1205 | |||
| 1206 | @Language::Axbasic::Function::Intrinsic::Numeric::cposr::ISA = qw( | ||
| 1207 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1208 | ); | ||
| 1209 | |||
| 1210 | # Cposr (string, substring) | ||
| 1211 | # Cposr (string, substring, n) | ||
| 1212 | |||
| 1213 | ################## | ||
| 1214 | # Methods | ||
| 1215 | |||
| 1216 | sub evaluate { | ||
| 1217 | |||
| 1218 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N') | ||
| 1219 | # | ||
| 1220 | # Expected arguments | ||
| 1221 | # $string, $subString, $posn | ||
| 1222 | # - The list of arguments supplied to the function | ||
| 1223 | # | ||
| 1224 | # Return values | ||
| 1225 | # The return value of the function | ||
| 1226 | |||
| 1227 | my ($self, $string, $subString, $posn) = @_; | ||
| 1228 | |||
| 1229 | # Local variables | ||
| 1230 | my ( | ||
| 1231 | $result, | ||
| 1232 | @charList, | ||
| 1233 | ); | ||
| 1234 | |||
| 1235 | # (No improper arguments to check) | ||
| 1236 | |||
| 1237 | # Evaluate the function and return the value | ||
| 1238 | if (defined $posn) { | ||
| 1239 | |||
| 1240 | # $posn must not be zero or a negative number | ||
| 1241 | if ($posn < 1) { | ||
| 1242 | |||
| 1243 | return $self->scriptObj->setError( | ||
| 1244 | 'number_NUM_out_of_range', | ||
| 1245 | $self->_objClass . '->evaluate', | ||
| 1246 | 'NUM', $posn, | ||
| 1247 | ); | ||
| 1248 | } | ||
| 1249 | |||
| 1250 | # $posn must be rounded | ||
| 1251 | $posn = substr( | ||
| 1252 | $posn + 0.5, | ||
| 1253 | 0, | ||
| 1254 | length(int($posn + 0.5)), | ||
| 1255 | ); | ||
| 1256 | |||
| 1257 | # Finally, Perl's index() function uses the number 0 for the first character in the | ||
| 1258 | # string, but True BASIC uses the number 1 | ||
| 1259 | $posn--; | ||
| 1260 | } | ||
| 1261 | |||
| 1262 | # If either string is a null string, True BASIC returns 0 | ||
| 1263 | if (! $string || ! $subString) { | ||
| 1264 | |||
| 1265 | return 0; | ||
| 1266 | } | ||
| 1267 | |||
| 1268 | # Evaluate the function for each character in $subString | ||
| 1269 | @charList = split(//, $subString); | ||
| 1270 | foreach my $char (@charList) { | ||
| 1271 | |||
| 1272 | if (defined $posn) { | ||
| 1273 | $result = rindex($string, $char, $posn); | ||
| 1274 | } else { | ||
| 1275 | $result = rindex($string, $char); | ||
| 1276 | } | ||
| 1277 | |||
| 1278 | if ($result != -1) { | ||
| 1279 | |||
| 1280 | # Look for 'g' in 'disgust' - Perl returns 3, but True BASIC returns 4 | ||
| 1281 | return ($result + 1); | ||
| 1282 | } | ||
| 1283 | } | ||
| 1284 | |||
| 1285 | # No character in the substring was found in the string | ||
| 1286 | return 0; | ||
| 1287 | } | ||
| 1288 | } | ||
| 1289 | |||
| 1290 | { package Language::Axbasic::Function::Intrinsic::Numeric::csc; | ||
| 1291 | |||
| 1292 | use strict; | ||
| 1293 | use warnings; | ||
| 1294 | # use diagnostics; | ||
| 1295 | |||
| 1296 | use Glib qw(TRUE FALSE); | ||
| 1297 | |||
| 1298 | @Language::Axbasic::Function::Intrinsic::Numeric::csc::ISA = qw( | ||
| 1299 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1300 | ); | ||
| 1301 | |||
| 1302 | # Csc (x) | ||
| 1303 | |||
| 1304 | ################## | ||
| 1305 | # Methods | ||
| 1306 | |||
| 1307 | sub evaluate { | ||
| 1308 | |||
| 1309 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1310 | # | ||
| 1311 | # Expected arguments | ||
| 1312 | # $arg - The first (and only) argument in the argument list | ||
| 1313 | # | ||
| 1314 | # Return values | ||
| 1315 | # The return value of the function | ||
| 1316 | |||
| 1317 | my ($self, $arg) = @_; | ||
| 1318 | |||
| 1319 | # (No improper arguments to check) | ||
| 1320 | |||
| 1321 | # Evaluate the function and return the value | ||
| 1322 | |||
| 1323 | # The value of $arg cannot be 0 (because this would cause division by 0) | ||
| 1324 | if (! $arg) { | ||
| 1325 | |||
| 1326 | return $self->scriptObj->setError( | ||
| 1327 | 'number_NUM_out_of_range', | ||
| 1328 | $self->_objClass . '->evaluate', | ||
| 1329 | 'NUM', $arg, | ||
| 1330 | ); | ||
| 1331 | } | ||
| 1332 | |||
| 1333 | # Use radians (default) or degrees? | ||
| 1334 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 1335 | |||
| 1336 | # Convert to radians | ||
| 1337 | $arg = Math::Trig::deg2rad($arg); | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | # Evaluate the function and return the value | ||
| 1341 | return Math::Trig::csc($arg); | ||
| 1342 | } | ||
| 1343 | } | ||
| 1344 | |||
| 1345 | { package Language::Axbasic::Function::Intrinsic::Numeric::date; | ||
| 1346 | |||
| 1347 | use strict; | ||
| 1348 | use warnings; | ||
| 1349 | # use diagnostics; | ||
| 1350 | |||
| 1351 | use Glib qw(TRUE FALSE); | ||
| 1352 | |||
| 1353 | @Language::Axbasic::Function::Intrinsic::Numeric::date::ISA = qw( | ||
| 1354 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1355 | ); | ||
| 1356 | |||
| 1357 | # Date () | ||
| 1358 | |||
| 1359 | ################## | ||
| 1360 | # Methods | ||
| 1361 | |||
| 1362 | sub evaluate { | ||
| 1363 | |||
| 1364 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 1365 | # | ||
| 1366 | # Expected arguments | ||
| 1367 | # $arg - The first (and only) argument in the argument list | ||
| 1368 | # | ||
| 1369 | # Return values | ||
| 1370 | # The return value of the function | ||
| 1371 | |||
| 1372 | my ($self, $arg) = @_; | ||
| 1373 | |||
| 1374 | # (No improper arguments to check) | ||
| 1375 | |||
| 1376 | # Evaluate the function and return the value | ||
| 1377 | |||
| 1378 | # Get the time and date | ||
| 1379 | my ( | ||
| 1380 | $second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, | ||
| 1381 | $daylightSavings, | ||
| 1382 | ) = localtime(); | ||
| 1383 | |||
| 1384 | # Return a value in the form YYDDD, where YY is in the range 00-99, and DDD is in the | ||
| 1385 | # range 1-365 | ||
| 1386 | return (sprintf("%02d", $yearOffset % 100) . ($dayOfYear + 1)); | ||
| 1387 | } | ||
| 1388 | } | ||
| 1389 | |||
| 1390 | { package Language::Axbasic::Function::Intrinsic::Numeric::deg; | ||
| 1391 | |||
| 1392 | use strict; | ||
| 1393 | use warnings; | ||
| 1394 | # use diagnostics; | ||
| 1395 | |||
| 1396 | use Glib qw(TRUE FALSE); | ||
| 1397 | |||
| 1398 | @Language::Axbasic::Function::Intrinsic::Numeric::deg::ISA = qw( | ||
| 1399 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1400 | ); | ||
| 1401 | |||
| 1402 | # Deg (x) | ||
| 1403 | |||
| 1404 | ################## | ||
| 1405 | # Methods | ||
| 1406 | |||
| 1407 | sub evaluate { | ||
| 1408 | |||
| 1409 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1410 | # | ||
| 1411 | # Expected arguments | ||
| 1412 | # $arg - The first (and only) argument in the argument list | ||
| 1413 | # | ||
| 1414 | # Return values | ||
| 1415 | # The return value of the function | ||
| 1416 | |||
| 1417 | my ($self, $arg) = @_; | ||
| 1418 | |||
| 1419 | # (No improper arguments to check) | ||
| 1420 | |||
| 1421 | # Evaluate the function and return the value | ||
| 1422 | return Math::Trig::rad2deg($arg); | ||
| 1423 | } | ||
| 1424 | } | ||
| 1425 | |||
| 1426 | { package Language::Axbasic::Function::Intrinsic::Numeric::eof; | ||
| 1427 | |||
| 1428 | use strict; | ||
| 1429 | use warnings; | ||
| 1430 | # use diagnostics; | ||
| 1431 | |||
| 1432 | use Glib qw(TRUE FALSE); | ||
| 1433 | |||
| 1434 | @Language::Axbasic::Function::Intrinsic::Numeric::eof::ISA = qw( | ||
| 1435 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1436 | ); | ||
| 1437 | |||
| 1438 | # Eof (channel) | ||
| 1439 | |||
| 1440 | ################## | ||
| 1441 | # Methods | ||
| 1442 | |||
| 1443 | sub evaluate { | ||
| 1444 | |||
| 1445 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1446 | # | ||
| 1447 | # Expected arguments | ||
| 1448 | # $arg - The first (and only) argument in the argument list | ||
| 1449 | # | ||
| 1450 | # Return values | ||
| 1451 | # The return value of the function | ||
| 1452 | |||
| 1453 | my ($self, $arg) = @_; | ||
| 1454 | |||
| 1455 | # Local variables | ||
| 1456 | my $channelObj; | ||
| 1457 | |||
| 1458 | # (No improper arguments to check) | ||
| 1459 | |||
| 1460 | # Evaluate the function and return the value | ||
| 1461 | |||
| 1462 | # Check that the file channel exists | ||
| 1463 | if (! $self->scriptObj->ivExists('fileChannelHash', $arg)) { | ||
| 1464 | |||
| 1465 | # File channel not open | ||
| 1466 | return 0; | ||
| 1467 | |||
| 1468 | } else { | ||
| 1469 | |||
| 1470 | $channelObj = $self->scriptObj->ivShow('fileChannelHash', $arg); | ||
| 1471 | |||
| 1472 | if (eof($channelObj->fileHandle)) { | ||
| 1473 | |||
| 1474 | # End of file reached, or filehandle not open | ||
| 1475 | return 1; | ||
| 1476 | |||
| 1477 | } else { | ||
| 1478 | |||
| 1479 | # End of file not reached | ||
| 1480 | return 0; | ||
| 1481 | } | ||
| 1482 | } | ||
| 1483 | } | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | { package Language::Axbasic::Function::Intrinsic::Numeric::epoch; | ||
| 1487 | |||
| 1488 | use strict; | ||
| 1489 | use warnings; | ||
| 1490 | # use diagnostics; | ||
| 1491 | |||
| 1492 | use Glib qw(TRUE FALSE); | ||
| 1493 | |||
| 1494 | @Language::Axbasic::Function::Intrinsic::Numeric::epoch::ISA = qw( | ||
| 1495 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1496 | ); | ||
| 1497 | |||
| 1498 | # Epoch () | ||
| 1499 | |||
| 1500 | ################## | ||
| 1501 | # Methods | ||
| 1502 | |||
| 1503 | sub evaluate { | ||
| 1504 | |||
| 1505 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 1506 | # | ||
| 1507 | # Expected arguments | ||
| 1508 | # $arg - The first (and only) argument in the argument list | ||
| 1509 | # | ||
| 1510 | # Return values | ||
| 1511 | # The return value of the function | ||
| 1512 | |||
| 1513 | my ($self, $arg) = @_; | ||
| 1514 | |||
| 1515 | # (No improper arguments to check) | ||
| 1516 | |||
| 1517 | # Evaluate the function and return the value | ||
| 1518 | return time; | ||
| 1519 | } | ||
| 1520 | } | ||
| 1521 | |||
| 1522 | { package Language::Axbasic::Function::Intrinsic::Numeric::exp; | ||
| 1523 | |||
| 1524 | use strict; | ||
| 1525 | use warnings; | ||
| 1526 | # use diagnostics; | ||
| 1527 | |||
| 1528 | use Glib qw(TRUE FALSE); | ||
| 1529 | |||
| 1530 | @Language::Axbasic::Function::Intrinsic::Numeric::exp::ISA = qw( | ||
| 1531 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1532 | ); | ||
| 1533 | |||
| 1534 | # Exp (x) | ||
| 1535 | |||
| 1536 | ################## | ||
| 1537 | # Methods | ||
| 1538 | |||
| 1539 | sub evaluate { | ||
| 1540 | |||
| 1541 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1542 | # | ||
| 1543 | # Expected arguments | ||
| 1544 | # $arg - The first (and only) argument in the argument list | ||
| 1545 | # | ||
| 1546 | # Return values | ||
| 1547 | # The return value of the function | ||
| 1548 | |||
| 1549 | my ($self, $arg) = @_; | ||
| 1550 | |||
| 1551 | # (No improper arguments to check) | ||
| 1552 | |||
| 1553 | # Evaluate the function and return the value | ||
| 1554 | return exp($arg); | ||
| 1555 | } | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | { package Language::Axbasic::Function::Intrinsic::Numeric::floor; | ||
| 1559 | |||
| 1560 | use strict; | ||
| 1561 | use warnings; | ||
| 1562 | # use diagnostics; | ||
| 1563 | |||
| 1564 | use Glib qw(TRUE FALSE); | ||
| 1565 | |||
| 1566 | @Language::Axbasic::Function::Intrinsic::Numeric::floor::ISA = qw( | ||
| 1567 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1568 | ); | ||
| 1569 | |||
| 1570 | # Floor (x) | ||
| 1571 | |||
| 1572 | ################## | ||
| 1573 | # Methods | ||
| 1574 | |||
| 1575 | sub evaluate { | ||
| 1576 | |||
| 1577 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1578 | # | ||
| 1579 | # Expected arguments | ||
| 1580 | # $arg - The first (and only) argument in the argument list | ||
| 1581 | # | ||
| 1582 | # Return values | ||
| 1583 | # The return value of the function | ||
| 1584 | |||
| 1585 | my ($self, $arg) = @_; | ||
| 1586 | |||
| 1587 | # (No improper arguments to check) | ||
| 1588 | |||
| 1589 | # Evaluate the function and return the value | ||
| 1590 | return POSIX::floor($arg); | ||
| 1591 | } | ||
| 1592 | } | ||
| 1593 | |||
| 1594 | { package Language::Axbasic::Function::Intrinsic::Numeric::fp; | ||
| 1595 | |||
| 1596 | use strict; | ||
| 1597 | use warnings; | ||
| 1598 | # use diagnostics; | ||
| 1599 | |||
| 1600 | use Glib qw(TRUE FALSE); | ||
| 1601 | |||
| 1602 | @Language::Axbasic::Function::Intrinsic::Numeric::fp::ISA = qw( | ||
| 1603 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1604 | ); | ||
| 1605 | |||
| 1606 | # Fp (x) | ||
| 1607 | |||
| 1608 | ################## | ||
| 1609 | # Methods | ||
| 1610 | |||
| 1611 | sub evaluate { | ||
| 1612 | |||
| 1613 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1614 | # | ||
| 1615 | # Expected arguments | ||
| 1616 | # $arg - The first (and only) argument in the argument list | ||
| 1617 | # | ||
| 1618 | # Return values | ||
| 1619 | # The return value of the function | ||
| 1620 | |||
| 1621 | my ($self, $arg) = @_; | ||
| 1622 | |||
| 1623 | # (No improper arguments to check) | ||
| 1624 | |||
| 1625 | # Evaluate the function and return the value | ||
| 1626 | return ($arg - int($arg)); | ||
| 1627 | } | ||
| 1628 | } | ||
| 1629 | |||
| 1630 | { package Language::Axbasic::Function::Intrinsic::Numeric::int; | ||
| 1631 | |||
| 1632 | use strict; | ||
| 1633 | use warnings; | ||
| 1634 | # use diagnostics; | ||
| 1635 | |||
| 1636 | use Glib qw(TRUE FALSE); | ||
| 1637 | |||
| 1638 | @Language::Axbasic::Function::Intrinsic::Numeric::int::ISA = qw( | ||
| 1639 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1640 | ); | ||
| 1641 | |||
| 1642 | # Int (number) | ||
| 1643 | |||
| 1644 | ################## | ||
| 1645 | # Methods | ||
| 1646 | |||
| 1647 | sub evaluate { | ||
| 1648 | |||
| 1649 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1650 | # | ||
| 1651 | # Expected arguments | ||
| 1652 | # $arg - The first (and only) argument in the argument list | ||
| 1653 | # | ||
| 1654 | # Return values | ||
| 1655 | # The return value of the function | ||
| 1656 | |||
| 1657 | my ($self, $arg) = @_; | ||
| 1658 | |||
| 1659 | # (No improper arguments to check) | ||
| 1660 | |||
| 1661 | # Evaluate the function and return the value | ||
| 1662 | if ($arg < 0) { | ||
| 1663 | return (int($arg) - 1); | ||
| 1664 | } else { | ||
| 1665 | return (int($arg)); | ||
| 1666 | } | ||
| 1667 | } | ||
| 1668 | } | ||
| 1669 | |||
| 1670 | { package Language::Axbasic::Function::Intrinsic::Numeric::ip; | ||
| 1671 | |||
| 1672 | use strict; | ||
| 1673 | use warnings; | ||
| 1674 | # use diagnostics; | ||
| 1675 | |||
| 1676 | use Glib qw(TRUE FALSE); | ||
| 1677 | |||
| 1678 | @Language::Axbasic::Function::Intrinsic::Numeric::ip::ISA = qw( | ||
| 1679 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1680 | ); | ||
| 1681 | |||
| 1682 | # Ip (x) | ||
| 1683 | |||
| 1684 | ################## | ||
| 1685 | # Methods | ||
| 1686 | |||
| 1687 | sub evaluate { | ||
| 1688 | |||
| 1689 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1690 | # | ||
| 1691 | # Expected arguments | ||
| 1692 | # $arg - The first (and only) argument in the argument list | ||
| 1693 | # | ||
| 1694 | # Return values | ||
| 1695 | # The return value of the function | ||
| 1696 | |||
| 1697 | my ($self, $arg) = @_; | ||
| 1698 | |||
| 1699 | # (No improper arguments to check) | ||
| 1700 | |||
| 1701 | # Evaluate the function and return the value | ||
| 1702 | return int($arg); | ||
| 1703 | } | ||
| 1704 | } | ||
| 1705 | |||
| 1706 | { package Language::Axbasic::Function::Intrinsic::Numeric::len; | ||
| 1707 | |||
| 1708 | use strict; | ||
| 1709 | use warnings; | ||
| 1710 | # use diagnostics; | ||
| 1711 | |||
| 1712 | use Glib qw(TRUE FALSE); | ||
| 1713 | |||
| 1714 | @Language::Axbasic::Function::Intrinsic::Numeric::len::ISA = qw( | ||
| 1715 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1716 | ); | ||
| 1717 | |||
| 1718 | # Len (string) | ||
| 1719 | |||
| 1720 | ################## | ||
| 1721 | # Methods | ||
| 1722 | |||
| 1723 | sub evaluate { | ||
| 1724 | |||
| 1725 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 1726 | # | ||
| 1727 | # Expected arguments | ||
| 1728 | # $arg - The first (and only) argument in the argument list | ||
| 1729 | # | ||
| 1730 | # Return values | ||
| 1731 | # The return value of the function | ||
| 1732 | |||
| 1733 | my ($self, $arg) = @_; | ||
| 1734 | |||
| 1735 | # (No improper arguments to check) | ||
| 1736 | |||
| 1737 | # Evaluate the function and return the value | ||
| 1738 | return length($arg); | ||
| 1739 | } | ||
| 1740 | } | ||
| 1741 | |||
| 1742 | { package Language::Axbasic::Function::Intrinsic::Numeric::log; | ||
| 1743 | |||
| 1744 | use strict; | ||
| 1745 | use warnings; | ||
| 1746 | # use diagnostics; | ||
| 1747 | |||
| 1748 | use Glib qw(TRUE FALSE); | ||
| 1749 | |||
| 1750 | @Language::Axbasic::Function::Intrinsic::Numeric::log::ISA = qw( | ||
| 1751 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1752 | ); | ||
| 1753 | |||
| 1754 | # Log (x) | ||
| 1755 | |||
| 1756 | ################## | ||
| 1757 | # Methods | ||
| 1758 | |||
| 1759 | sub evaluate { | ||
| 1760 | |||
| 1761 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1762 | # | ||
| 1763 | # Expected arguments | ||
| 1764 | # $arg - The first (and only) argument in the argument list | ||
| 1765 | # | ||
| 1766 | # Return values | ||
| 1767 | # The return value of the function | ||
| 1768 | |||
| 1769 | my ($self, $arg) = @_; | ||
| 1770 | |||
| 1771 | # (No improper arguments to check) | ||
| 1772 | |||
| 1773 | # Evaluate the function and return the value | ||
| 1774 | return log($arg); | ||
| 1775 | } | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | { package Language::Axbasic::Function::Intrinsic::Numeric::log2; | ||
| 1779 | |||
| 1780 | use strict; | ||
| 1781 | use warnings; | ||
| 1782 | # use diagnostics; | ||
| 1783 | |||
| 1784 | use Glib qw(TRUE FALSE); | ||
| 1785 | |||
| 1786 | @Language::Axbasic::Function::Intrinsic::Numeric::log2::ISA = qw( | ||
| 1787 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1788 | ); | ||
| 1789 | |||
| 1790 | # Log2 (x) | ||
| 1791 | |||
| 1792 | ################## | ||
| 1793 | # Methods | ||
| 1794 | |||
| 1795 | sub evaluate { | ||
| 1796 | |||
| 1797 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1798 | # | ||
| 1799 | # Expected arguments | ||
| 1800 | # $arg - The first (and only) argument in the argument list | ||
| 1801 | # | ||
| 1802 | # Return values | ||
| 1803 | # The return value of the function | ||
| 1804 | |||
| 1805 | my ($self, $arg) = @_; | ||
| 1806 | |||
| 1807 | # (No improper arguments to check) | ||
| 1808 | |||
| 1809 | # Evaluate the function and return the value | ||
| 1810 | return (log($arg) / log(2)); | ||
| 1811 | } | ||
| 1812 | } | ||
| 1813 | |||
| 1814 | { package Language::Axbasic::Function::Intrinsic::Numeric::log10; | ||
| 1815 | |||
| 1816 | use strict; | ||
| 1817 | use warnings; | ||
| 1818 | # use diagnostics; | ||
| 1819 | |||
| 1820 | use Glib qw(TRUE FALSE); | ||
| 1821 | |||
| 1822 | @Language::Axbasic::Function::Intrinsic::Numeric::log10::ISA = qw( | ||
| 1823 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1824 | ); | ||
| 1825 | |||
| 1826 | # Log10 (x) | ||
| 1827 | |||
| 1828 | ################## | ||
| 1829 | # Methods | ||
| 1830 | |||
| 1831 | sub evaluate { | ||
| 1832 | |||
| 1833 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 1834 | # | ||
| 1835 | # Expected arguments | ||
| 1836 | # $arg - The first (and only) argument in the argument list | ||
| 1837 | # | ||
| 1838 | # Return values | ||
| 1839 | # The return value of the function | ||
| 1840 | |||
| 1841 | my ($self, $arg) = @_; | ||
| 1842 | |||
| 1843 | # (No improper arguments to check) | ||
| 1844 | |||
| 1845 | # Evaluate the function and return the value | ||
| 1846 | return (log($arg) / log(10)); | ||
| 1847 | } | ||
| 1848 | } | ||
| 1849 | |||
| 1850 | { package Language::Axbasic::Function::Intrinsic::Numeric::match; | ||
| 1851 | |||
| 1852 | use strict; | ||
| 1853 | use warnings; | ||
| 1854 | # use diagnostics; | ||
| 1855 | |||
| 1856 | use Glib qw(TRUE FALSE); | ||
| 1857 | |||
| 1858 | @Language::Axbasic::Function::Intrinsic::Numeric::match::ISA = qw( | ||
| 1859 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1860 | ); | ||
| 1861 | |||
| 1862 | # Match (string, regex) | ||
| 1863 | |||
| 1864 | ################## | ||
| 1865 | # Methods | ||
| 1866 | |||
| 1867 | sub evaluate { | ||
| 1868 | |||
| 1869 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS') | ||
| 1870 | # | ||
| 1871 | # Expected arguments | ||
| 1872 | # @args - The list of arguments supplied to the function | ||
| 1873 | # | ||
| 1874 | # Return values | ||
| 1875 | # The return value of the function | ||
| 1876 | |||
| 1877 | my ($self, @args) = @_; | ||
| 1878 | |||
| 1879 | # Local variables | ||
| 1880 | my ($string, $regex); | ||
| 1881 | |||
| 1882 | # (No improper arguments to check) | ||
| 1883 | |||
| 1884 | # Evaluate the function and return the value | ||
| 1885 | ($string, $regex) = @args; | ||
| 1886 | |||
| 1887 | if ($string =~ m/$regex/) { | ||
| 1888 | return 1; | ||
| 1889 | } else { | ||
| 1890 | return 0; | ||
| 1891 | } | ||
| 1892 | } | ||
| 1893 | } | ||
| 1894 | |||
| 1895 | { package Language::Axbasic::Function::Intrinsic::Numeric::matchi; | ||
| 1896 | |||
| 1897 | use strict; | ||
| 1898 | use warnings; | ||
| 1899 | # use diagnostics; | ||
| 1900 | |||
| 1901 | use Glib qw(TRUE FALSE); | ||
| 1902 | |||
| 1903 | @Language::Axbasic::Function::Intrinsic::Numeric::matchi::ISA = qw( | ||
| 1904 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1905 | ); | ||
| 1906 | |||
| 1907 | # Matchi (string, regex) | ||
| 1908 | |||
| 1909 | ################## | ||
| 1910 | # Methods | ||
| 1911 | |||
| 1912 | sub evaluate { | ||
| 1913 | |||
| 1914 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS') | ||
| 1915 | # | ||
| 1916 | # Expected arguments | ||
| 1917 | # @args - The list of arguments supplied to the function | ||
| 1918 | # | ||
| 1919 | # Return values | ||
| 1920 | # The return value of the function | ||
| 1921 | |||
| 1922 | my ($self, @args) = @_; | ||
| 1923 | |||
| 1924 | # Local variables | ||
| 1925 | my ($string, $regex); | ||
| 1926 | |||
| 1927 | # (No improper arguments to check) | ||
| 1928 | |||
| 1929 | # Evaluate the function and return the value | ||
| 1930 | ($string, $regex) = @args; | ||
| 1931 | |||
| 1932 | if ($string =~ m/$regex/i) { | ||
| 1933 | return 1; | ||
| 1934 | } else { | ||
| 1935 | return 0; | ||
| 1936 | } | ||
| 1937 | } | ||
| 1938 | } | ||
| 1939 | |||
| 1940 | { package Language::Axbasic::Function::Intrinsic::Numeric::max; | ||
| 1941 | |||
| 1942 | use strict; | ||
| 1943 | use warnings; | ||
| 1944 | # use diagnostics; | ||
| 1945 | |||
| 1946 | use Glib qw(TRUE FALSE); | ||
| 1947 | |||
| 1948 | @Language::Axbasic::Function::Intrinsic::Numeric::max::ISA = qw( | ||
| 1949 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1950 | ); | ||
| 1951 | |||
| 1952 | # Max (x, y) | ||
| 1953 | |||
| 1954 | ################## | ||
| 1955 | # Methods | ||
| 1956 | |||
| 1957 | sub evaluate { | ||
| 1958 | |||
| 1959 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN') | ||
| 1960 | # | ||
| 1961 | # Expected arguments | ||
| 1962 | # @args - The list of arguments supplied to the function | ||
| 1963 | # | ||
| 1964 | # Return values | ||
| 1965 | # The return value of the function | ||
| 1966 | |||
| 1967 | my ($self, @args) = @_; | ||
| 1968 | |||
| 1969 | # (No improper arguments to check) | ||
| 1970 | |||
| 1971 | # Evaluate the function and return the value | ||
| 1972 | if ($args[0] > $args[1]) { | ||
| 1973 | return $args[0]; | ||
| 1974 | } else { | ||
| 1975 | return $args[1]; | ||
| 1976 | } | ||
| 1977 | } | ||
| 1978 | } | ||
| 1979 | |||
| 1980 | { package Language::Axbasic::Function::Intrinsic::Numeric::min; | ||
| 1981 | |||
| 1982 | use strict; | ||
| 1983 | use warnings; | ||
| 1984 | # use diagnostics; | ||
| 1985 | |||
| 1986 | use Glib qw(TRUE FALSE); | ||
| 1987 | |||
| 1988 | @Language::Axbasic::Function::Intrinsic::Numeric::min::ISA = qw( | ||
| 1989 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 1990 | ); | ||
| 1991 | |||
| 1992 | # Min (x, y) | ||
| 1993 | |||
| 1994 | ################## | ||
| 1995 | # Methods | ||
| 1996 | |||
| 1997 | sub evaluate { | ||
| 1998 | |||
| 1999 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN') | ||
| 2000 | # | ||
| 2001 | # Expected arguments | ||
| 2002 | # @args - The list of arguments supplied to the function | ||
| 2003 | # | ||
| 2004 | # Return values | ||
| 2005 | # The return value of the function | ||
| 2006 | |||
| 2007 | my ($self, @args) = @_; | ||
| 2008 | |||
| 2009 | # (No improper arguments to check) | ||
| 2010 | |||
| 2011 | # Evaluate the function and return the value | ||
| 2012 | if ($args[0] < $args[1]) { | ||
| 2013 | return $args[0]; | ||
| 2014 | } else { | ||
| 2015 | return $args[1]; | ||
| 2016 | } | ||
| 2017 | } | ||
| 2018 | } | ||
| 2019 | |||
| 2020 | { package Language::Axbasic::Function::Intrinsic::Numeric::mod; | ||
| 2021 | |||
| 2022 | use strict; | ||
| 2023 | use warnings; | ||
| 2024 | # use diagnostics; | ||
| 2025 | |||
| 2026 | use Glib qw(TRUE FALSE); | ||
| 2027 | |||
| 2028 | @Language::Axbasic::Function::Intrinsic::Numeric::mod::ISA = qw( | ||
| 2029 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2030 | ); | ||
| 2031 | |||
| 2032 | # Mod (x, y) | ||
| 2033 | |||
| 2034 | ################## | ||
| 2035 | # Methods | ||
| 2036 | |||
| 2037 | sub evaluate { | ||
| 2038 | |||
| 2039 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN') | ||
| 2040 | # | ||
| 2041 | # Evaluates the function using the supplied arguments | ||
| 2042 | # | ||
| 2043 | # Expected arguments | ||
| 2044 | # @args - The list of arguments supplied to the function | ||
| 2045 | # | ||
| 2046 | # Return values | ||
| 2047 | # The return value of the function | ||
| 2048 | |||
| 2049 | my ($self, @args) = @_; | ||
| 2050 | |||
| 2051 | # (No improper arguments to check) | ||
| 2052 | |||
| 2053 | # Evaluate the function and return the value | ||
| 2054 | return ($args[0] % $args[1]); | ||
| 2055 | } | ||
| 2056 | } | ||
| 2057 | |||
| 2058 | { package Language::Axbasic::Function::Intrinsic::Numeric::ncpos; | ||
| 2059 | |||
| 2060 | use strict; | ||
| 2061 | use warnings; | ||
| 2062 | # use diagnostics; | ||
| 2063 | |||
| 2064 | use Glib qw(TRUE FALSE); | ||
| 2065 | |||
| 2066 | @Language::Axbasic::Function::Intrinsic::Numeric::ncpos::ISA = qw( | ||
| 2067 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2068 | ); | ||
| 2069 | |||
| 2070 | # Ncpos (string, substring) | ||
| 2071 | # Ncpos (string, substring, n) | ||
| 2072 | |||
| 2073 | ################## | ||
| 2074 | # Methods | ||
| 2075 | |||
| 2076 | sub evaluate { | ||
| 2077 | |||
| 2078 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N') | ||
| 2079 | # | ||
| 2080 | # Expected arguments | ||
| 2081 | # $string, $subString, $position | ||
| 2082 | # - The list of arguments supplied to the function | ||
| 2083 | # | ||
| 2084 | # Return values | ||
| 2085 | # The return value of the function | ||
| 2086 | |||
| 2087 | my ($self, $string, $subString, $posn) = @_; | ||
| 2088 | |||
| 2089 | # Local variables | ||
| 2090 | my @charList; | ||
| 2091 | |||
| 2092 | # (No improper arguments to check) | ||
| 2093 | |||
| 2094 | # Evaluate the function and return the value | ||
| 2095 | if (defined $posn) { | ||
| 2096 | |||
| 2097 | # If $string is a null string, True BASIC returns 0; | ||
| 2098 | if (! $string) { | ||
| 2099 | |||
| 2100 | return 0; | ||
| 2101 | |||
| 2102 | # If $subString is a null string, True BASIC returns the starting position | ||
| 2103 | } elsif (! $subString) { | ||
| 2104 | |||
| 2105 | return $posn; | ||
| 2106 | } | ||
| 2107 | |||
| 2108 | # $posn must not be zero or a negative number | ||
| 2109 | if ($posn < 1) { | ||
| 2110 | |||
| 2111 | return $self->scriptObj->setError( | ||
| 2112 | 'number_NUM_out_of_range', | ||
| 2113 | $self->_objClass . '->evaluate', | ||
| 2114 | 'NUM', $posn, | ||
| 2115 | ); | ||
| 2116 | } | ||
| 2117 | |||
| 2118 | # $posn must be rounded | ||
| 2119 | $posn = substr($posn + 0.5, 0, length(int($posn + 0.5))); | ||
| 2120 | |||
| 2121 | # Finally, Perl's index() function uses the number 0 for the first character in the | ||
| 2122 | # string, but True BASIC uses the number 1 | ||
| 2123 | $posn--; | ||
| 2124 | |||
| 2125 | } else { | ||
| 2126 | |||
| 2127 | # If either string is a null string, True BASIC returns 0 | ||
| 2128 | if (! $string || ! $subString) { | ||
| 2129 | |||
| 2130 | return 0; | ||
| 2131 | } | ||
| 2132 | |||
| 2133 | # We start the search at (Perl) character position 0 | ||
| 2134 | $posn = 0; | ||
| 2135 | } | ||
| 2136 | |||
| 2137 | # Evaluate the function for each character in $string | ||
| 2138 | @charList = split(//, $string); | ||
| 2139 | for (my $count = $posn; $count < length $string; $count++) { | ||
| 2140 | |||
| 2141 | if (index($subString, $charList[$count]) == -1) { | ||
| 2142 | |||
| 2143 | # The character doesn't appear in the substring | ||
| 2144 | return ($count + 1); | ||
| 2145 | } | ||
| 2146 | } | ||
| 2147 | |||
| 2148 | # No character in the string was found in the substring | ||
| 2149 | return 0; | ||
| 2150 | } | ||
| 2151 | } | ||
| 2152 | |||
| 2153 | { package Language::Axbasic::Function::Intrinsic::Numeric::ncposr; | ||
| 2154 | |||
| 2155 | use strict; | ||
| 2156 | use warnings; | ||
| 2157 | # use diagnostics; | ||
| 2158 | |||
| 2159 | use Glib qw(TRUE FALSE); | ||
| 2160 | |||
| 2161 | @Language::Axbasic::Function::Intrinsic::Numeric::ncposr::ISA = qw( | ||
| 2162 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2163 | ); | ||
| 2164 | |||
| 2165 | # Ncposr (string, substring) | ||
| 2166 | # Ncposr (string, substring, n) | ||
| 2167 | |||
| 2168 | ################## | ||
| 2169 | # Methods | ||
| 2170 | |||
| 2171 | sub evaluate { | ||
| 2172 | |||
| 2173 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N') | ||
| 2174 | # | ||
| 2175 | # Expected arguments | ||
| 2176 | # $string, $subString, $posn | ||
| 2177 | # - The list of arguments supplied to the function | ||
| 2178 | # | ||
| 2179 | # Return values | ||
| 2180 | # The return value of the function | ||
| 2181 | |||
| 2182 | my ($self, $string, $subString, $posn) = @_; | ||
| 2183 | |||
| 2184 | # Local variables | ||
| 2185 | my @charList; | ||
| 2186 | |||
| 2187 | # (No improper arguments to check) | ||
| 2188 | |||
| 2189 | # Evaluate the function and return the value | ||
| 2190 | if (defined $posn) { | ||
| 2191 | |||
| 2192 | # If $string is a null string, True BASIC returns 0; | ||
| 2193 | if (! $string) { | ||
| 2194 | |||
| 2195 | return 0; | ||
| 2196 | |||
| 2197 | # If $subString is a null string, True BASIC returns the starting position | ||
| 2198 | } elsif (! $subString) { | ||
| 2199 | |||
| 2200 | return $posn; | ||
| 2201 | } | ||
| 2202 | |||
| 2203 | # $posn must not be zero or a negative number | ||
| 2204 | if ($posn < 1) { | ||
| 2205 | |||
| 2206 | return $self->scriptObj->setError( | ||
| 2207 | 'number_NUM_out_of_range', | ||
| 2208 | $self->_objClass . '->evaluate', | ||
| 2209 | 'NUM', $posn, | ||
| 2210 | ); | ||
| 2211 | } | ||
| 2212 | |||
| 2213 | # $posn must be rounded | ||
| 2214 | $posn = substr( | ||
| 2215 | $posn + 0.5, | ||
| 2216 | 0, | ||
| 2217 | length(int($posn + 0.5)), | ||
| 2218 | ); | ||
| 2219 | |||
| 2220 | # Finally, Perl's index() function uses the number 0 for the first character in the | ||
| 2221 | # string, but True BASIC uses the number 1 | ||
| 2222 | $posn--; | ||
| 2223 | |||
| 2224 | } else { | ||
| 2225 | |||
| 2226 | # If the string is a null string, True BASIC returns 0 | ||
| 2227 | if (! $string) { | ||
| 2228 | |||
| 2229 | return 0; | ||
| 2230 | |||
| 2231 | # If the substring is a null string but the string isn't, True BASIC returns the length | ||
| 2232 | # of the string | ||
| 2233 | } elsif (! $subString) { | ||
| 2234 | |||
| 2235 | return length($string); | ||
| 2236 | } | ||
| 2237 | |||
| 2238 | # We start the search at the (Perl) end of the string | ||
| 2239 | $posn = (length($string) - 1); | ||
| 2240 | } | ||
| 2241 | |||
| 2242 | # Evaluate the function for each character in $string | ||
| 2243 | @charList = split(//, $string); | ||
| 2244 | for (my $count = $posn; $count >= 0; $count--) { | ||
| 2245 | |||
| 2246 | if (index($subString, $charList[$count]) == -1) { | ||
| 2247 | |||
| 2248 | # The character doesn't appear in the substring | ||
| 2249 | return ($count + 1); | ||
| 2250 | } | ||
| 2251 | } | ||
| 2252 | |||
| 2253 | # No character in the string was found in the substring | ||
| 2254 | return 0; | ||
| 2255 | } | ||
| 2256 | } | ||
| 2257 | |||
| 2258 | { package Language::Axbasic::Function::Intrinsic::Numeric::pi; | ||
| 2259 | |||
| 2260 | use strict; | ||
| 2261 | use warnings; | ||
| 2262 | # use diagnostics; | ||
| 2263 | |||
| 2264 | use Glib qw(TRUE FALSE); | ||
| 2265 | |||
| 2266 | @Language::Axbasic::Function::Intrinsic::Numeric::pi::ISA = qw( | ||
| 2267 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2268 | ); | ||
| 2269 | |||
| 2270 | # Pi () | ||
| 2271 | |||
| 2272 | ################## | ||
| 2273 | # Methods | ||
| 2274 | |||
| 2275 | sub evaluate { | ||
| 2276 | |||
| 2277 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 2278 | # | ||
| 2279 | # Expected arguments | ||
| 2280 | # $arg - The first (and only) argument in the argument list | ||
| 2281 | # | ||
| 2282 | # Return values | ||
| 2283 | # The return value of the function | ||
| 2284 | |||
| 2285 | my ($self, $arg) = @_; | ||
| 2286 | |||
| 2287 | # (No improper arguments to check) | ||
| 2288 | |||
| 2289 | # Evaluate the function and return the value | ||
| 2290 | return Math::Trig::pi(); | ||
| 2291 | } | ||
| 2292 | } | ||
| 2293 | |||
| 2294 | { package Language::Axbasic::Function::Intrinsic::Numeric::pos; | ||
| 2295 | |||
| 2296 | use strict; | ||
| 2297 | use warnings; | ||
| 2298 | # use diagnostics; | ||
| 2299 | |||
| 2300 | use Glib qw(TRUE FALSE); | ||
| 2301 | |||
| 2302 | @Language::Axbasic::Function::Intrinsic::Numeric::pos::ISA = qw( | ||
| 2303 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2304 | ); | ||
| 2305 | |||
| 2306 | # Pos (string, substring) | ||
| 2307 | # Pos (string, substring, n) | ||
| 2308 | |||
| 2309 | ################## | ||
| 2310 | # Methods | ||
| 2311 | |||
| 2312 | sub evaluate { | ||
| 2313 | |||
| 2314 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N') | ||
| 2315 | # | ||
| 2316 | # Expected arguments | ||
| 2317 | # $string, $subString, $posn | ||
| 2318 | # - The list of arguments supplied to the function | ||
| 2319 | # | ||
| 2320 | # Return values | ||
| 2321 | # The return value of the function | ||
| 2322 | |||
| 2323 | my ($self, $string, $subString, $posn) = @_; | ||
| 2324 | |||
| 2325 | # Local variables | ||
| 2326 | my $result; | ||
| 2327 | |||
| 2328 | # (No improper arguments to check) | ||
| 2329 | |||
| 2330 | # Evaluate the function and return the value | ||
| 2331 | if (defined $posn) { | ||
| 2332 | |||
| 2333 | # $posn must not be zero or a negative number | ||
| 2334 | if ($posn < 1) { | ||
| 2335 | |||
| 2336 | return $self->scriptObj->setError( | ||
| 2337 | 'number_NUM_out_of_range', | ||
| 2338 | $self->_objClass . '->evaluate', | ||
| 2339 | 'NUM', $posn, | ||
| 2340 | ); | ||
| 2341 | } | ||
| 2342 | |||
| 2343 | # $posn must be rounded | ||
| 2344 | $posn = substr( | ||
| 2345 | $posn + 0.5, | ||
| 2346 | 0, | ||
| 2347 | length(int($posn + 0.5)), | ||
| 2348 | ); | ||
| 2349 | |||
| 2350 | # Finally, Perl's index() function uses the number 0 for the first character in the | ||
| 2351 | # string, but True BASIC uses the number 1 | ||
| 2352 | $posn--; | ||
| 2353 | } | ||
| 2354 | |||
| 2355 | # If $string is null but $substring is not, True BASIC returns 0 | ||
| 2356 | if (! $string && $subString) { | ||
| 2357 | |||
| 2358 | return 0; | ||
| 2359 | |||
| 2360 | } elsif (! $subString) { | ||
| 2361 | |||
| 2362 | if (defined $posn) { | ||
| 2363 | |||
| 2364 | # If $subString is null, True BASIC returns the starting position | ||
| 2365 | return ($posn + 1); | ||
| 2366 | |||
| 2367 | } else { | ||
| 2368 | |||
| 2369 | # If $subString is null, True BASIC returns 1 | ||
| 2370 | return 1; | ||
| 2371 | } | ||
| 2372 | } | ||
| 2373 | |||
| 2374 | # Evaluate the function and return the value | ||
| 2375 | if (defined $posn) { | ||
| 2376 | $result = index($string, $subString, $posn); | ||
| 2377 | } else { | ||
| 2378 | $result = index($string, $subString); | ||
| 2379 | } | ||
| 2380 | |||
| 2381 | if ($result == -1) { | ||
| 2382 | |||
| 2383 | # $subString not found - True BASIC returns 0 | ||
| 2384 | return 0; | ||
| 2385 | |||
| 2386 | } else { | ||
| 2387 | |||
| 2388 | # Look for 'gust' in 'disgust' - Perl returns 3, but True BASIC returns 4 | ||
| 2389 | return ($result + 1); | ||
| 2390 | } | ||
| 2391 | } | ||
| 2392 | } | ||
| 2393 | |||
| 2394 | { package Language::Axbasic::Function::Intrinsic::Numeric::posr; | ||
| 2395 | |||
| 2396 | use strict; | ||
| 2397 | use warnings; | ||
| 2398 | # use diagnostics; | ||
| 2399 | |||
| 2400 | use Glib qw(TRUE FALSE); | ||
| 2401 | |||
| 2402 | @Language::Axbasic::Function::Intrinsic::Numeric::posr::ISA = qw( | ||
| 2403 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2404 | ); | ||
| 2405 | |||
| 2406 | # Posr (string, substring) | ||
| 2407 | # Posr (string, substring, n) | ||
| 2408 | |||
| 2409 | ################## | ||
| 2410 | # Methods | ||
| 2411 | |||
| 2412 | sub evaluate { | ||
| 2413 | |||
| 2414 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N') | ||
| 2415 | # | ||
| 2416 | # Expected arguments | ||
| 2417 | # $string, $subString, $posn | ||
| 2418 | # - The list of arguments supplied to the function | ||
| 2419 | # | ||
| 2420 | # Return values | ||
| 2421 | # The return value of the function | ||
| 2422 | |||
| 2423 | my ($self, $string, $subString, $posn) = @_; | ||
| 2424 | |||
| 2425 | # Local variables | ||
| 2426 | my $result; | ||
| 2427 | |||
| 2428 | # (No improper arguments to check) | ||
| 2429 | |||
| 2430 | # Evaluate the function and return the value | ||
| 2431 | if (defined $posn) { | ||
| 2432 | |||
| 2433 | # $posn must not be a negative number | ||
| 2434 | if ($posn < 1) { | ||
| 2435 | |||
| 2436 | return $self->scriptObj->setError( | ||
| 2437 | 'number_NUM_out_of_range', | ||
| 2438 | $self->_objClass . '->evaluate', | ||
| 2439 | 'NUM', $posn, | ||
| 2440 | ); | ||
| 2441 | } | ||
| 2442 | |||
| 2443 | # $posn must be rounded | ||
| 2444 | $posn = substr($posn + 0.5, 0, length(int($posn + 0.5))); | ||
| 2445 | |||
| 2446 | # Finally, Perl's index() function uses the number 0 for the first character in the | ||
| 2447 | # string, but True BASIC uses the number 1 | ||
| 2448 | $posn--; | ||
| 2449 | } | ||
| 2450 | |||
| 2451 | # If $string is null but $substring is not, True BASIC returns 0 | ||
| 2452 | if (! $string && $subString) { | ||
| 2453 | |||
| 2454 | return 0; | ||
| 2455 | |||
| 2456 | } elsif (! $subString) { | ||
| 2457 | |||
| 2458 | if (defined $posn) { | ||
| 2459 | |||
| 2460 | # If $subString is null, True BASIC returns the starting position | ||
| 2461 | return ($posn + 1); | ||
| 2462 | |||
| 2463 | } else { | ||
| 2464 | |||
| 2465 | # If $subString is null, True BASIC returns 1 | ||
| 2466 | return 1; | ||
| 2467 | } | ||
| 2468 | } | ||
| 2469 | |||
| 2470 | # Evaluate the function and return the value | ||
| 2471 | if (defined $posn) { | ||
| 2472 | $result = rindex($string, $subString, $posn); | ||
| 2473 | } else { | ||
| 2474 | $result = rindex($string, $subString); | ||
| 2475 | } | ||
| 2476 | |||
| 2477 | if ($result == -1) { | ||
| 2478 | |||
| 2479 | # $subString not found - True BASIC returns 0 | ||
| 2480 | return 0; | ||
| 2481 | |||
| 2482 | } else { | ||
| 2483 | |||
| 2484 | # Look for 'gust' in 'disgust' - Perl returns 3, but True BASIC returns 4 | ||
| 2485 | return ($result + 1); | ||
| 2486 | } | ||
| 2487 | } | ||
| 2488 | } | ||
| 2489 | |||
| 2490 | { package Language::Axbasic::Function::Intrinsic::Numeric::rad; | ||
| 2491 | |||
| 2492 | use strict; | ||
| 2493 | use warnings; | ||
| 2494 | # use diagnostics; | ||
| 2495 | |||
| 2496 | use Glib qw(TRUE FALSE); | ||
| 2497 | |||
| 2498 | @Language::Axbasic::Function::Intrinsic::Numeric::rad::ISA = qw( | ||
| 2499 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2500 | ); | ||
| 2501 | |||
| 2502 | # Rad (x) | ||
| 2503 | |||
| 2504 | ################## | ||
| 2505 | # Methods | ||
| 2506 | |||
| 2507 | sub evaluate { | ||
| 2508 | |||
| 2509 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2510 | # | ||
| 2511 | # Expected arguments | ||
| 2512 | # $arg - The first (and only) argument in the argument list | ||
| 2513 | # | ||
| 2514 | # Return values | ||
| 2515 | # The return value of the function | ||
| 2516 | |||
| 2517 | my ($self, $arg) = @_; | ||
| 2518 | |||
| 2519 | # (No improper arguments to check) | ||
| 2520 | |||
| 2521 | # Evaluate the function and return the value | ||
| 2522 | return Math::Trig::deg2rad($arg); | ||
| 2523 | } | ||
| 2524 | } | ||
| 2525 | |||
| 2526 | { package Language::Axbasic::Function::Intrinsic::Numeric::remainder; | ||
| 2527 | |||
| 2528 | use strict; | ||
| 2529 | use warnings; | ||
| 2530 | # use diagnostics; | ||
| 2531 | |||
| 2532 | use Glib qw(TRUE FALSE); | ||
| 2533 | |||
| 2534 | @Language::Axbasic::Function::Intrinsic::Numeric::remainder::ISA = qw( | ||
| 2535 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2536 | ); | ||
| 2537 | |||
| 2538 | # Remainder (x, y) | ||
| 2539 | |||
| 2540 | ################## | ||
| 2541 | # Methods | ||
| 2542 | |||
| 2543 | sub evaluate { | ||
| 2544 | |||
| 2545 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN') | ||
| 2546 | # | ||
| 2547 | # Expected arguments | ||
| 2548 | # @args - The list of arguments supplied to the function | ||
| 2549 | # | ||
| 2550 | # Return values | ||
| 2551 | # The return value of the function | ||
| 2552 | |||
| 2553 | my ($self, @args) = @_; | ||
| 2554 | |||
| 2555 | # (No improper arguments to check) | ||
| 2556 | |||
| 2557 | # Evaluate the function and return the value | ||
| 2558 | return ($args[0] % $args[1]); | ||
| 2559 | } | ||
| 2560 | } | ||
| 2561 | |||
| 2562 | { package Language::Axbasic::Function::Intrinsic::Numeric::rnd; | ||
| 2563 | |||
| 2564 | use strict; | ||
| 2565 | use warnings; | ||
| 2566 | # use diagnostics; | ||
| 2567 | |||
| 2568 | use Glib qw(TRUE FALSE); | ||
| 2569 | |||
| 2570 | @Language::Axbasic::Function::Intrinsic::Numeric::rnd::ISA = qw( | ||
| 2571 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2572 | ); | ||
| 2573 | |||
| 2574 | # Rnd (n) | ||
| 2575 | |||
| 2576 | ################## | ||
| 2577 | # Methods | ||
| 2578 | |||
| 2579 | sub evaluate { | ||
| 2580 | |||
| 2581 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2582 | # | ||
| 2583 | # Expected arguments | ||
| 2584 | # $arg - The first (and only) argument in the argument list | ||
| 2585 | # | ||
| 2586 | # Return values | ||
| 2587 | # The return value of the function | ||
| 2588 | |||
| 2589 | my ($self, $arg) = @_; | ||
| 2590 | |||
| 2591 | # Local variables | ||
| 2592 | my $value; | ||
| 2593 | |||
| 2594 | # (No improper arguments to check) | ||
| 2595 | |||
| 2596 | # Evaluate the function and return the value | ||
| 2597 | return rand($arg); | ||
| 2598 | } | ||
| 2599 | } | ||
| 2600 | |||
| 2601 | { package Language::Axbasic::Function::Intrinsic::Numeric::round; | ||
| 2602 | |||
| 2603 | use strict; | ||
| 2604 | use warnings; | ||
| 2605 | # use diagnostics; | ||
| 2606 | |||
| 2607 | use Glib qw(TRUE FALSE); | ||
| 2608 | |||
| 2609 | @Language::Axbasic::Function::Intrinsic::Numeric::round::ISA = qw( | ||
| 2610 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2611 | ); | ||
| 2612 | |||
| 2613 | # Round (x) | ||
| 2614 | # Round (x, n) | ||
| 2615 | |||
| 2616 | ################## | ||
| 2617 | # Methods | ||
| 2618 | |||
| 2619 | sub evaluate { | ||
| 2620 | |||
| 2621 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N;N') | ||
| 2622 | # | ||
| 2623 | # Expected arguments | ||
| 2624 | # @args - The list of arguments supplied to the function | ||
| 2625 | # | ||
| 2626 | # Return values | ||
| 2627 | # The return value of the function | ||
| 2628 | |||
| 2629 | my ($self, @args) = @_; | ||
| 2630 | |||
| 2631 | # Local variables | ||
| 2632 | my ($number, $decimals); | ||
| 2633 | |||
| 2634 | # (No improper arguments to check) | ||
| 2635 | |||
| 2636 | # Evaluate the function and return the value | ||
| 2637 | $number = shift @args; | ||
| 2638 | $decimals = shift @args; | ||
| 2639 | if (! defined $decimals) { | ||
| 2640 | |||
| 2641 | $decimals = 0; | ||
| 2642 | } | ||
| 2643 | |||
| 2644 | # return sprintf("%." . $decimals . "f", $number); | ||
| 2645 | return Math::Round::nearest((10 ** ($decimals * -1)), $number); | ||
| 2646 | } | ||
| 2647 | } | ||
| 2648 | |||
| 2649 | { package Language::Axbasic::Function::Intrinsic::Numeric::sec; | ||
| 2650 | |||
| 2651 | use strict; | ||
| 2652 | use warnings; | ||
| 2653 | # use diagnostics; | ||
| 2654 | |||
| 2655 | use Glib qw(TRUE FALSE); | ||
| 2656 | # Include module here, as well as in Axbasic.pm, so that .../t/00-compile.t won't fail | ||
| 2657 | use Math::Trig; | ||
| 2658 | |||
| 2659 | @Language::Axbasic::Function::Intrinsic::Numeric::sec::ISA = qw( | ||
| 2660 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2661 | ); | ||
| 2662 | |||
| 2663 | # Sec (x) | ||
| 2664 | |||
| 2665 | ################## | ||
| 2666 | # Methods | ||
| 2667 | |||
| 2668 | sub evaluate { | ||
| 2669 | |||
| 2670 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2671 | # | ||
| 2672 | # Expected arguments | ||
| 2673 | # $arg - The first (and only) argument in the argument list | ||
| 2674 | # | ||
| 2675 | # Return values | ||
| 2676 | # The return value of the function | ||
| 2677 | |||
| 2678 | my ($self, $arg) = @_; | ||
| 2679 | |||
| 2680 | # Local variables | ||
| 2681 | my $value; | ||
| 2682 | |||
| 2683 | # (No improper arguments to check) | ||
| 2684 | |||
| 2685 | # Evaluate the function and return the value | ||
| 2686 | |||
| 2687 | # $arg must not be (pi/2) + (k * pi), where k is any integer | ||
| 2688 | if ( | ||
| 2689 | ( | ||
| 2690 | (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi) | ||
| 2691 | == int (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi) | ||
| 2692 | ) || ( | ||
| 2693 | # Don't know why we need to use 'eq' instead of '==' in the case of k = 0, but we | ||
| 2694 | # do... | ||
| 2695 | $arg eq (Math::Trig::pi / 2) | ||
| 2696 | ) | ||
| 2697 | ) { | ||
| 2698 | return $self->scriptObj->setError( | ||
| 2699 | 'number_NUM_out_of_range', | ||
| 2700 | $self->_objClass . '->evaluate', | ||
| 2701 | 'NUM', $arg, | ||
| 2702 | ); | ||
| 2703 | } | ||
| 2704 | |||
| 2705 | # Use radians (default) or degrees? | ||
| 2706 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 2707 | |||
| 2708 | # Convert to radians | ||
| 2709 | $arg = Math::Trig::deg2rad($arg); | ||
| 2710 | } | ||
| 2711 | |||
| 2712 | # Evaluate the function and return the value | ||
| 2713 | return Math::Trig::sec($arg); | ||
| 2714 | } | ||
| 2715 | } | ||
| 2716 | |||
| 2717 | { package Language::Axbasic::Function::Intrinsic::Numeric::sgn; | ||
| 2718 | |||
| 2719 | use strict; | ||
| 2720 | use warnings; | ||
| 2721 | # use diagnostics; | ||
| 2722 | |||
| 2723 | use Glib qw(TRUE FALSE); | ||
| 2724 | |||
| 2725 | @Language::Axbasic::Function::Intrinsic::Numeric::sgn::ISA = qw( | ||
| 2726 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2727 | ); | ||
| 2728 | |||
| 2729 | # Sgn (x) | ||
| 2730 | |||
| 2731 | ################## | ||
| 2732 | # Methods | ||
| 2733 | |||
| 2734 | sub evaluate { | ||
| 2735 | |||
| 2736 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2737 | # | ||
| 2738 | # Expected arguments | ||
| 2739 | # $arg - The first (and only) argument in the argument list | ||
| 2740 | # | ||
| 2741 | # Return values | ||
| 2742 | # The return value of the function | ||
| 2743 | |||
| 2744 | my ($self, $arg) = @_; | ||
| 2745 | |||
| 2746 | # (No improper arguments to check) | ||
| 2747 | |||
| 2748 | # Evaluate the function and return the value | ||
| 2749 | if ($arg > 0) { | ||
| 2750 | return 1; | ||
| 2751 | } elsif ($arg < 0) { | ||
| 2752 | return -1; | ||
| 2753 | } else { | ||
| 2754 | return 0; | ||
| 2755 | } | ||
| 2756 | } | ||
| 2757 | } | ||
| 2758 | |||
| 2759 | { package Language::Axbasic::Function::Intrinsic::Numeric::sin; | ||
| 2760 | |||
| 2761 | use strict; | ||
| 2762 | use warnings; | ||
| 2763 | # use diagnostics; | ||
| 2764 | |||
| 2765 | use Glib qw(TRUE FALSE); | ||
| 2766 | |||
| 2767 | @Language::Axbasic::Function::Intrinsic::Numeric::sin::ISA = qw( | ||
| 2768 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2769 | ); | ||
| 2770 | |||
| 2771 | # Sin (x) | ||
| 2772 | |||
| 2773 | ################## | ||
| 2774 | # Methods | ||
| 2775 | |||
| 2776 | sub evaluate { | ||
| 2777 | |||
| 2778 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2779 | # | ||
| 2780 | # Expected arguments | ||
| 2781 | # $arg - The first (and only) argument in the argument list | ||
| 2782 | # | ||
| 2783 | # Return values | ||
| 2784 | # The return value of the function | ||
| 2785 | |||
| 2786 | my ($self, $arg) = @_; | ||
| 2787 | |||
| 2788 | # (No improper arguments to check) | ||
| 2789 | |||
| 2790 | # Evaluate the function and return the value | ||
| 2791 | |||
| 2792 | # Use radians (default) or degrees? | ||
| 2793 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 2794 | |||
| 2795 | # Convert to radians | ||
| 2796 | $arg = Math::Trig::deg2rad($arg); | ||
| 2797 | } | ||
| 2798 | |||
| 2799 | # Evaluate the function and return the value | ||
| 2800 | return sin($arg); | ||
| 2801 | } | ||
| 2802 | } | ||
| 2803 | |||
| 2804 | { package Language::Axbasic::Function::Intrinsic::Numeric::sinh; | ||
| 2805 | |||
| 2806 | use strict; | ||
| 2807 | use warnings; | ||
| 2808 | # use diagnostics; | ||
| 2809 | |||
| 2810 | use Glib qw(TRUE FALSE); | ||
| 2811 | |||
| 2812 | @Language::Axbasic::Function::Intrinsic::Numeric::sinh::ISA = qw( | ||
| 2813 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2814 | ); | ||
| 2815 | |||
| 2816 | # Sinh (x) | ||
| 2817 | |||
| 2818 | ################## | ||
| 2819 | # Methods | ||
| 2820 | |||
| 2821 | sub evaluate { | ||
| 2822 | |||
| 2823 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2824 | # | ||
| 2825 | # Expected arguments | ||
| 2826 | # $arg - The first (and only) argument in the argument list | ||
| 2827 | # | ||
| 2828 | # Return values | ||
| 2829 | # The return value of the function | ||
| 2830 | |||
| 2831 | my ($self, $arg) = @_; | ||
| 2832 | |||
| 2833 | # (No improper arguments to check) | ||
| 2834 | |||
| 2835 | # Evaluate the function and return the value | ||
| 2836 | return &sinh($arg); | ||
| 2837 | } | ||
| 2838 | } | ||
| 2839 | |||
| 2840 | { package Language::Axbasic::Function::Intrinsic::Numeric::sqr; | ||
| 2841 | |||
| 2842 | use strict; | ||
| 2843 | use warnings; | ||
| 2844 | # use diagnostics; | ||
| 2845 | |||
| 2846 | use Glib qw(TRUE FALSE); | ||
| 2847 | |||
| 2848 | @Language::Axbasic::Function::Intrinsic::Numeric::sqr::ISA = qw( | ||
| 2849 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2850 | ); | ||
| 2851 | |||
| 2852 | # Sqr (x) | ||
| 2853 | |||
| 2854 | ################## | ||
| 2855 | # Methods | ||
| 2856 | |||
| 2857 | sub evaluate { | ||
| 2858 | |||
| 2859 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2860 | # | ||
| 2861 | # Expected arguments | ||
| 2862 | # $arg - The first (and only) argument in the argument list | ||
| 2863 | # | ||
| 2864 | # Return values | ||
| 2865 | # The return value of the function | ||
| 2866 | |||
| 2867 | my ($self, $arg) = @_; | ||
| 2868 | |||
| 2869 | # (No improper arguments to check) | ||
| 2870 | |||
| 2871 | # Evaluate the function and return the value | ||
| 2872 | |||
| 2873 | # Don't try to get the square root of a negative number | ||
| 2874 | if ($arg < 0) { | ||
| 2875 | |||
| 2876 | return $self->scriptObj->setError( | ||
| 2877 | 'number_NUM_out_of_range', | ||
| 2878 | $self->_objClass . '->evaluate', | ||
| 2879 | 'NUM', $arg, | ||
| 2880 | ); | ||
| 2881 | } | ||
| 2882 | |||
| 2883 | # Evaluate the function and return the value | ||
| 2884 | return sqrt($arg); | ||
| 2885 | } | ||
| 2886 | } | ||
| 2887 | |||
| 2888 | { package Language::Axbasic::Function::Intrinsic::Numeric::tan; | ||
| 2889 | |||
| 2890 | use strict; | ||
| 2891 | use warnings; | ||
| 2892 | # use diagnostics; | ||
| 2893 | |||
| 2894 | use Glib qw(TRUE FALSE); | ||
| 2895 | |||
| 2896 | @Language::Axbasic::Function::Intrinsic::Numeric::tan::ISA = qw( | ||
| 2897 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2898 | ); | ||
| 2899 | |||
| 2900 | # Tan (x) | ||
| 2901 | |||
| 2902 | ################## | ||
| 2903 | # Methods | ||
| 2904 | |||
| 2905 | sub evaluate { | ||
| 2906 | |||
| 2907 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2908 | # | ||
| 2909 | # Expected arguments | ||
| 2910 | # $arg - The first (and only) argument in the argument list | ||
| 2911 | # | ||
| 2912 | # Return values | ||
| 2913 | # The return value of the function | ||
| 2914 | |||
| 2915 | my ($self, $arg) = @_; | ||
| 2916 | |||
| 2917 | # (No improper arguments to check) | ||
| 2918 | |||
| 2919 | # Evaluate the function and return the value | ||
| 2920 | |||
| 2921 | # $arg must not be (pi/2) + (k * pi), where k is any integer | ||
| 2922 | if ( | ||
| 2923 | ( | ||
| 2924 | (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi) | ||
| 2925 | == int (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi) | ||
| 2926 | ) || ( | ||
| 2927 | # Don't know why we need to use 'eq' instead of '==' in the case of k = 0, but we | ||
| 2928 | # do... | ||
| 2929 | $arg eq (Math::Trig::pi / 2) | ||
| 2930 | ) | ||
| 2931 | ) { | ||
| 2932 | return $self->scriptObj->setError( | ||
| 2933 | 'number_NUM_out_of_range', | ||
| 2934 | $self->_objClass . '->evaluate', | ||
| 2935 | 'NUM', $arg, | ||
| 2936 | ); | ||
| 2937 | } | ||
| 2938 | |||
| 2939 | # Use radians (default) or degrees? | ||
| 2940 | if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') { | ||
| 2941 | |||
| 2942 | # Convert to radians | ||
| 2943 | $arg = Math::Trig::deg2rad($arg); | ||
| 2944 | } | ||
| 2945 | |||
| 2946 | # Evaluate the function and return the value | ||
| 2947 | return Math::Trig::tan($arg); | ||
| 2948 | } | ||
| 2949 | } | ||
| 2950 | |||
| 2951 | { package Language::Axbasic::Function::Intrinsic::Numeric::tanh; | ||
| 2952 | |||
| 2953 | use strict; | ||
| 2954 | use warnings; | ||
| 2955 | # use diagnostics; | ||
| 2956 | |||
| 2957 | use Glib qw(TRUE FALSE); | ||
| 2958 | |||
| 2959 | @Language::Axbasic::Function::Intrinsic::Numeric::tanh::ISA = qw( | ||
| 2960 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 2961 | ); | ||
| 2962 | |||
| 2963 | # Tanh (x) | ||
| 2964 | |||
| 2965 | ################## | ||
| 2966 | # Methods | ||
| 2967 | |||
| 2968 | sub evaluate { | ||
| 2969 | |||
| 2970 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 2971 | # | ||
| 2972 | # Expected arguments | ||
| 2973 | # $arg - The first (and only) argument in the argument lisT | ||
| 2974 | # | ||
| 2975 | # Return values | ||
| 2976 | # The return value of the function | ||
| 2977 | |||
| 2978 | my ($self, $arg) = @_; | ||
| 2979 | |||
| 2980 | # Local variables | ||
| 2981 | my $value; | ||
| 2982 | |||
| 2983 | # (No improper arguments to check) | ||
| 2984 | |||
| 2985 | # Evaluate the function and return the value | ||
| 2986 | |||
| 2987 | # $arg must not be (pi/2) + (k * pi), where k is any integer | ||
| 2988 | if ( | ||
| 2989 | ( | ||
| 2990 | (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi) | ||
| 2991 | == int (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi) | ||
| 2992 | ) || ( | ||
| 2993 | # Don't know why we need to use 'eq' instead of '==' in the case of k = 0, but we | ||
| 2994 | # do... | ||
| 2995 | $arg eq (Math::Trig::pi / 2) | ||
| 2996 | ) | ||
| 2997 | ) { | ||
| 2998 | return $self->scriptObj->setError( | ||
| 2999 | 'number_NUM_out_of_range', | ||
| 3000 | $self->_objClass . '->evaluate', | ||
| 3001 | 'NUM', $arg, | ||
| 3002 | ); | ||
| 3003 | } | ||
| 3004 | |||
| 3005 | # Evaluate the function and return the value | ||
| 3006 | return Math::Trig::tanh($arg); | ||
| 3007 | } | ||
| 3008 | } | ||
| 3009 | |||
| 3010 | { package Language::Axbasic::Function::Intrinsic::Numeric::testpat; | ||
| 3011 | |||
| 3012 | use strict; | ||
| 3013 | use warnings; | ||
| 3014 | # use diagnostics; | ||
| 3015 | |||
| 3016 | use Glib qw(TRUE FALSE); | ||
| 3017 | |||
| 3018 | @Language::Axbasic::Function::Intrinsic::Numeric::testpat::ISA = qw( | ||
| 3019 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 3020 | ); | ||
| 3021 | |||
| 3022 | # Testpat (regex) | ||
| 3023 | |||
| 3024 | ################## | ||
| 3025 | # Methods | ||
| 3026 | |||
| 3027 | sub evaluate { | ||
| 3028 | |||
| 3029 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 3030 | # | ||
| 3031 | # Expected arguments | ||
| 3032 | # $arg - The first (and only) argument in the argument lisT | ||
| 3033 | # | ||
| 3034 | # Return values | ||
| 3035 | # The return value of the function | ||
| 3036 | |||
| 3037 | my ($self, $arg) = @_; | ||
| 3038 | |||
| 3039 | # Local variables | ||
| 3040 | my $value; | ||
| 3041 | |||
| 3042 | # (No improper arguments to check) | ||
| 3043 | |||
| 3044 | # Evaluate the function and return the value | ||
| 3045 | |||
| 3046 | if ($arg eq '' || $axmud::CLIENT->regexCheck($arg)) { | ||
| 3047 | return 0; | ||
| 3048 | } else { | ||
| 3049 | return 1; | ||
| 3050 | } | ||
| 3051 | } | ||
| 3052 | } | ||
| 3053 | |||
| 3054 | { package Language::Axbasic::Function::Intrinsic::Numeric::time; | ||
| 3055 | |||
| 3056 | use strict; | ||
| 3057 | use warnings; | ||
| 3058 | # use diagnostics; | ||
| 3059 | |||
| 3060 | use Glib qw(TRUE FALSE); | ||
| 3061 | |||
| 3062 | @Language::Axbasic::Function::Intrinsic::Numeric::time::ISA = qw( | ||
| 3063 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 3064 | ); | ||
| 3065 | |||
| 3066 | # Time | ||
| 3067 | |||
| 3068 | ################## | ||
| 3069 | # Methods | ||
| 3070 | |||
| 3071 | sub evaluate { | ||
| 3072 | |||
| 3073 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 3074 | # | ||
| 3075 | # Expected arguments | ||
| 3076 | # $arg - The first (and only) argument in the argument list | ||
| 3077 | # | ||
| 3078 | # Return values | ||
| 3079 | # The return value of the function | ||
| 3080 | |||
| 3081 | my ($self, $arg) = @_; | ||
| 3082 | |||
| 3083 | # (No improper arguments to check) | ||
| 3084 | |||
| 3085 | # Evaluate the function and return the value | ||
| 3086 | |||
| 3087 | # Get the time | ||
| 3088 | my ($second, $minute, $hour) = localtime(); | ||
| 3089 | |||
| 3090 | # Return the number of seconds since midnight | ||
| 3091 | return ( ($hour * 3600) + ($minute * 60) + $second); | ||
| 3092 | } | ||
| 3093 | } | ||
| 3094 | |||
| 3095 | { package Language::Axbasic::Function::Intrinsic::Numeric::trunc; | ||
| 3096 | |||
| 3097 | use strict; | ||
| 3098 | use warnings; | ||
| 3099 | # use diagnostics; | ||
| 3100 | |||
| 3101 | use Glib qw(TRUE FALSE); | ||
| 3102 | |||
| 3103 | @Language::Axbasic::Function::Intrinsic::Numeric::trunc::ISA = qw( | ||
| 3104 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 3105 | ); | ||
| 3106 | |||
| 3107 | # Trunc (x) | ||
| 3108 | # Trunc (x, n) | ||
| 3109 | |||
| 3110 | ################## | ||
| 3111 | # Methods | ||
| 3112 | |||
| 3113 | sub evaluate { | ||
| 3114 | |||
| 3115 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N;N') | ||
| 3116 | # | ||
| 3117 | # Expected arguments | ||
| 3118 | # @args - The list of arguments supplied to the function | ||
| 3119 | # | ||
| 3120 | # Return values | ||
| 3121 | # The return value of the function | ||
| 3122 | |||
| 3123 | my ($self, @args) = @_; | ||
| 3124 | |||
| 3125 | # Local variables | ||
| 3126 | my ($number, $decimals, $value); | ||
| 3127 | |||
| 3128 | # (No improper arguments to check) | ||
| 3129 | |||
| 3130 | # Evaluate the function and return the value | ||
| 3131 | $number = shift @args; | ||
| 3132 | $decimals = shift @args; | ||
| 3133 | if (! defined $decimals) { | ||
| 3134 | |||
| 3135 | $decimals = 0; | ||
| 3136 | } | ||
| 3137 | |||
| 3138 | if ($decimals < 0) { | ||
| 3139 | |||
| 3140 | return undef; | ||
| 3141 | |||
| 3142 | } elsif ($decimals == 0) { | ||
| 3143 | |||
| 3144 | $value = substr( | ||
| 3145 | $number + ( '0.' . '0' x $decimals ), | ||
| 3146 | 0, | ||
| 3147 | $decimals + length(int($number)) | ||
| 3148 | ); | ||
| 3149 | |||
| 3150 | } else { | ||
| 3151 | |||
| 3152 | $value = substr( | ||
| 3153 | $number + ( '0.' . '0' x $decimals ), | ||
| 3154 | 0, | ||
| 3155 | $decimals + length(int($number)) + 1 | ||
| 3156 | ); | ||
| 3157 | } | ||
| 3158 | |||
| 3159 | return $value; | ||
| 3160 | } | ||
| 3161 | } | ||
| 3162 | |||
| 3163 | { package Language::Axbasic::Function::Intrinsic::Numeric::val; | ||
| 3164 | |||
| 3165 | use strict; | ||
| 3166 | use warnings; | ||
| 3167 | # use diagnostics; | ||
| 3168 | |||
| 3169 | use Glib qw(TRUE FALSE); | ||
| 3170 | |||
| 3171 | @Language::Axbasic::Function::Intrinsic::Numeric::val::ISA = qw( | ||
| 3172 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 3173 | ); | ||
| 3174 | |||
| 3175 | # Val (string) | ||
| 3176 | |||
| 3177 | ################## | ||
| 3178 | # Methods | ||
| 3179 | |||
| 3180 | sub evaluate { | ||
| 3181 | |||
| 3182 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 3183 | # | ||
| 3184 | # Expected arguments | ||
| 3185 | # $arg - The first (and only) argument in the argument list | ||
| 3186 | # | ||
| 3187 | # Return values | ||
| 3188 | # The return value of the function | ||
| 3189 | |||
| 3190 | my ($self, $arg) = @_; | ||
| 3191 | |||
| 3192 | # (No improper arguments to check) | ||
| 3193 | |||
| 3194 | # Evaluate the function and return the value | ||
| 3195 | if (! $axmud::CLIENT->floatCheck($arg)) { | ||
| 3196 | return 0; | ||
| 3197 | } else { | ||
| 3198 | return ($arg + 0); | ||
| 3199 | } | ||
| 3200 | } | ||
| 3201 | } | ||
| 3202 | |||
| 3203 | { package Language::Axbasic::Function::Intrinsic::Numeric::version; | ||
| 3204 | |||
| 3205 | use strict; | ||
| 3206 | use warnings; | ||
| 3207 | # use diagnostics; | ||
| 3208 | |||
| 3209 | use Glib qw(TRUE FALSE); | ||
| 3210 | |||
| 3211 | @Language::Axbasic::Function::Intrinsic::Numeric::version::ISA = qw( | ||
| 3212 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 3213 | ); | ||
| 3214 | |||
| 3215 | # Version | ||
| 3216 | |||
| 3217 | ################## | ||
| 3218 | # Methods | ||
| 3219 | |||
| 3220 | sub evaluate { | ||
| 3221 | |||
| 3222 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 3223 | # | ||
| 3224 | # Expected arguments | ||
| 3225 | # $arg - The first (and only) argument in the argument list | ||
| 3226 | # | ||
| 3227 | # Return values | ||
| 3228 | # The return value of the function | ||
| 3229 | |||
| 3230 | my ($self, $arg) = @_; | ||
| 3231 | |||
| 3232 | # (No improper arguments to check) | ||
| 3233 | |||
| 3234 | # Evaluate the function and return the value | ||
| 3235 | return $axmud::BASIC_VERSION; | ||
| 3236 | } | ||
| 3237 | } | ||
| 3238 | |||
| 3239 | ### Pure BASIC functions (string) ### | ||
| 3240 | |||
| 3241 | { package Language::Axbasic::Function::Intrinsic::String::chr; | ||
| 3242 | |||
| 3243 | use strict; | ||
| 3244 | use warnings; | ||
| 3245 | # use diagnostics; | ||
| 3246 | |||
| 3247 | use Glib qw(TRUE FALSE); | ||
| 3248 | |||
| 3249 | @Language::Axbasic::Function::Intrinsic::String::chr::ISA = qw( | ||
| 3250 | Language::Axbasic::Function::Intrinsic::String | ||
| 3251 | ); | ||
| 3252 | |||
| 3253 | # Chr$ (number) | ||
| 3254 | |||
| 3255 | ################## | ||
| 3256 | # Methods | ||
| 3257 | |||
| 3258 | sub evaluate { | ||
| 3259 | |||
| 3260 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 3261 | # | ||
| 3262 | # Expected arguments | ||
| 3263 | # $arg - The first (and only) argument in the argument list | ||
| 3264 | # | ||
| 3265 | # Return values | ||
| 3266 | # The return value of the function | ||
| 3267 | |||
| 3268 | my ($self, $arg) = @_; | ||
| 3269 | |||
| 3270 | # (No improper arguments to check) | ||
| 3271 | |||
| 3272 | # Evaluate the function and return the value | ||
| 3273 | if ($arg < 0 || $arg > 127) { | ||
| 3274 | |||
| 3275 | return $self->scriptObj->setError( | ||
| 3276 | 'number_NUM_out_of_range\'NUM\'', | ||
| 3277 | $self->_objClass . '->evaluate', | ||
| 3278 | 'NUM', $arg, | ||
| 3279 | ); | ||
| 3280 | |||
| 3281 | } else { | ||
| 3282 | |||
| 3283 | return (chr($arg)); | ||
| 3284 | } | ||
| 3285 | } | ||
| 3286 | } | ||
| 3287 | |||
| 3288 | { package Language::Axbasic::Function::Intrinsic::String::date; | ||
| 3289 | |||
| 3290 | use strict; | ||
| 3291 | use warnings; | ||
| 3292 | # use diagnostics; | ||
| 3293 | |||
| 3294 | use Glib qw(TRUE FALSE); | ||
| 3295 | |||
| 3296 | @Language::Axbasic::Function::Intrinsic::String::date::ISA = qw( | ||
| 3297 | Language::Axbasic::Function::Intrinsic::String | ||
| 3298 | ); | ||
| 3299 | |||
| 3300 | # Date$ () | ||
| 3301 | |||
| 3302 | ################## | ||
| 3303 | # Methods | ||
| 3304 | |||
| 3305 | sub evaluate { | ||
| 3306 | |||
| 3307 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 3308 | # | ||
| 3309 | # Expected arguments | ||
| 3310 | # $arg - The first (and only) argument in the argument list | ||
| 3311 | # | ||
| 3312 | # Return values | ||
| 3313 | # The return value of the function | ||
| 3314 | |||
| 3315 | my ($self, $arg) = @_; | ||
| 3316 | |||
| 3317 | # (No improper arguments to check) | ||
| 3318 | |||
| 3319 | # Evaluate the function and return the value | ||
| 3320 | |||
| 3321 | # Get the time and date | ||
| 3322 | my ( | ||
| 3323 | $second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, | ||
| 3324 | $daylightSavings | ||
| 3325 | ) = localtime(); | ||
| 3326 | |||
| 3327 | my $year = 1900 + $yearOffset; | ||
| 3328 | |||
| 3329 | # Return the date in the form "YYYYMMDD". | ||
| 3330 | return ($year . sprintf("%02d", ($month + 1)) . sprintf("%02d", $dayOfMonth)); | ||
| 3331 | } | ||
| 3332 | } | ||
| 3333 | |||
| 3334 | { package Language::Axbasic::Function::Intrinsic::String::ip; | ||
| 3335 | |||
| 3336 | use strict; | ||
| 3337 | use warnings; | ||
| 3338 | # use diagnostics; | ||
| 3339 | |||
| 3340 | use Glib qw(TRUE FALSE); | ||
| 3341 | |||
| 3342 | @Language::Axbasic::Function::Intrinsic::String::ip::ISA = qw( | ||
| 3343 | Language::Axbasic::Function::Intrinsic::String | ||
| 3344 | ); | ||
| 3345 | |||
| 3346 | # Ip$ () | ||
| 3347 | |||
| 3348 | ################## | ||
| 3349 | # Methods | ||
| 3350 | |||
| 3351 | sub evaluate { | ||
| 3352 | |||
| 3353 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 3354 | # | ||
| 3355 | # Expected arguments | ||
| 3356 | # $arg - The first (and only) argument in the argument list | ||
| 3357 | # | ||
| 3358 | # Return values | ||
| 3359 | # The return value of the function | ||
| 3360 | |||
| 3361 | my ($self, $arg) = @_; | ||
| 3362 | |||
| 3363 | # (No improper arguments to check) | ||
| 3364 | |||
| 3365 | # Evaluate the function and return the value | ||
| 3366 | |||
| 3367 | # Get the user's IP | ||
| 3368 | my $ip = $axmud::CLIENT->ipv4Get(); | ||
| 3369 | if (! defined $ip) { | ||
| 3370 | |||
| 3371 | # Failsafe value | ||
| 3372 | $ip = '127.0.0.1'; | ||
| 3373 | } | ||
| 3374 | |||
| 3375 | return $ip; | ||
| 3376 | } | ||
| 3377 | } | ||
| 3378 | |||
| 3379 | { package Language::Axbasic::Function::Intrinsic::String::lcase; | ||
| 3380 | |||
| 3381 | use strict; | ||
| 3382 | use warnings; | ||
| 3383 | # use diagnostics; | ||
| 3384 | |||
| 3385 | use Glib qw(TRUE FALSE); | ||
| 3386 | |||
| 3387 | @Language::Axbasic::Function::Intrinsic::String::lcase::ISA = qw( | ||
| 3388 | Language::Axbasic::Function::Intrinsic::String | ||
| 3389 | ); | ||
| 3390 | |||
| 3391 | # Lcase$ (string) | ||
| 3392 | |||
| 3393 | ################## | ||
| 3394 | # Methods | ||
| 3395 | |||
| 3396 | sub evaluate { | ||
| 3397 | |||
| 3398 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 3399 | # | ||
| 3400 | # Expected arguments | ||
| 3401 | # $arg - The first (and only) argument in the argument list | ||
| 3402 | # | ||
| 3403 | # Return values | ||
| 3404 | # The return value of the function | ||
| 3405 | |||
| 3406 | my ($self, $arg) = @_; | ||
| 3407 | |||
| 3408 | # (No improper arguments to check) | ||
| 3409 | |||
| 3410 | # Evaluate the function and return the value | ||
| 3411 | return lc($arg); | ||
| 3412 | } | ||
| 3413 | } | ||
| 3414 | |||
| 3415 | { package Language::Axbasic::Function::Intrinsic::String::left; | ||
| 3416 | |||
| 3417 | use strict; | ||
| 3418 | use warnings; | ||
| 3419 | # use diagnostics; | ||
| 3420 | |||
| 3421 | use Glib qw(TRUE FALSE); | ||
| 3422 | |||
| 3423 | @Language::Axbasic::Function::Intrinsic::String::left::ISA = qw( | ||
| 3424 | Language::Axbasic::Function::Intrinsic::String | ||
| 3425 | ); | ||
| 3426 | |||
| 3427 | # Left$ (string, length) | ||
| 3428 | |||
| 3429 | ################## | ||
| 3430 | # Methods | ||
| 3431 | |||
| 3432 | sub evaluate { | ||
| 3433 | |||
| 3434 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN') | ||
| 3435 | # | ||
| 3436 | # Expected arguments | ||
| 3437 | # @args - The list of arguments supplied to the function | ||
| 3438 | # | ||
| 3439 | # Return values | ||
| 3440 | # The return value of the function | ||
| 3441 | |||
| 3442 | my ($self, @args) = @_; | ||
| 3443 | |||
| 3444 | # Local variables | ||
| 3445 | my ($string, $length); | ||
| 3446 | |||
| 3447 | # (No improper arguments to check) | ||
| 3448 | |||
| 3449 | # Evaluate the function and return the value | ||
| 3450 | ($string, $length) = @args; | ||
| 3451 | |||
| 3452 | # The value of $length can be 0 (which returns an empty string), but cannot be negative | ||
| 3453 | if ($length < 0) { | ||
| 3454 | |||
| 3455 | return $self->scriptObj->setError( | ||
| 3456 | 'number_NUM_out_of_range', | ||
| 3457 | $self->_objClass . '->evaluate', | ||
| 3458 | 'NUM', $length, | ||
| 3459 | ); | ||
| 3460 | } | ||
| 3461 | |||
| 3462 | return substr($string, 0, $length); | ||
| 3463 | } | ||
| 3464 | } | ||
| 3465 | |||
| 3466 | { package Language::Axbasic::Function::Intrinsic::String::ltrim; | ||
| 3467 | |||
| 3468 | use strict; | ||
| 3469 | use warnings; | ||
| 3470 | # use diagnostics; | ||
| 3471 | |||
| 3472 | use Glib qw(TRUE FALSE); | ||
| 3473 | |||
| 3474 | @Language::Axbasic::Function::Intrinsic::String::ltrim::ISA = qw( | ||
| 3475 | Language::Axbasic::Function::Intrinsic::String | ||
| 3476 | ); | ||
| 3477 | |||
| 3478 | # Ltrim$ (string) | ||
| 3479 | |||
| 3480 | ################## | ||
| 3481 | # Methods | ||
| 3482 | |||
| 3483 | sub evaluate { | ||
| 3484 | |||
| 3485 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 3486 | # | ||
| 3487 | # Expected arguments | ||
| 3488 | # $arg - The first (and only) argument in the argument list | ||
| 3489 | # | ||
| 3490 | # Return values | ||
| 3491 | # The return value of the function | ||
| 3492 | |||
| 3493 | my ($self, $arg) = @_; | ||
| 3494 | |||
| 3495 | # (No improper arguments to check) | ||
| 3496 | |||
| 3497 | # Evaluate the function and return the value | ||
| 3498 | $arg =~ s/^\s+//; | ||
| 3499 | |||
| 3500 | return uc($arg); | ||
| 3501 | } | ||
| 3502 | } | ||
| 3503 | |||
| 3504 | { package Language::Axbasic::Function::Intrinsic::String::mid; | ||
| 3505 | |||
| 3506 | use strict; | ||
| 3507 | use warnings; | ||
| 3508 | # use diagnostics; | ||
| 3509 | |||
| 3510 | use Glib qw(TRUE FALSE); | ||
| 3511 | |||
| 3512 | @Language::Axbasic::Function::Intrinsic::String::mid::ISA = qw( | ||
| 3513 | Language::Axbasic::Function::Intrinsic::String | ||
| 3514 | ); | ||
| 3515 | |||
| 3516 | # Mid$ (string, offset) | ||
| 3517 | # Mid$ (string, offset, length) | ||
| 3518 | |||
| 3519 | ################## | ||
| 3520 | # Methods | ||
| 3521 | |||
| 3522 | sub evaluate { | ||
| 3523 | |||
| 3524 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN;N') | ||
| 3525 | # | ||
| 3526 | # Expected arguments | ||
| 3527 | # @args - The list of arguments supplied to the function | ||
| 3528 | # | ||
| 3529 | # Return values | ||
| 3530 | # The return value of the function | ||
| 3531 | |||
| 3532 | my ($self, @args) = @_; | ||
| 3533 | |||
| 3534 | # Local variables | ||
| 3535 | my ($string, $index, $length); | ||
| 3536 | |||
| 3537 | # (No improper arguments to check) | ||
| 3538 | |||
| 3539 | # Evaluate the function and return the value | ||
| 3540 | ($string, $index, $length) = @args; | ||
| 3541 | |||
| 3542 | # $index must be 1 or more. $length can be (which returns an empty string), but cannot be | ||
| 3543 | # negative | ||
| 3544 | if ($index < 1) { | ||
| 3545 | |||
| 3546 | return $self->scriptObj->setError( | ||
| 3547 | 'number_NUM_out_of_range', | ||
| 3548 | $self->_objClass . '->evaluate', | ||
| 3549 | 'NUM', $index, | ||
| 3550 | ); | ||
| 3551 | |||
| 3552 | } elsif ($length < 0) { | ||
| 3553 | |||
| 3554 | return $self->scriptObj->setError( | ||
| 3555 | 'number_NUM_out_of_range', | ||
| 3556 | $self->_objClass . '->evaluate', | ||
| 3557 | 'NUM', $length, | ||
| 3558 | ); | ||
| 3559 | } | ||
| 3560 | |||
| 3561 | # Axbasic strings index from 1 | ||
| 3562 | $index--; | ||
| 3563 | |||
| 3564 | if (defined $length) { | ||
| 3565 | return substr($string, $index, $length); | ||
| 3566 | } else { | ||
| 3567 | return substr($string, $index); | ||
| 3568 | } | ||
| 3569 | } | ||
| 3570 | } | ||
| 3571 | |||
| 3572 | { package Language::Axbasic::Function::Intrinsic::String::repeat; | ||
| 3573 | |||
| 3574 | use strict; | ||
| 3575 | use warnings; | ||
| 3576 | # use diagnostics; | ||
| 3577 | |||
| 3578 | use Glib qw(TRUE FALSE); | ||
| 3579 | |||
| 3580 | @Language::Axbasic::Function::Intrinsic::String::repeat::ISA = qw( | ||
| 3581 | Language::Axbasic::Function::Intrinsic::String | ||
| 3582 | ); | ||
| 3583 | |||
| 3584 | # Repeat$ (string, n) | ||
| 3585 | |||
| 3586 | ################## | ||
| 3587 | # Methods | ||
| 3588 | |||
| 3589 | sub evaluate { | ||
| 3590 | |||
| 3591 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN') | ||
| 3592 | # | ||
| 3593 | # Expected arguments | ||
| 3594 | # $string, $number | ||
| 3595 | # - The list of arguments supplied to the function | ||
| 3596 | # | ||
| 3597 | # Return values | ||
| 3598 | # The return value of the function | ||
| 3599 | |||
| 3600 | my ($self, $string, $number) = @_; | ||
| 3601 | |||
| 3602 | # (No improper arguments to check) | ||
| 3603 | |||
| 3604 | # Evaluate the function and return the value | ||
| 3605 | |||
| 3606 | # $number must not be a negative number | ||
| 3607 | if ($number < 0) { | ||
| 3608 | |||
| 3609 | return $self->scriptObj->setError( | ||
| 3610 | 'number_NUM_out_of_range', | ||
| 3611 | $self->_objClass . '->evaluate', | ||
| 3612 | 'NUM', $number, | ||
| 3613 | ); | ||
| 3614 | } | ||
| 3615 | |||
| 3616 | # $number must be rounded | ||
| 3617 | $number = substr( | ||
| 3618 | $number + 0.5, | ||
| 3619 | 0, | ||
| 3620 | length(int($number + 0.5)), | ||
| 3621 | ); | ||
| 3622 | |||
| 3623 | return ($string x $number); | ||
| 3624 | } | ||
| 3625 | } | ||
| 3626 | |||
| 3627 | { package Language::Axbasic::Function::Intrinsic::String::right; | ||
| 3628 | |||
| 3629 | use strict; | ||
| 3630 | use warnings; | ||
| 3631 | # use diagnostics; | ||
| 3632 | |||
| 3633 | use Glib qw(TRUE FALSE); | ||
| 3634 | |||
| 3635 | @Language::Axbasic::Function::Intrinsic::String::right::ISA = qw( | ||
| 3636 | Language::Axbasic::Function::Intrinsic::String | ||
| 3637 | ); | ||
| 3638 | |||
| 3639 | # Right$ (string, length) | ||
| 3640 | |||
| 3641 | ################## | ||
| 3642 | # Methods | ||
| 3643 | |||
| 3644 | sub evaluate { | ||
| 3645 | |||
| 3646 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN') | ||
| 3647 | # | ||
| 3648 | # Expected arguments | ||
| 3649 | # @args - The list of arguments supplied to the function | ||
| 3650 | # | ||
| 3651 | # Return values | ||
| 3652 | # The return value of the function | ||
| 3653 | |||
| 3654 | my ($self, @args) = @_; | ||
| 3655 | |||
| 3656 | # Local variables | ||
| 3657 | my ($string, $length); | ||
| 3658 | |||
| 3659 | # (No improper arguments to check) | ||
| 3660 | |||
| 3661 | # Evaluate the function and return the value | ||
| 3662 | ($string, $length) = @args; | ||
| 3663 | |||
| 3664 | # The value of $length can be 0 (which returns an empty string), but cannot be negative | ||
| 3665 | if ($length < 0) { | ||
| 3666 | |||
| 3667 | return $self->scriptObj->setError( | ||
| 3668 | 'number_NUM_out_of_range', | ||
| 3669 | $self->_objClass . '->evaluate', | ||
| 3670 | 'NUM', $length, | ||
| 3671 | ); | ||
| 3672 | } | ||
| 3673 | |||
| 3674 | return substr($string, ($length * -1)); | ||
| 3675 | } | ||
| 3676 | } | ||
| 3677 | |||
| 3678 | { package Language::Axbasic::Function::Intrinsic::String::rtrim; | ||
| 3679 | |||
| 3680 | use strict; | ||
| 3681 | use warnings; | ||
| 3682 | # use diagnostics; | ||
| 3683 | |||
| 3684 | use Glib qw(TRUE FALSE); | ||
| 3685 | |||
| 3686 | @Language::Axbasic::Function::Intrinsic::String::rtrim::ISA = qw( | ||
| 3687 | Language::Axbasic::Function::Intrinsic::String | ||
| 3688 | ); | ||
| 3689 | |||
| 3690 | # Rtrim$ (string) | ||
| 3691 | |||
| 3692 | ################## | ||
| 3693 | # Methods | ||
| 3694 | |||
| 3695 | sub evaluate { | ||
| 3696 | |||
| 3697 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 3698 | # | ||
| 3699 | # Expected arguments | ||
| 3700 | # $arg - The first (and only) argument in the argument list | ||
| 3701 | # | ||
| 3702 | # Return values | ||
| 3703 | # The return value of the function | ||
| 3704 | |||
| 3705 | my ($self, $arg) = @_; | ||
| 3706 | |||
| 3707 | # (No improper arguments to check) | ||
| 3708 | |||
| 3709 | # Evaluate the function and return the value | ||
| 3710 | $arg =~ s/\s+$//; | ||
| 3711 | |||
| 3712 | return uc($arg); | ||
| 3713 | } | ||
| 3714 | } | ||
| 3715 | |||
| 3716 | { package Language::Axbasic::Function::Intrinsic::String::str; | ||
| 3717 | |||
| 3718 | use strict; | ||
| 3719 | use warnings; | ||
| 3720 | # use diagnostics; | ||
| 3721 | |||
| 3722 | use Glib qw(TRUE FALSE); | ||
| 3723 | |||
| 3724 | @Language::Axbasic::Function::Intrinsic::String::str::ISA = qw( | ||
| 3725 | Language::Axbasic::Function::Intrinsic::String | ||
| 3726 | ); | ||
| 3727 | |||
| 3728 | # Str$ (number) | ||
| 3729 | |||
| 3730 | ################## | ||
| 3731 | # Methods | ||
| 3732 | |||
| 3733 | sub evaluate { | ||
| 3734 | |||
| 3735 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 3736 | # | ||
| 3737 | # Expected arguments | ||
| 3738 | # $arg - The first (and only) argument in the argument list | ||
| 3739 | # | ||
| 3740 | # Return values | ||
| 3741 | # The return value of the function | ||
| 3742 | |||
| 3743 | my ($self, $arg) = @_; | ||
| 3744 | |||
| 3745 | # (No improper arguments to check) | ||
| 3746 | |||
| 3747 | # Evaluate the function and return the value | ||
| 3748 | return $arg . ''; | ||
| 3749 | } | ||
| 3750 | } | ||
| 3751 | |||
| 3752 | { package Language::Axbasic::Function::Intrinsic::String::testpat; | ||
| 3753 | |||
| 3754 | use strict; | ||
| 3755 | use warnings; | ||
| 3756 | # use diagnostics; | ||
| 3757 | |||
| 3758 | use Glib qw(TRUE FALSE); | ||
| 3759 | |||
| 3760 | @Language::Axbasic::Function::Intrinsic::String::testpat::ISA = qw( | ||
| 3761 | Language::Axbasic::Function::Intrinsic::String | ||
| 3762 | ); | ||
| 3763 | |||
| 3764 | # Testpat$ (regex) | ||
| 3765 | |||
| 3766 | ################## | ||
| 3767 | # Methods | ||
| 3768 | |||
| 3769 | sub evaluate { | ||
| 3770 | |||
| 3771 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 3772 | # | ||
| 3773 | # Expected arguments | ||
| 3774 | # $arg - The first (and only) argument in the argument list | ||
| 3775 | # | ||
| 3776 | # Return values | ||
| 3777 | # The return value of the function | ||
| 3778 | |||
| 3779 | my ($self, $arg) = @_; | ||
| 3780 | |||
| 3781 | # Local variables | ||
| 3782 | my $result; | ||
| 3783 | |||
| 3784 | # (No improper arguments to check) | ||
| 3785 | |||
| 3786 | # Evaluate the function and return the value | ||
| 3787 | |||
| 3788 | $result = $axmud::CLIENT->regexCheck($arg); | ||
| 3789 | |||
| 3790 | if ($arg eq '' || ! defined $result) { | ||
| 3791 | return ''; | ||
| 3792 | } else { | ||
| 3793 | return $result; | ||
| 3794 | } | ||
| 3795 | } | ||
| 3796 | } | ||
| 3797 | |||
| 3798 | { package Language::Axbasic::Function::Intrinsic::String::time; | ||
| 3799 | |||
| 3800 | use strict; | ||
| 3801 | use warnings; | ||
| 3802 | # use diagnostics; | ||
| 3803 | |||
| 3804 | use Glib qw(TRUE FALSE); | ||
| 3805 | |||
| 3806 | @Language::Axbasic::Function::Intrinsic::String::time::ISA = qw( | ||
| 3807 | Language::Axbasic::Function::Intrinsic::String | ||
| 3808 | ); | ||
| 3809 | |||
| 3810 | # Time$ () | ||
| 3811 | |||
| 3812 | ################## | ||
| 3813 | # Methods | ||
| 3814 | |||
| 3815 | sub evaluate { | ||
| 3816 | |||
| 3817 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 3818 | # | ||
| 3819 | # Expected arguments | ||
| 3820 | # $arg - The first (and only) argument in the argument list | ||
| 3821 | # | ||
| 3822 | # Return values | ||
| 3823 | # The return value of the function | ||
| 3824 | |||
| 3825 | my ($self, $arg) = @_; | ||
| 3826 | |||
| 3827 | # (No improper arguments to check) | ||
| 3828 | |||
| 3829 | # Evaluate the function and return the value | ||
| 3830 | |||
| 3831 | # Get the time | ||
| 3832 | my ($second, $minute, $hour) = localtime(); | ||
| 3833 | |||
| 3834 | # Return the time in the form "HH:MM:SS" | ||
| 3835 | return ( | ||
| 3836 | sprintf("%02d", ($hour)) | ||
| 3837 | . ':' . sprintf("%02d", ($minute)) | ||
| 3838 | . ':' . sprintf("%02d", ($second)), | ||
| 3839 | ); | ||
| 3840 | } | ||
| 3841 | } | ||
| 3842 | |||
| 3843 | { package Language::Axbasic::Function::Intrinsic::String::trim; | ||
| 3844 | |||
| 3845 | use strict; | ||
| 3846 | use warnings; | ||
| 3847 | # use diagnostics; | ||
| 3848 | |||
| 3849 | use Glib qw(TRUE FALSE); | ||
| 3850 | |||
| 3851 | @Language::Axbasic::Function::Intrinsic::String::trim::ISA = qw( | ||
| 3852 | Language::Axbasic::Function::Intrinsic::String | ||
| 3853 | ); | ||
| 3854 | |||
| 3855 | # Trim$ (string) | ||
| 3856 | |||
| 3857 | ################## | ||
| 3858 | # Methods | ||
| 3859 | |||
| 3860 | sub evaluate { | ||
| 3861 | |||
| 3862 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 3863 | # | ||
| 3864 | # Expected arguments | ||
| 3865 | # $arg - The first (and only) argument in the argument list | ||
| 3866 | # | ||
| 3867 | # Return values | ||
| 3868 | # The return value of the function | ||
| 3869 | |||
| 3870 | my ($self, $arg) = @_; | ||
| 3871 | |||
| 3872 | # (No improper arguments to check) | ||
| 3873 | |||
| 3874 | # Evaluate the function and return the value | ||
| 3875 | $arg =~ s/^\s+//; | ||
| 3876 | $arg =~ s/\s+$//; | ||
| 3877 | |||
| 3878 | return uc($arg); | ||
| 3879 | } | ||
| 3880 | } | ||
| 3881 | |||
| 3882 | { package Language::Axbasic::Function::Intrinsic::String::ucase; | ||
| 3883 | |||
| 3884 | use strict; | ||
| 3885 | use warnings; | ||
| 3886 | # use diagnostics; | ||
| 3887 | |||
| 3888 | use Glib qw(TRUE FALSE); | ||
| 3889 | |||
| 3890 | @Language::Axbasic::Function::Intrinsic::String::ucase::ISA = qw( | ||
| 3891 | Language::Axbasic::Function::Intrinsic::String | ||
| 3892 | ); | ||
| 3893 | |||
| 3894 | # Ucase$ (string) | ||
| 3895 | |||
| 3896 | ################## | ||
| 3897 | # Methods | ||
| 3898 | |||
| 3899 | sub evaluate { | ||
| 3900 | |||
| 3901 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 3902 | # | ||
| 3903 | # Expected arguments | ||
| 3904 | # $arg - The first (and only) argument in the argument list | ||
| 3905 | # | ||
| 3906 | # Return values | ||
| 3907 | # The return value of the function | ||
| 3908 | |||
| 3909 | my ($self, $arg) = @_; | ||
| 3910 | |||
| 3911 | # (No improper arguments to check) | ||
| 3912 | |||
| 3913 | # Evaluate the function and return the value | ||
| 3914 | return uc($arg); | ||
| 3915 | } | ||
| 3916 | } | ||
| 3917 | |||
| 3918 | ### Axmud-dependent functions (numeric) ### | ||
| 3919 | |||
| 3920 | { package Language::Axbasic::Function::Intrinsic::Numeric::addexit; | ||
| 3921 | |||
| 3922 | use strict; | ||
| 3923 | use warnings; | ||
| 3924 | # use diagnostics; | ||
| 3925 | |||
| 3926 | use Glib qw(TRUE FALSE); | ||
| 3927 | |||
| 3928 | @Language::Axbasic::Function::Intrinsic::Numeric::addexit::ISA = qw( | ||
| 3929 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 3930 | ); | ||
| 3931 | |||
| 3932 | # Addexit (number, string) | ||
| 3933 | # Addexit (number, string, string) | ||
| 3934 | |||
| 3935 | ################## | ||
| 3936 | # Methods | ||
| 3937 | |||
| 3938 | sub evaluate { | ||
| 3939 | |||
| 3940 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NS;S') | ||
| 3941 | # | ||
| 3942 | # Expected arguments | ||
| 3943 | # @args - The list of arguments supplied to the function | ||
| 3944 | # | ||
| 3945 | # Return values | ||
| 3946 | # The return value of the function | ||
| 3947 | |||
| 3948 | my ($self, @args) = @_; | ||
| 3949 | |||
| 3950 | # Local variables | ||
| 3951 | my ( | ||
| 3952 | $wmObj, $roomNum, $dir, $mapDir, $roomObj, $exitObj, $dictObj, | ||
| 3953 | @shortList, @longList, @dirList, | ||
| 3954 | ); | ||
| 3955 | |||
| 3956 | # (No improper arguments to check) | ||
| 3957 | |||
| 3958 | # Evaluate the function and return the value | ||
| 3959 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 3960 | |||
| 3961 | $roomNum = $args[0]; | ||
| 3962 | $dir = $args[1]; | ||
| 3963 | $mapDir = $args[2]; | ||
| 3964 | |||
| 3965 | # Check that the specified room exists | ||
| 3966 | if (! $wmObj->ivExists('roomModelHash', $roomNum)) { | ||
| 3967 | |||
| 3968 | return 0; | ||
| 3969 | } | ||
| 3970 | |||
| 3971 | # Check that an exit in the specified direction doesn't already exist | ||
| 3972 | $roomObj = $wmObj->ivShow('roomModelHash', $roomNum); | ||
| 3973 | if ($roomObj->ivExists('exitNumHash', $dir)) { | ||
| 3974 | |||
| 3975 | return 0; | ||
| 3976 | } | ||
| 3977 | |||
| 3978 | # Check that a standard (i.e. primary) direction is valid, if specified | ||
| 3979 | if (defined $mapDir) { | ||
| 3980 | |||
| 3981 | if (! $axmud::CLIENT->ivShow('constOppDirHash', $mapDir)) { | ||
| 3982 | |||
| 3983 | return 0; | ||
| 3984 | } | ||
| 3985 | |||
| 3986 | } else { | ||
| 3987 | |||
| 3988 | $dictObj = $self->scriptObj->session->currentDict; | ||
| 3989 | $mapDir = $dictObj->ivShow('combRevDirHash', $dir); | ||
| 3990 | if (! defined $mapDir) { | ||
| 3991 | |||
| 3992 | # $dir is not a primary direction; map it onto the first available primary | ||
| 3993 | # direction | ||
| 3994 | # This code is adapted from GA::Win::Map->allocateMapDirCallback and | ||
| 3995 | # ->getAvailableDirs. If Axmud is ever refactored, that code should probably be | ||
| 3996 | # moved from GA::Win::Map into the worldmodel, so this function can call it... | ||
| 3997 | @shortList = qw( | ||
| 3998 | north northeast east southeast south southwest west northwest up down | ||
| 3999 | ); | ||
| 4000 | |||
| 4001 | @longList = qw( | ||
| 4002 | northnortheast eastnortheast eastsoutheast southsoutheast | ||
| 4003 | southsouthwest westsouthwest westnorthwest northnorthwest | ||
| 4004 | ); | ||
| 4005 | |||
| 4006 | if ($wmObj->showAllPrimaryFlag) { | ||
| 4007 | @dirList = (@shortList, @longList); | ||
| 4008 | } else { | ||
| 4009 | @dirList = @shortList; | ||
| 4010 | } | ||
| 4011 | |||
| 4012 | OUTER: foreach my $thisMapDir (@dirList) { | ||
| 4013 | |||
| 4014 | INNER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) { | ||
| 4015 | |||
| 4016 | my $thisExitObj = $wmObj->ivShow('exitModelHash', $exitNum); | ||
| 4017 | |||
| 4018 | if ( | ||
| 4019 | $thisExitObj->mapDir | ||
| 4020 | && $thisExitObj->mapDir eq $thisMapDir | ||
| 4021 | && ( | ||
| 4022 | $thisExitObj->drawMode eq 'primary' | ||
| 4023 | || $thisExitObj->drawMode eq 'perm_alloc' | ||
| 4024 | ) | ||
| 4025 | ) { | ||
| 4026 | # $mapDir isn't available | ||
| 4027 | next OUTER; | ||
| 4028 | } | ||
| 4029 | } | ||
| 4030 | |||
| 4031 | # $mapDir is available | ||
| 4032 | $mapDir = $thisMapDir; | ||
| 4033 | last OUTER; | ||
| 4034 | } | ||
| 4035 | } | ||
| 4036 | } | ||
| 4037 | |||
| 4038 | if (! defined $mapDir) { | ||
| 4039 | |||
| 4040 | return 0; | ||
| 4041 | } | ||
| 4042 | |||
| 4043 | # Attempt to add the exit | ||
| 4044 | $exitObj = $wmObj->addExit( | ||
| 4045 | $self->scriptObj->session, | ||
| 4046 | TRUE, # Update Automapper windows now | ||
| 4047 | $roomObj, | ||
| 4048 | $dir, | ||
| 4049 | $mapDir, | ||
| 4050 | ); | ||
| 4051 | |||
| 4052 | if (! $exitObj) { | ||
| 4053 | return 0; | ||
| 4054 | } else { | ||
| 4055 | return $exitObj->number; | ||
| 4056 | } | ||
| 4057 | } | ||
| 4058 | } | ||
| 4059 | |||
| 4060 | { package Language::Axbasic::Function::Intrinsic::Numeric::addfirstroom; | ||
| 4061 | |||
| 4062 | use strict; | ||
| 4063 | use warnings; | ||
| 4064 | # use diagnostics; | ||
| 4065 | |||
| 4066 | use Glib qw(TRUE FALSE); | ||
| 4067 | |||
| 4068 | @Language::Axbasic::Function::Intrinsic::Numeric::addfirstroom::ISA = qw( | ||
| 4069 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4070 | ); | ||
| 4071 | |||
| 4072 | # Addfirstroom () | ||
| 4073 | |||
| 4074 | ################## | ||
| 4075 | # Methods | ||
| 4076 | |||
| 4077 | sub evaluate { | ||
| 4078 | |||
| 4079 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 4080 | # | ||
| 4081 | # Expected arguments | ||
| 4082 | # $arg - The first (and only) argument in the argument list | ||
| 4083 | # | ||
| 4084 | # Return values | ||
| 4085 | # The return value of the function | ||
| 4086 | |||
| 4087 | my ($self, $arg) = @_; | ||
| 4088 | |||
| 4089 | # Local variables | ||
| 4090 | my $mapWin; | ||
| 4091 | |||
| 4092 | # (No improper arguments to check) | ||
| 4093 | |||
| 4094 | # Evaluate the function and return the value | ||
| 4095 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 4096 | |||
| 4097 | if (! $mapWin || ! $mapWin->currentRegionmap || $mapWin->currentRegionmap->gridRoomHash) { | ||
| 4098 | |||
| 4099 | # Automapper window not open, no current regionmap or the current regionmap isn't | ||
| 4100 | # empty | ||
| 4101 | return 0; | ||
| 4102 | } | ||
| 4103 | |||
| 4104 | # Attemp to add a first room | ||
| 4105 | if (! $mapWin->addFirstRoomCallback()) { | ||
| 4106 | |||
| 4107 | # Operation failed | ||
| 4108 | return 0; | ||
| 4109 | |||
| 4110 | } else { | ||
| 4111 | |||
| 4112 | # Return the number of the room created | ||
| 4113 | return $mapWin->mapObj->currentRoom->number; | ||
| 4114 | } | ||
| 4115 | } | ||
| 4116 | } | ||
| 4117 | |||
| 4118 | { package Language::Axbasic::Function::Intrinsic::Numeric::addlabel; | ||
| 4119 | |||
| 4120 | use strict; | ||
| 4121 | use warnings; | ||
| 4122 | # use diagnostics; | ||
| 4123 | |||
| 4124 | use Glib qw(TRUE FALSE); | ||
| 4125 | |||
| 4126 | @Language::Axbasic::Function::Intrinsic::Numeric::addlabel::ISA = qw( | ||
| 4127 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4128 | ); | ||
| 4129 | |||
| 4130 | # Addlabel (string, x, y, z) | ||
| 4131 | |||
| 4132 | ################## | ||
| 4133 | # Methods | ||
| 4134 | |||
| 4135 | sub evaluate { | ||
| 4136 | |||
| 4137 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SNNN') | ||
| 4138 | # | ||
| 4139 | # Expected arguments | ||
| 4140 | # @args - The list of arguments supplied to the function | ||
| 4141 | # | ||
| 4142 | # Return values | ||
| 4143 | # The return value of the function | ||
| 4144 | |||
| 4145 | my ($self, @args) = @_; | ||
| 4146 | |||
| 4147 | # Local variables | ||
| 4148 | my ($mapObj, $wmObj, $regionmapObj, $xPos, $yPos, $zPos, $labelObj); | ||
| 4149 | |||
| 4150 | # (No improper arguments to check) | ||
| 4151 | |||
| 4152 | # Evaluate the function and return the value | ||
| 4153 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 4154 | $wmObj = $mapObj->worldModelObj; | ||
| 4155 | |||
| 4156 | if ( | ||
| 4157 | ! $mapObj->currentRoom | ||
| 4158 | || ! $args[0] | ||
| 4159 | ) { | ||
| 4160 | # No current room or empty label string | ||
| 4161 | return 0; | ||
| 4162 | } | ||
| 4163 | |||
| 4164 | # Get the current room's parent regionmap | ||
| 4165 | $regionmapObj = $wmObj->findRegionmap($mapObj->currentRoom->parent); | ||
| 4166 | if (! $regionmapObj) { | ||
| 4167 | |||
| 4168 | # Failsafe | ||
| 4169 | return 0; | ||
| 4170 | } | ||
| 4171 | |||
| 4172 | # Get the current room's coordinates on the grid, and add (or subtract) the relative | ||
| 4173 | # coordinates in the argument list | ||
| 4174 | $xPos = $mapObj->currentRoom->xPosBlocks + $args[1]; | ||
| 4175 | $yPos = $mapObj->currentRoom->yPosBlocks + $args[2]; | ||
| 4176 | $zPos = $mapObj->currentRoom->zPosBlocks + $args[3]; | ||
| 4177 | |||
| 4178 | # Check that the gridblock is valid | ||
| 4179 | if (! $regionmapObj->checkGridBlock($xPos, $yPos, $zPos)) { | ||
| 4180 | |||
| 4181 | return 0; | ||
| 4182 | } | ||
| 4183 | |||
| 4184 | # Attempt to add the label | ||
| 4185 | $labelObj = $wmObj->addLabel( | ||
| 4186 | $self->scriptObj->session, | ||
| 4187 | TRUE, # Update Automapper windows now | ||
| 4188 | $regionmapObj, | ||
| 4189 | ($xPos * $regionmapObj->blockWidthPixels), | ||
| 4190 | ($yPos * $regionmapObj->blockHeightPixels), | ||
| 4191 | $zPos, | ||
| 4192 | $args[0], | ||
| 4193 | ); | ||
| 4194 | |||
| 4195 | if (! $labelObj) { | ||
| 4196 | return 0; | ||
| 4197 | } else { | ||
| 4198 | return $labelObj->number; | ||
| 4199 | } | ||
| 4200 | } | ||
| 4201 | } | ||
| 4202 | |||
| 4203 | { package Language::Axbasic::Function::Intrinsic::Numeric::addregion; | ||
| 4204 | |||
| 4205 | use strict; | ||
| 4206 | use warnings; | ||
| 4207 | # use diagnostics; | ||
| 4208 | |||
| 4209 | use Glib qw(TRUE FALSE); | ||
| 4210 | |||
| 4211 | @Language::Axbasic::Function::Intrinsic::Numeric::addregion::ISA = qw( | ||
| 4212 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4213 | ); | ||
| 4214 | |||
| 4215 | # Addregion (string) | ||
| 4216 | |||
| 4217 | ################## | ||
| 4218 | # Methods | ||
| 4219 | |||
| 4220 | sub evaluate { | ||
| 4221 | |||
| 4222 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 4223 | # | ||
| 4224 | # Expected arguments | ||
| 4225 | # $arg - The first (and only) argument in the argument list | ||
| 4226 | # | ||
| 4227 | # Return values | ||
| 4228 | # The return value of the function | ||
| 4229 | |||
| 4230 | my ($self, $arg) = @_; | ||
| 4231 | |||
| 4232 | # Local variables | ||
| 4233 | my $regionObj; | ||
| 4234 | |||
| 4235 | # (No improper arguments to check) | ||
| 4236 | |||
| 4237 | # Evaluate the function and return the value | ||
| 4238 | $regionObj = $self->scriptObj->session->worldModelObj->addRegion( | ||
| 4239 | $self->scriptObj->session, | ||
| 4240 | TRUE, # Update Automapper windows now | ||
| 4241 | $arg, | ||
| 4242 | ); | ||
| 4243 | |||
| 4244 | if (! $regionObj) { | ||
| 4245 | return 0; | ||
| 4246 | } else { | ||
| 4247 | return $regionObj->number; | ||
| 4248 | } | ||
| 4249 | } | ||
| 4250 | } | ||
| 4251 | |||
| 4252 | { package Language::Axbasic::Function::Intrinsic::Numeric::addroom; | ||
| 4253 | |||
| 4254 | use strict; | ||
| 4255 | use warnings; | ||
| 4256 | # use diagnostics; | ||
| 4257 | |||
| 4258 | use Glib qw(TRUE FALSE); | ||
| 4259 | |||
| 4260 | @Language::Axbasic::Function::Intrinsic::Numeric::addroom::ISA = qw( | ||
| 4261 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4262 | ); | ||
| 4263 | |||
| 4264 | # Addroom (x, y, z) | ||
| 4265 | |||
| 4266 | ################## | ||
| 4267 | # Methods | ||
| 4268 | |||
| 4269 | sub evaluate { | ||
| 4270 | |||
| 4271 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NNN') | ||
| 4272 | # | ||
| 4273 | # Expected arguments | ||
| 4274 | # @args - The list of arguments supplied to the function | ||
| 4275 | # | ||
| 4276 | # Return values | ||
| 4277 | # The return value of the function | ||
| 4278 | |||
| 4279 | my ($self, @args) = @_; | ||
| 4280 | |||
| 4281 | # Local variables | ||
| 4282 | my ($mapObj, $wmObj, $regionmapObj, $xPos, $yPos, $zPos, $roomObj); | ||
| 4283 | |||
| 4284 | # (No improper arguments to check) | ||
| 4285 | |||
| 4286 | # Evaluate the function and return the value | ||
| 4287 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 4288 | $wmObj = $mapObj->worldModelObj; | ||
| 4289 | |||
| 4290 | if (! $mapObj->currentRoom ) { | ||
| 4291 | |||
| 4292 | # No current room | ||
| 4293 | return 0; | ||
| 4294 | } | ||
| 4295 | |||
| 4296 | # Get the current room's parent regionmap | ||
| 4297 | $regionmapObj = $wmObj->findRegionmap($mapObj->currentRoom->parent); | ||
| 4298 | if (! $regionmapObj) { | ||
| 4299 | |||
| 4300 | # Failsafe | ||
| 4301 | return 0; | ||
| 4302 | } | ||
| 4303 | |||
| 4304 | # Get the current room's coordinates on the grid, and add (or subtract) the relative | ||
| 4305 | # coordinates in the argument list | ||
| 4306 | $xPos = $mapObj->currentRoom->xPosBlocks + $args[0]; | ||
| 4307 | $yPos = $mapObj->currentRoom->yPosBlocks + $args[1]; | ||
| 4308 | $zPos = $mapObj->currentRoom->zPosBlocks + $args[2]; | ||
| 4309 | |||
| 4310 | # Check that the gridblock is valid and not occupied by an existing room | ||
| 4311 | if ( | ||
| 4312 | ! $regionmapObj->checkGridBlock($xPos, $yPos, $zPos) | ||
| 4313 | || $regionmapObj->fetchRoom($xPos, $yPos, $zPos) | ||
| 4314 | ) { | ||
| 4315 | return 0; | ||
| 4316 | } | ||
| 4317 | |||
| 4318 | # Attempt to add the room | ||
| 4319 | $roomObj = $wmObj->addRoom( | ||
| 4320 | $self->scriptObj->session, | ||
| 4321 | TRUE, # Update Automapper windows now | ||
| 4322 | $regionmapObj->name, | ||
| 4323 | $xPos, | ||
| 4324 | $yPos, | ||
| 4325 | $zPos, | ||
| 4326 | ); | ||
| 4327 | |||
| 4328 | if (! $roomObj) { | ||
| 4329 | return 0; | ||
| 4330 | } else { | ||
| 4331 | return $roomObj->number; | ||
| 4332 | } | ||
| 4333 | } | ||
| 4334 | } | ||
| 4335 | |||
| 4336 | { package Language::Axbasic::Function::Intrinsic::Numeric::addtempregion; | ||
| 4337 | |||
| 4338 | use strict; | ||
| 4339 | use warnings; | ||
| 4340 | # use diagnostics; | ||
| 4341 | |||
| 4342 | use Glib qw(TRUE FALSE); | ||
| 4343 | |||
| 4344 | @Language::Axbasic::Function::Intrinsic::Numeric::addtempregion::ISA = qw( | ||
| 4345 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4346 | ); | ||
| 4347 | |||
| 4348 | # Addtempregion () | ||
| 4349 | # Addtempregion (string) | ||
| 4350 | |||
| 4351 | ################## | ||
| 4352 | # Methods | ||
| 4353 | |||
| 4354 | sub evaluate { | ||
| 4355 | |||
| 4356 | # Called by LA::Expression::Function->evaluate (using arguments in the form ';S') | ||
| 4357 | # | ||
| 4358 | # Expected arguments | ||
| 4359 | # $arg - The first (and only) argument in the argument list | ||
| 4360 | # | ||
| 4361 | # Return values | ||
| 4362 | # The return value of the function | ||
| 4363 | |||
| 4364 | my ($self, $arg) = @_; | ||
| 4365 | |||
| 4366 | # Local variables | ||
| 4367 | my ( | ||
| 4368 | $wmObj, $count, $name, $regionObj, | ||
| 4369 | %regionHash, | ||
| 4370 | ); | ||
| 4371 | |||
| 4372 | # (No improper arguments to check) | ||
| 4373 | |||
| 4374 | # Evaluate the function and return the value | ||
| 4375 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 4376 | |||
| 4377 | # If a region name wasn't specified, we have to create one in the form 'temp_x'. To protect | ||
| 4378 | # against infinite loops, give up at 9999 | ||
| 4379 | if (! $arg) { | ||
| 4380 | |||
| 4381 | # Get a convenient hash of region names for quick lookup | ||
| 4382 | foreach my $obj ($wmObj->ivValues('regionModelHash')) { | ||
| 4383 | |||
| 4384 | if ($obj->name) { | ||
| 4385 | |||
| 4386 | $regionHash{$obj->name} = undef; | ||
| 4387 | } | ||
| 4388 | } | ||
| 4389 | |||
| 4390 | # First temporary region would be called 'temp_1' | ||
| 4391 | $count = 0; | ||
| 4392 | do { | ||
| 4393 | |||
| 4394 | $count++; | ||
| 4395 | my $string = 'temp_' . $count; | ||
| 4396 | |||
| 4397 | if (! exists $regionHash{$string}) { | ||
| 4398 | |||
| 4399 | # We can use this name | ||
| 4400 | $name = $string; | ||
| 4401 | } | ||
| 4402 | |||
| 4403 | } until ($name || $count >= 9999); | ||
| 4404 | |||
| 4405 | } else { | ||
| 4406 | |||
| 4407 | $name = $arg; | ||
| 4408 | } | ||
| 4409 | |||
| 4410 | if (! $name) { | ||
| 4411 | |||
| 4412 | # Could not find a name for the temporary region | ||
| 4413 | return 0; | ||
| 4414 | } | ||
| 4415 | |||
| 4416 | # Add the temporary region | ||
| 4417 | $regionObj = $wmObj->addRegion( | ||
| 4418 | $self->scriptObj->session, | ||
| 4419 | TRUE, # Update Automapper windows now | ||
| 4420 | $name, | ||
| 4421 | undef, # No parent region | ||
| 4422 | TRUE, # Temporary region | ||
| 4423 | ); | ||
| 4424 | |||
| 4425 | if (! $regionObj) { | ||
| 4426 | return 0; | ||
| 4427 | } else { | ||
| 4428 | return $regionObj->number; | ||
| 4429 | } | ||
| 4430 | } | ||
| 4431 | } | ||
| 4432 | |||
| 4433 | { package Language::Axbasic::Function::Intrinsic::Numeric::addtwinexit; | ||
| 4434 | |||
| 4435 | use strict; | ||
| 4436 | use warnings; | ||
| 4437 | # use diagnostics; | ||
| 4438 | |||
| 4439 | use Glib qw(TRUE FALSE); | ||
| 4440 | |||
| 4441 | @Language::Axbasic::Function::Intrinsic::Numeric::addtwinexit::ISA = qw( | ||
| 4442 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4443 | ); | ||
| 4444 | |||
| 4445 | # Addtwinexit (number) | ||
| 4446 | |||
| 4447 | ################## | ||
| 4448 | # Methods | ||
| 4449 | |||
| 4450 | sub evaluate { | ||
| 4451 | |||
| 4452 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 4453 | # | ||
| 4454 | # Expected arguments | ||
| 4455 | # $arg - The first (and only) argument in the argument list | ||
| 4456 | # | ||
| 4457 | # Return values | ||
| 4458 | # The return value of the function | ||
| 4459 | |||
| 4460 | my ($self, $arg) = @_; | ||
| 4461 | |||
| 4462 | # Local variables | ||
| 4463 | my ($wmObj, $exitObj, $oppExitObj, $roomObj, $destRoomObj, $dictObj, $oppMapDir); | ||
| 4464 | |||
| 4465 | # (No improper arguments to check) | ||
| 4466 | |||
| 4467 | # Evaluate the function and return the value | ||
| 4468 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 4469 | |||
| 4470 | # Find the specified exit, and check it is connected, and that it does not already have a | ||
| 4471 | # twin | ||
| 4472 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 4473 | if ( | ||
| 4474 | ! defined $exitObj | ||
| 4475 | || ! $exitObj->mapDir | ||
| 4476 | || ! $exitObj->destRoom | ||
| 4477 | || $exitObj->twinExit | ||
| 4478 | ) { | ||
| 4479 | return 0; | ||
| 4480 | } | ||
| 4481 | |||
| 4482 | # If an exit in the opposite direction already exists, and is not connected to a room, then | ||
| 4483 | # make this a pair of twin exits | ||
| 4484 | $roomObj = $wmObj->ivShow('roomModelHash', $exitObj->parent); | ||
| 4485 | $oppExitObj = $wmObj->checkOppPrimary($exitObj); | ||
| 4486 | if ($oppExitObj) { | ||
| 4487 | |||
| 4488 | # (As usual, we don't use unallocated exits) | ||
| 4489 | if ( | ||
| 4490 | $oppExitObj->twinExit | ||
| 4491 | || $oppExitObj->destRoom | ||
| 4492 | || ( | ||
| 4493 | $oppExitObj->drawMode ne 'primary' | ||
| 4494 | && $oppExitObj->drawMode ne 'perm_alloc' | ||
| 4495 | ) | ||
| 4496 | ) { | ||
| 4497 | |||
| 4498 | return 0; | ||
| 4499 | |||
| 4500 | } else { | ||
| 4501 | |||
| 4502 | $destRoomObj = $wmObj->ivShow('roomModelHash', $oppExitObj->parent); | ||
| 4503 | |||
| 4504 | } | ||
| 4505 | |||
| 4506 | # Otherwise, create a new exit | ||
| 4507 | } else { | ||
| 4508 | |||
| 4509 | $dictObj = $self->scriptObj->session->currentDict; | ||
| 4510 | $oppMapDir = $axmud::CLIENT->ivShow('constOppDirHash', $exitObj->mapDir); | ||
| 4511 | $destRoomObj = $wmObj->ivShow('roomModelHash', $exitObj->destRoom); | ||
| 4512 | |||
| 4513 | $oppExitObj = $wmObj->addExit( | ||
| 4514 | $self->scriptObj->session, | ||
| 4515 | TRUE, # Update Automapper windows now | ||
| 4516 | $destRoomObj, | ||
| 4517 | $dictObj->ivShow('combDirHash', $oppMapDir), | ||
| 4518 | $oppMapDir, | ||
| 4519 | ); | ||
| 4520 | |||
| 4521 | if (! $oppExitObj) { | ||
| 4522 | |||
| 4523 | return 0; | ||
| 4524 | } | ||
| 4525 | } | ||
| 4526 | |||
| 4527 | # Connect the rooms/exists together | ||
| 4528 | if ( | ||
| 4529 | ! $wmObj->connectRooms( | ||
| 4530 | $self->scriptObj->session, | ||
| 4531 | TRUE, # Update Automapper windows now | ||
| 4532 | $destRoomObj, | ||
| 4533 | $roomObj, | ||
| 4534 | $oppExitObj->dir, | ||
| 4535 | $oppExitObj->mapDir, | ||
| 4536 | $oppExitObj, | ||
| 4537 | $exitObj, | ||
| 4538 | ) | ||
| 4539 | ) { | ||
| 4540 | |||
| 4541 | return 0; | ||
| 4542 | |||
| 4543 | } else { | ||
| 4544 | |||
| 4545 | return $oppExitObj->number; | ||
| 4546 | } | ||
| 4547 | } | ||
| 4548 | } | ||
| 4549 | |||
| 4550 | { package Language::Axbasic::Function::Intrinsic::Numeric::closemap; | ||
| 4551 | |||
| 4552 | use strict; | ||
| 4553 | use warnings; | ||
| 4554 | # use diagnostics; | ||
| 4555 | |||
| 4556 | use Glib qw(TRUE FALSE); | ||
| 4557 | |||
| 4558 | @Language::Axbasic::Function::Intrinsic::Numeric::closemap::ISA = qw( | ||
| 4559 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4560 | ); | ||
| 4561 | |||
| 4562 | # Closemap () | ||
| 4563 | |||
| 4564 | ################## | ||
| 4565 | # Methods | ||
| 4566 | |||
| 4567 | sub evaluate { | ||
| 4568 | |||
| 4569 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 4570 | # | ||
| 4571 | # Expected arguments | ||
| 4572 | # $arg - The first (and only) argument in the argument list | ||
| 4573 | # | ||
| 4574 | # Return values | ||
| 4575 | # The return value of the function | ||
| 4576 | |||
| 4577 | my ($self, $arg) = @_; | ||
| 4578 | |||
| 4579 | # Local variables | ||
| 4580 | my $mapWin; | ||
| 4581 | |||
| 4582 | # (No improper arguments to check) | ||
| 4583 | |||
| 4584 | # Evaluate the function and return the value | ||
| 4585 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 4586 | if (! $mapWin) { | ||
| 4587 | |||
| 4588 | # The window is already closed | ||
| 4589 | return 1; | ||
| 4590 | |||
| 4591 | } else { | ||
| 4592 | |||
| 4593 | # Try to close the window | ||
| 4594 | $mapWin->winDestroy(); | ||
| 4595 | |||
| 4596 | if (! $self->scriptObj->session->mapWin) { | ||
| 4597 | |||
| 4598 | # Window closed successfully | ||
| 4599 | return 1; | ||
| 4600 | |||
| 4601 | } else { | ||
| 4602 | |||
| 4603 | # Could not close window | ||
| 4604 | return 0; | ||
| 4605 | } | ||
| 4606 | } | ||
| 4607 | } | ||
| 4608 | } | ||
| 4609 | |||
| 4610 | { package Language::Axbasic::Function::Intrinsic::Numeric::connectexit; | ||
| 4611 | |||
| 4612 | use strict; | ||
| 4613 | use warnings; | ||
| 4614 | # use diagnostics; | ||
| 4615 | |||
| 4616 | use Glib qw(TRUE FALSE); | ||
| 4617 | |||
| 4618 | @Language::Axbasic::Function::Intrinsic::Numeric::connectexit::ISA = qw( | ||
| 4619 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4620 | ); | ||
| 4621 | |||
| 4622 | # Connectexit (number, number) | ||
| 4623 | |||
| 4624 | ################## | ||
| 4625 | # Methods | ||
| 4626 | |||
| 4627 | sub evaluate { | ||
| 4628 | |||
| 4629 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN') | ||
| 4630 | # | ||
| 4631 | # Expected arguments | ||
| 4632 | # @args - The list of arguments supplied to the function | ||
| 4633 | # | ||
| 4634 | # Return values | ||
| 4635 | # The return value of the function | ||
| 4636 | |||
| 4637 | my ($self, @args) = @_; | ||
| 4638 | |||
| 4639 | # Local variables | ||
| 4640 | my ($wmObj, $exitNum, $roomNum, $exitObj, $roomObj, $departRoomObj); | ||
| 4641 | |||
| 4642 | # (No improper arguments to check) | ||
| 4643 | |||
| 4644 | # Evaluate the function and return the value | ||
| 4645 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 4646 | |||
| 4647 | $exitNum = $args[0]; | ||
| 4648 | $roomNum = $args[1]; | ||
| 4649 | |||
| 4650 | # Check that the specified exit and room exist | ||
| 4651 | $exitObj = $wmObj->ivShow('exitModelHash', $exitNum); | ||
| 4652 | $roomObj = $wmObj->ivShow('roomModelHash', $roomNum); | ||
| 4653 | if (! defined $exitObj || ! defined $roomObj) { | ||
| 4654 | |||
| 4655 | return 0; | ||
| 4656 | } | ||
| 4657 | |||
| 4658 | # Check that the exit is not already connected to a room | ||
| 4659 | if (defined $exitObj->destRoom) { | ||
| 4660 | |||
| 4661 | return 0; | ||
| 4662 | } | ||
| 4663 | |||
| 4664 | # Attempt to connect the exit to the room | ||
| 4665 | $departRoomObj = $wmObj->ivShow('roomModelHash', $exitObj->parent); | ||
| 4666 | if ( | ||
| 4667 | ! $wmObj->connectRooms( | ||
| 4668 | $self->scriptObj->session, | ||
| 4669 | TRUE, # Update Automapper windows now | ||
| 4670 | $departRoomObj, | ||
| 4671 | $roomObj, | ||
| 4672 | $exitObj->dir, | ||
| 4673 | $exitObj->mapDir, | ||
| 4674 | $exitObj, | ||
| 4675 | ) | ||
| 4676 | ) { | ||
| 4677 | return 0; | ||
| 4678 | } else { | ||
| 4679 | return $exitObj->number; | ||
| 4680 | } | ||
| 4681 | } | ||
| 4682 | } | ||
| 4683 | |||
| 4684 | { package Language::Axbasic::Function::Intrinsic::Numeric::counttask; | ||
| 4685 | |||
| 4686 | use strict; | ||
| 4687 | use warnings; | ||
| 4688 | # use diagnostics; | ||
| 4689 | |||
| 4690 | use Glib qw(TRUE FALSE); | ||
| 4691 | |||
| 4692 | @Language::Axbasic::Function::Intrinsic::Numeric::counttask::ISA = qw( | ||
| 4693 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4694 | ); | ||
| 4695 | |||
| 4696 | # Counttask (string) | ||
| 4697 | |||
| 4698 | ################## | ||
| 4699 | # Methods | ||
| 4700 | |||
| 4701 | sub evaluate { | ||
| 4702 | |||
| 4703 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 4704 | # | ||
| 4705 | # Expected arguments | ||
| 4706 | # $arg - The first (and only) argument in the argument list | ||
| 4707 | # | ||
| 4708 | # Return values | ||
| 4709 | # The return value of the function | ||
| 4710 | |||
| 4711 | my ($self, $arg) = @_; | ||
| 4712 | |||
| 4713 | # Local variables | ||
| 4714 | my @list; | ||
| 4715 | |||
| 4716 | # (No improper arguments to check) | ||
| 4717 | |||
| 4718 | # Evaluate the function and return the value | ||
| 4719 | |||
| 4720 | # Get a list of tasks in the current tasklist which match $arg. The ->findTask function | ||
| 4721 | # usually accepts the string '-a', but this Axbasic function does not | ||
| 4722 | if ($arg ne '-a') { | ||
| 4723 | |||
| 4724 | @list = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $arg); | ||
| 4725 | } | ||
| 4726 | |||
| 4727 | return scalar @list; | ||
| 4728 | } | ||
| 4729 | } | ||
| 4730 | |||
| 4731 | { package Language::Axbasic::Function::Intrinsic::Numeric::delexit; | ||
| 4732 | |||
| 4733 | use strict; | ||
| 4734 | use warnings; | ||
| 4735 | # use diagnostics; | ||
| 4736 | |||
| 4737 | use Glib qw(TRUE FALSE); | ||
| 4738 | |||
| 4739 | @Language::Axbasic::Function::Intrinsic::Numeric::delexit::ISA = qw( | ||
| 4740 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4741 | ); | ||
| 4742 | |||
| 4743 | # Delexit (number) | ||
| 4744 | |||
| 4745 | ################## | ||
| 4746 | # Methods | ||
| 4747 | |||
| 4748 | sub evaluate { | ||
| 4749 | |||
| 4750 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 4751 | # | ||
| 4752 | # Expected arguments | ||
| 4753 | # $arg - The first (and only) argument in the argument list | ||
| 4754 | # | ||
| 4755 | # Return values | ||
| 4756 | # The return value of the function | ||
| 4757 | |||
| 4758 | my ($self, $arg) = @_; | ||
| 4759 | |||
| 4760 | # Local variables | ||
| 4761 | my ($wmObj, $exitObj); | ||
| 4762 | |||
| 4763 | # (No improper arguments to check) | ||
| 4764 | |||
| 4765 | # Evaluate the function and return the value | ||
| 4766 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 4767 | |||
| 4768 | # Find the specified exit | ||
| 4769 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 4770 | if (! defined $exitObj) { | ||
| 4771 | |||
| 4772 | return 0; | ||
| 4773 | } | ||
| 4774 | |||
| 4775 | # Delete the exit | ||
| 4776 | if ( | ||
| 4777 | ! $wmObj->deleteExits( | ||
| 4778 | $self->scriptObj->session, | ||
| 4779 | TRUE, # Update Automapper windows now | ||
| 4780 | ($exitObj), | ||
| 4781 | ) | ||
| 4782 | ) { | ||
| 4783 | return 0; | ||
| 4784 | } else { | ||
| 4785 | return 1; | ||
| 4786 | } | ||
| 4787 | } | ||
| 4788 | } | ||
| 4789 | |||
| 4790 | { package Language::Axbasic::Function::Intrinsic::Numeric::delregion; | ||
| 4791 | |||
| 4792 | use strict; | ||
| 4793 | use warnings; | ||
| 4794 | # use diagnostics; | ||
| 4795 | |||
| 4796 | use Glib qw(TRUE FALSE); | ||
| 4797 | |||
| 4798 | @Language::Axbasic::Function::Intrinsic::Numeric::delregion::ISA = qw( | ||
| 4799 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4800 | ); | ||
| 4801 | |||
| 4802 | # Delregion (string) | ||
| 4803 | |||
| 4804 | ################## | ||
| 4805 | # Methods | ||
| 4806 | |||
| 4807 | sub evaluate { | ||
| 4808 | |||
| 4809 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 4810 | # | ||
| 4811 | # Expected arguments | ||
| 4812 | # $arg - The first (and only) argument in the argument list | ||
| 4813 | # | ||
| 4814 | # Return values | ||
| 4815 | # The return value of the function | ||
| 4816 | |||
| 4817 | my ($self, $arg) = @_; | ||
| 4818 | |||
| 4819 | # Local variables | ||
| 4820 | my ($wmObj, $regionmapObj, $obj); | ||
| 4821 | |||
| 4822 | # (No improper arguments to check) | ||
| 4823 | |||
| 4824 | # Evaluate the function and return the value | ||
| 4825 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 4826 | |||
| 4827 | # Find a region model object whose name matches $arg | ||
| 4828 | $regionmapObj = $wmObj->ivShow('regionmapHash', $arg); | ||
| 4829 | if ($regionmapObj) { | ||
| 4830 | |||
| 4831 | $obj = $wmObj->ivShow('modelHash', $regionmapObj->number); | ||
| 4832 | } | ||
| 4833 | |||
| 4834 | if (! $obj) { | ||
| 4835 | |||
| 4836 | # No region whose name matches $arg | ||
| 4837 | return 0; | ||
| 4838 | |||
| 4839 | } else { | ||
| 4840 | |||
| 4841 | # Delete the region and all its children (including its rooms and their contents) | ||
| 4842 | if ( | ||
| 4843 | ! $wmObj->deleteRegions( | ||
| 4844 | $self->scriptObj->session, | ||
| 4845 | TRUE, # Update Automapper windows now | ||
| 4846 | $obj, | ||
| 4847 | ) | ||
| 4848 | ) { | ||
| 4849 | return 0; | ||
| 4850 | } else { | ||
| 4851 | return 1; | ||
| 4852 | } | ||
| 4853 | } | ||
| 4854 | } | ||
| 4855 | } | ||
| 4856 | |||
| 4857 | { package Language::Axbasic::Function::Intrinsic::Numeric::delroom; | ||
| 4858 | |||
| 4859 | use strict; | ||
| 4860 | use warnings; | ||
| 4861 | # use diagnostics; | ||
| 4862 | |||
| 4863 | use Glib qw(TRUE FALSE); | ||
| 4864 | |||
| 4865 | @Language::Axbasic::Function::Intrinsic::Numeric::delroom::ISA = qw( | ||
| 4866 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4867 | ); | ||
| 4868 | |||
| 4869 | # Delroom (number) | ||
| 4870 | |||
| 4871 | ################## | ||
| 4872 | # Methods | ||
| 4873 | |||
| 4874 | sub evaluate { | ||
| 4875 | |||
| 4876 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 4877 | # | ||
| 4878 | # Expected arguments | ||
| 4879 | # $arg - The first (and only) argument in the argument list | ||
| 4880 | # | ||
| 4881 | # Return values | ||
| 4882 | # The return value of the function | ||
| 4883 | |||
| 4884 | my ($self, $arg) = @_; | ||
| 4885 | |||
| 4886 | # Local variables | ||
| 4887 | my ($wmObj, $roomObj); | ||
| 4888 | |||
| 4889 | # (No improper arguments to check) | ||
| 4890 | |||
| 4891 | # Evaluate the function and return the value | ||
| 4892 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 4893 | |||
| 4894 | # Find the specified room | ||
| 4895 | $roomObj = $wmObj->ivShow('roomModelHash', $arg); | ||
| 4896 | if (! defined $roomObj) { | ||
| 4897 | |||
| 4898 | return 0; | ||
| 4899 | } | ||
| 4900 | |||
| 4901 | # Delete the room | ||
| 4902 | if ( | ||
| 4903 | ! $wmObj->deleteRooms( | ||
| 4904 | $self->scriptObj->session, | ||
| 4905 | TRUE, # Update Automapper windows now | ||
| 4906 | ($roomObj), | ||
| 4907 | ) | ||
| 4908 | ) { | ||
| 4909 | return 0; | ||
| 4910 | } else { | ||
| 4911 | return 1; | ||
| 4912 | } | ||
| 4913 | } | ||
| 4914 | } | ||
| 4915 | |||
| 4916 | { package Language::Axbasic::Function::Intrinsic::Numeric::deltempregions; | ||
| 4917 | |||
| 4918 | use strict; | ||
| 4919 | use warnings; | ||
| 4920 | # use diagnostics; | ||
| 4921 | |||
| 4922 | use Glib qw(TRUE FALSE); | ||
| 4923 | |||
| 4924 | @Language::Axbasic::Function::Intrinsic::Numeric::deltempregions::ISA = qw( | ||
| 4925 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4926 | ); | ||
| 4927 | |||
| 4928 | # Deltempregions () | ||
| 4929 | |||
| 4930 | ################## | ||
| 4931 | # Methods | ||
| 4932 | |||
| 4933 | sub evaluate { | ||
| 4934 | |||
| 4935 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 4936 | # | ||
| 4937 | # Expected arguments | ||
| 4938 | # $arg - The first (and only) argument in the argument list | ||
| 4939 | # | ||
| 4940 | # Return values | ||
| 4941 | # The return value of the function | ||
| 4942 | |||
| 4943 | my ($self, $arg) = @_; | ||
| 4944 | |||
| 4945 | # (No improper arguments to check) | ||
| 4946 | |||
| 4947 | # Evaluate the function and return the value | ||
| 4948 | if ( | ||
| 4949 | ! $self->scriptObj->session->worldModelObj->deleteTempRegions( | ||
| 4950 | $self->scriptObj->session, | ||
| 4951 | TRUE, # Update Automapper windows now | ||
| 4952 | ) | ||
| 4953 | ) { | ||
| 4954 | return 0; | ||
| 4955 | } else { | ||
| 4956 | return 1; | ||
| 4957 | } | ||
| 4958 | } | ||
| 4959 | } | ||
| 4960 | |||
| 4961 | { package Language::Axbasic::Function::Intrinsic::Numeric::disconnectexit; | ||
| 4962 | |||
| 4963 | use strict; | ||
| 4964 | use warnings; | ||
| 4965 | # use diagnostics; | ||
| 4966 | |||
| 4967 | use Glib qw(TRUE FALSE); | ||
| 4968 | |||
| 4969 | @Language::Axbasic::Function::Intrinsic::Numeric::disconnectexit::ISA = qw( | ||
| 4970 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 4971 | ); | ||
| 4972 | |||
| 4973 | # Disconnectexit (number) | ||
| 4974 | |||
| 4975 | ################## | ||
| 4976 | # Methods | ||
| 4977 | |||
| 4978 | sub evaluate { | ||
| 4979 | |||
| 4980 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 4981 | # | ||
| 4982 | # Expected arguments | ||
| 4983 | # $arg - The first (and only) argument in the argument list | ||
| 4984 | # | ||
| 4985 | # Return values | ||
| 4986 | # The return value of the function | ||
| 4987 | |||
| 4988 | my ($self, $arg) = @_; | ||
| 4989 | |||
| 4990 | # Local variables | ||
| 4991 | my ($wmObj, $exitObj); | ||
| 4992 | |||
| 4993 | # (No improper arguments to check) | ||
| 4994 | |||
| 4995 | # Evaluate the function and return the value | ||
| 4996 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 4997 | |||
| 4998 | # Find the specified exit | ||
| 4999 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 5000 | if (! defined $exitObj) { | ||
| 5001 | |||
| 5002 | return 0; | ||
| 5003 | } | ||
| 5004 | |||
| 5005 | # Disconnect the exit | ||
| 5006 | if ( | ||
| 5007 | ! $wmObj->disconnectExit( | ||
| 5008 | TRUE, # Update Automapper windows now | ||
| 5009 | $exitObj, | ||
| 5010 | ) | ||
| 5011 | ) { | ||
| 5012 | return 0; | ||
| 5013 | } else { | ||
| 5014 | return 1; | ||
| 5015 | } | ||
| 5016 | } | ||
| 5017 | } | ||
| 5018 | |||
| 5019 | { package Language::Axbasic::Function::Intrinsic::Numeric::getexitdest; | ||
| 5020 | |||
| 5021 | use strict; | ||
| 5022 | use warnings; | ||
| 5023 | # use diagnostics; | ||
| 5024 | |||
| 5025 | use Glib qw(TRUE FALSE); | ||
| 5026 | |||
| 5027 | @Language::Axbasic::Function::Intrinsic::Numeric::getexitdest::ISA = qw( | ||
| 5028 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5029 | ); | ||
| 5030 | |||
| 5031 | # Getexitdest (number) | ||
| 5032 | |||
| 5033 | ################## | ||
| 5034 | # Methods | ||
| 5035 | |||
| 5036 | sub evaluate { | ||
| 5037 | |||
| 5038 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 5039 | # | ||
| 5040 | # Expected arguments | ||
| 5041 | # $arg - The first (and only) argument in the argument list | ||
| 5042 | # | ||
| 5043 | # Return values | ||
| 5044 | # The return value of the function | ||
| 5045 | |||
| 5046 | my ($self, $arg) = @_; | ||
| 5047 | |||
| 5048 | # Local variables | ||
| 5049 | my ($mapObj, $wmObj, $dir, $modelNum, $obj); | ||
| 5050 | |||
| 5051 | # (No improper arguments to check) | ||
| 5052 | |||
| 5053 | # Evaluate the function and return the value | ||
| 5054 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 5055 | $wmObj = $mapObj->worldModelObj; | ||
| 5056 | |||
| 5057 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 5058 | $arg--; | ||
| 5059 | |||
| 5060 | if ( | ||
| 5061 | ! $mapObj->currentRoom | ||
| 5062 | || ! $mapObj->currentRoom->sortedExitList | ||
| 5063 | || $arg < 0 | ||
| 5064 | || $arg >= scalar ($mapObj->currentRoom->sortedExitList) | ||
| 5065 | ) { | ||
| 5066 | # No current room, no exits in current room or invalid exit number | ||
| 5067 | return 0; | ||
| 5068 | |||
| 5069 | } else { | ||
| 5070 | |||
| 5071 | # Get the exit model object | ||
| 5072 | $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg); | ||
| 5073 | $modelNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir); | ||
| 5074 | if (! $modelNum || ! $wmObj->ivExists('exitModelHash', $modelNum)) { | ||
| 5075 | |||
| 5076 | # Exit model object not found | ||
| 5077 | return 0; | ||
| 5078 | |||
| 5079 | } else { | ||
| 5080 | |||
| 5081 | $obj = $wmObj->ivShow('exitModelHash', $modelNum); | ||
| 5082 | if (! $obj->destRoom || $obj->randomType ne 'none') { | ||
| 5083 | |||
| 5084 | # Exit doesn't have a destination room, or leads to a random destination | ||
| 5085 | return 0; | ||
| 5086 | |||
| 5087 | } else { | ||
| 5088 | |||
| 5089 | # Return the numbered exit's destination room | ||
| 5090 | return $obj->destRoom; | ||
| 5091 | } | ||
| 5092 | } | ||
| 5093 | } | ||
| 5094 | } | ||
| 5095 | } | ||
| 5096 | |||
| 5097 | { package Language::Axbasic::Function::Intrinsic::Numeric::getexitnum; | ||
| 5098 | |||
| 5099 | use strict; | ||
| 5100 | use warnings; | ||
| 5101 | # use diagnostics; | ||
| 5102 | |||
| 5103 | use Glib qw(TRUE FALSE); | ||
| 5104 | |||
| 5105 | @Language::Axbasic::Function::Intrinsic::Numeric::getexitnum::ISA = qw( | ||
| 5106 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5107 | ); | ||
| 5108 | |||
| 5109 | # Getexitnum (number) | ||
| 5110 | |||
| 5111 | ################## | ||
| 5112 | # Methods | ||
| 5113 | |||
| 5114 | sub evaluate { | ||
| 5115 | |||
| 5116 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 5117 | # | ||
| 5118 | # Expected arguments | ||
| 5119 | # $arg - The first (and only) argument in the argument list | ||
| 5120 | # | ||
| 5121 | # Return values | ||
| 5122 | # The return value of the function | ||
| 5123 | |||
| 5124 | my ($self, $arg) = @_; | ||
| 5125 | |||
| 5126 | # Local variables | ||
| 5127 | my ($mapObj, $wmObj, $dir, $modelNum); | ||
| 5128 | |||
| 5129 | # (No improper arguments to check) | ||
| 5130 | |||
| 5131 | # Evaluate the function and return the value | ||
| 5132 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 5133 | $wmObj = $mapObj->worldModelObj; | ||
| 5134 | |||
| 5135 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 5136 | $arg--; | ||
| 5137 | |||
| 5138 | if ( | ||
| 5139 | ! $mapObj->currentRoom | ||
| 5140 | || ! $mapObj->currentRoom->sortedExitList | ||
| 5141 | || $arg < 0 | ||
| 5142 | || $arg >= scalar ($mapObj->currentRoom->sortedExitList) | ||
| 5143 | ) { | ||
| 5144 | # No current room, no exits in current room or invalid exit number | ||
| 5145 | return 0; | ||
| 5146 | |||
| 5147 | } else { | ||
| 5148 | |||
| 5149 | # Get the exit model object | ||
| 5150 | $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg); | ||
| 5151 | $modelNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir); | ||
| 5152 | if (! $modelNum || ! $wmObj->ivExists('exitModelHash', $modelNum)) { | ||
| 5153 | |||
| 5154 | # Exit model object not found | ||
| 5155 | return 0; | ||
| 5156 | |||
| 5157 | } else { | ||
| 5158 | |||
| 5159 | # Return the exit model number | ||
| 5160 | return $modelNum; | ||
| 5161 | } | ||
| 5162 | } | ||
| 5163 | } | ||
| 5164 | } | ||
| 5165 | |||
| 5166 | { package Language::Axbasic::Function::Intrinsic::Numeric::getexittwin; | ||
| 5167 | |||
| 5168 | use strict; | ||
| 5169 | use warnings; | ||
| 5170 | # use diagnostics; | ||
| 5171 | |||
| 5172 | use Glib qw(TRUE FALSE); | ||
| 5173 | |||
| 5174 | @Language::Axbasic::Function::Intrinsic::Numeric::getexittwin::ISA = qw( | ||
| 5175 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5176 | ); | ||
| 5177 | |||
| 5178 | # Getexittwin (number) | ||
| 5179 | |||
| 5180 | ################## | ||
| 5181 | # Methods | ||
| 5182 | |||
| 5183 | sub evaluate { | ||
| 5184 | |||
| 5185 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 5186 | # | ||
| 5187 | # Expected arguments | ||
| 5188 | # $arg - The first (and only) argument in the argument list | ||
| 5189 | # | ||
| 5190 | # Return values | ||
| 5191 | # The return value of the function | ||
| 5192 | |||
| 5193 | my ($self, $arg) = @_; | ||
| 5194 | |||
| 5195 | # Local variables | ||
| 5196 | my ($mapObj, $wmObj, $dir, $modelNum, $obj); | ||
| 5197 | |||
| 5198 | # (No improper arguments to check) | ||
| 5199 | |||
| 5200 | # Evaluate the function and return the value | ||
| 5201 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 5202 | $wmObj = $mapObj->worldModelObj; | ||
| 5203 | |||
| 5204 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 5205 | $arg--; | ||
| 5206 | |||
| 5207 | if ( | ||
| 5208 | ! $mapObj->currentRoom | ||
| 5209 | || ! $mapObj->currentRoom->sortedExitList | ||
| 5210 | || $arg < 0 | ||
| 5211 | || $arg >= scalar ($mapObj->currentRoom->sortedExitList) | ||
| 5212 | ) { | ||
| 5213 | # No current room, no exits in current room or invalid exit number | ||
| 5214 | return 0; | ||
| 5215 | |||
| 5216 | } else { | ||
| 5217 | |||
| 5218 | # Get the exit model object | ||
| 5219 | $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg); | ||
| 5220 | $modelNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir); | ||
| 5221 | if (! $modelNum || ! $wmObj->ivExists('exitModelHash', $modelNum)) { | ||
| 5222 | |||
| 5223 | # Exit model object not found | ||
| 5224 | return 0; | ||
| 5225 | |||
| 5226 | } else { | ||
| 5227 | |||
| 5228 | $obj = $wmObj->ivShow('exitModelHash', $modelNum); | ||
| 5229 | if (! $obj->twinExit) { | ||
| 5230 | |||
| 5231 | # Exit doesn't have a twin exit | ||
| 5232 | return 0; | ||
| 5233 | |||
| 5234 | } else { | ||
| 5235 | |||
| 5236 | # Return the numbered exit's twin exit | ||
| 5237 | return $obj->twinExit; | ||
| 5238 | } | ||
| 5239 | } | ||
| 5240 | } | ||
| 5241 | } | ||
| 5242 | } | ||
| 5243 | |||
| 5244 | { package Language::Axbasic::Function::Intrinsic::Numeric::getlostroom; | ||
| 5245 | |||
| 5246 | use strict; | ||
| 5247 | use warnings; | ||
| 5248 | # use diagnostics; | ||
| 5249 | |||
| 5250 | use Glib qw(TRUE FALSE); | ||
| 5251 | |||
| 5252 | @Language::Axbasic::Function::Intrinsic::Numeric::getlostroom::ISA = qw( | ||
| 5253 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5254 | ); | ||
| 5255 | |||
| 5256 | # Getlostroom () | ||
| 5257 | |||
| 5258 | ################## | ||
| 5259 | # Methods | ||
| 5260 | |||
| 5261 | sub evaluate { | ||
| 5262 | |||
| 5263 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5264 | # | ||
| 5265 | # Expected arguments | ||
| 5266 | # $arg - The first (and only) argument in the argument list | ||
| 5267 | # | ||
| 5268 | # Return values | ||
| 5269 | # The return value of the function | ||
| 5270 | |||
| 5271 | my ($self, $arg) = @_; | ||
| 5272 | |||
| 5273 | # Local variables | ||
| 5274 | my $mapObj; | ||
| 5275 | |||
| 5276 | # (No improper arguments to check) | ||
| 5277 | |||
| 5278 | # Evaluate the function and return the value | ||
| 5279 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 5280 | if (! $mapObj->lastKnownRoom) { | ||
| 5281 | |||
| 5282 | # Automapper not lost | ||
| 5283 | return 0; | ||
| 5284 | |||
| 5285 | } else { | ||
| 5286 | |||
| 5287 | # Automapper is lost. Return the number of the previous room | ||
| 5288 | return $mapObj->lastKnownRoom->number; | ||
| 5289 | } | ||
| 5290 | } | ||
| 5291 | } | ||
| 5292 | |||
| 5293 | { package Language::Axbasic::Function::Intrinsic::Numeric::getobjectalive; | ||
| 5294 | |||
| 5295 | use strict; | ||
| 5296 | use warnings; | ||
| 5297 | # use diagnostics; | ||
| 5298 | |||
| 5299 | use Glib qw(TRUE FALSE); | ||
| 5300 | |||
| 5301 | @Language::Axbasic::Function::Intrinsic::Numeric::getobjectalive::ISA = qw( | ||
| 5302 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5303 | ); | ||
| 5304 | |||
| 5305 | # Getobjectalive (number) | ||
| 5306 | |||
| 5307 | ################## | ||
| 5308 | # Methods | ||
| 5309 | |||
| 5310 | sub evaluate { | ||
| 5311 | |||
| 5312 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 5313 | # | ||
| 5314 | # Expected arguments | ||
| 5315 | # $arg - The first (and only) argument in the argument list | ||
| 5316 | # | ||
| 5317 | # Return values | ||
| 5318 | # The return value of the function | ||
| 5319 | |||
| 5320 | my ($self, $arg) = @_; | ||
| 5321 | |||
| 5322 | # Local variables | ||
| 5323 | my ($taskObj, $roomObj, $thisObj); | ||
| 5324 | |||
| 5325 | # (No improper arguments to check) | ||
| 5326 | |||
| 5327 | # Evaluate the function and return the value | ||
| 5328 | $taskObj = $self->scriptObj->session->locatorTask; | ||
| 5329 | if (! $taskObj) { | ||
| 5330 | |||
| 5331 | # Locator task not running | ||
| 5332 | return 0; | ||
| 5333 | } | ||
| 5334 | |||
| 5335 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 5336 | $arg--; | ||
| 5337 | |||
| 5338 | $roomObj = $taskObj->roomObj; | ||
| 5339 | if ( | ||
| 5340 | ! $roomObj | ||
| 5341 | || ! $roomObj->tempObjList | ||
| 5342 | || $arg < 0 | ||
| 5343 | || scalar $roomObj->tempObjList <= $arg | ||
| 5344 | ) { | ||
| 5345 | # Locator task doesn't know current location, current location is empty or the | ||
| 5346 | # numbered object doesn't exist | ||
| 5347 | return 0; | ||
| 5348 | |||
| 5349 | } else { | ||
| 5350 | |||
| 5351 | # Return the object's ->aliveFlag | ||
| 5352 | $thisObj = $roomObj->ivIndex('tempObjList', $arg); | ||
| 5353 | if (! $thisObj->aliveFlag) { | ||
| 5354 | return 0; | ||
| 5355 | } else { | ||
| 5356 | return 1; | ||
| 5357 | } | ||
| 5358 | } | ||
| 5359 | } | ||
| 5360 | } | ||
| 5361 | |||
| 5362 | { package Language::Axbasic::Function::Intrinsic::Numeric::getobjectcount; | ||
| 5363 | |||
| 5364 | use strict; | ||
| 5365 | use warnings; | ||
| 5366 | # use diagnostics; | ||
| 5367 | |||
| 5368 | use Glib qw(TRUE FALSE); | ||
| 5369 | |||
| 5370 | @Language::Axbasic::Function::Intrinsic::Numeric::getobjectcount::ISA = qw( | ||
| 5371 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5372 | ); | ||
| 5373 | |||
| 5374 | # Getobjectcount (number) | ||
| 5375 | |||
| 5376 | ################## | ||
| 5377 | # Methods | ||
| 5378 | |||
| 5379 | sub evaluate { | ||
| 5380 | |||
| 5381 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 5382 | # | ||
| 5383 | # Expected arguments | ||
| 5384 | # $arg - The first (and only) argument in the argument list | ||
| 5385 | # | ||
| 5386 | # Return values | ||
| 5387 | # The return value of the function | ||
| 5388 | |||
| 5389 | my ($self, $arg) = @_; | ||
| 5390 | |||
| 5391 | # Local variables | ||
| 5392 | my ($taskObj, $roomObj, $thisObj); | ||
| 5393 | |||
| 5394 | # (No improper arguments to check) | ||
| 5395 | |||
| 5396 | # Evaluate the function and return the value | ||
| 5397 | $taskObj = $self->scriptObj->session->locatorTask; | ||
| 5398 | if (! $taskObj) { | ||
| 5399 | |||
| 5400 | # Locator task not running | ||
| 5401 | return 0; | ||
| 5402 | } | ||
| 5403 | |||
| 5404 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 5405 | $arg--; | ||
| 5406 | |||
| 5407 | $roomObj = $taskObj->roomObj; | ||
| 5408 | if ( | ||
| 5409 | ! $roomObj | ||
| 5410 | || ! $roomObj->tempObjList | ||
| 5411 | || $arg < 0 | ||
| 5412 | || scalar $roomObj->tempObjList <= $arg | ||
| 5413 | ) { | ||
| 5414 | # Locator task doesn't know current location, current location is empty or the | ||
| 5415 | # numbered object doesn't exist | ||
| 5416 | return 0; | ||
| 5417 | |||
| 5418 | } else { | ||
| 5419 | |||
| 5420 | # Return the object's ->multiple | ||
| 5421 | $thisObj = $roomObj->ivIndex('tempObjList', $arg); | ||
| 5422 | if (! $thisObj->multiple) { | ||
| 5423 | |||
| 5424 | # Make sure we don't return an 'undef' value (unlikely) | ||
| 5425 | return 0; | ||
| 5426 | |||
| 5427 | } else { | ||
| 5428 | |||
| 5429 | return $thisObj->multiple; | ||
| 5430 | } | ||
| 5431 | } | ||
| 5432 | } | ||
| 5433 | } | ||
| 5434 | |||
| 5435 | { package Language::Axbasic::Function::Intrinsic::Numeric::getregionnum; | ||
| 5436 | |||
| 5437 | use strict; | ||
| 5438 | use warnings; | ||
| 5439 | # use diagnostics; | ||
| 5440 | |||
| 5441 | use Glib qw(TRUE FALSE); | ||
| 5442 | |||
| 5443 | @Language::Axbasic::Function::Intrinsic::Numeric::getregionnum::ISA = qw( | ||
| 5444 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5445 | ); | ||
| 5446 | |||
| 5447 | # Getregionnum () | ||
| 5448 | |||
| 5449 | ################## | ||
| 5450 | # Methods | ||
| 5451 | |||
| 5452 | sub evaluate { | ||
| 5453 | |||
| 5454 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5455 | # | ||
| 5456 | # Expected arguments | ||
| 5457 | # $arg - The first (and only) argument in the argument list | ||
| 5458 | # | ||
| 5459 | # Return values | ||
| 5460 | # The return value of the function | ||
| 5461 | |||
| 5462 | my ($self, $arg) = @_; | ||
| 5463 | |||
| 5464 | # Local variables | ||
| 5465 | my $mapWin; | ||
| 5466 | |||
| 5467 | # (No improper arguments to check) | ||
| 5468 | |||
| 5469 | # Evaluate the function and return the value | ||
| 5470 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 5471 | if (! $mapWin || ! $mapWin->currentRegionmap) { | ||
| 5472 | |||
| 5473 | # Automapper window closed, or no current region | ||
| 5474 | return 0; | ||
| 5475 | |||
| 5476 | } else { | ||
| 5477 | |||
| 5478 | # Return the number of the current region | ||
| 5479 | return $mapWin->currentRegionmap->number; | ||
| 5480 | } | ||
| 5481 | } | ||
| 5482 | } | ||
| 5483 | |||
| 5484 | { package Language::Axbasic::Function::Intrinsic::Numeric::getroomexits; | ||
| 5485 | |||
| 5486 | use strict; | ||
| 5487 | use warnings; | ||
| 5488 | # use diagnostics; | ||
| 5489 | |||
| 5490 | use Glib qw(TRUE FALSE); | ||
| 5491 | |||
| 5492 | @Language::Axbasic::Function::Intrinsic::Numeric::getroomexits::ISA = qw( | ||
| 5493 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5494 | ); | ||
| 5495 | |||
| 5496 | # Getroomexits () | ||
| 5497 | |||
| 5498 | ################## | ||
| 5499 | # Methods | ||
| 5500 | |||
| 5501 | sub evaluate { | ||
| 5502 | |||
| 5503 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5504 | # | ||
| 5505 | # Expected arguments | ||
| 5506 | # $arg - The first (and only) argument in the argument list | ||
| 5507 | # | ||
| 5508 | # Return values | ||
| 5509 | # The return value of the function | ||
| 5510 | |||
| 5511 | my ($self, $arg) = @_; | ||
| 5512 | |||
| 5513 | # Local variables | ||
| 5514 | my $mapObj; | ||
| 5515 | |||
| 5516 | # (No improper arguments to check) | ||
| 5517 | |||
| 5518 | # Evaluate the function and return the value | ||
| 5519 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 5520 | if (! $mapObj->currentRoom || ! $mapObj->currentRoom->sortedExitList) { | ||
| 5521 | |||
| 5522 | # No current room or current room has no exits | ||
| 5523 | return 0; | ||
| 5524 | |||
| 5525 | } else { | ||
| 5526 | |||
| 5527 | # Return the number of exits in the current room | ||
| 5528 | return (scalar $mapObj->currentRoom->sortedExitList); | ||
| 5529 | } | ||
| 5530 | } | ||
| 5531 | } | ||
| 5532 | |||
| 5533 | { package Language::Axbasic::Function::Intrinsic::Numeric::getroomnum; | ||
| 5534 | |||
| 5535 | use strict; | ||
| 5536 | use warnings; | ||
| 5537 | # use diagnostics; | ||
| 5538 | |||
| 5539 | use Glib qw(TRUE FALSE); | ||
| 5540 | |||
| 5541 | @Language::Axbasic::Function::Intrinsic::Numeric::getroomnum::ISA = qw( | ||
| 5542 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5543 | ); | ||
| 5544 | |||
| 5545 | # Getroomnum () | ||
| 5546 | |||
| 5547 | ################## | ||
| 5548 | # Methods | ||
| 5549 | |||
| 5550 | sub evaluate { | ||
| 5551 | |||
| 5552 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5553 | # | ||
| 5554 | # Expected arguments | ||
| 5555 | # $arg - The first (and only) argument in the argument list | ||
| 5556 | # | ||
| 5557 | # Return values | ||
| 5558 | # The return value of the function | ||
| 5559 | |||
| 5560 | my ($self, $arg) = @_; | ||
| 5561 | |||
| 5562 | # Local variables | ||
| 5563 | my $mapObj; | ||
| 5564 | |||
| 5565 | # (No improper arguments to check) | ||
| 5566 | |||
| 5567 | # Evaluate the function and return the value | ||
| 5568 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 5569 | |||
| 5570 | if (! $mapObj->currentRoom) { | ||
| 5571 | |||
| 5572 | # No current room | ||
| 5573 | return 0; | ||
| 5574 | |||
| 5575 | } else { | ||
| 5576 | |||
| 5577 | # Return the number of the current room | ||
| 5578 | return $mapObj->currentRoom->number; | ||
| 5579 | } | ||
| 5580 | } | ||
| 5581 | } | ||
| 5582 | |||
| 5583 | { package Language::Axbasic::Function::Intrinsic::Numeric::getroomobjects; | ||
| 5584 | |||
| 5585 | use strict; | ||
| 5586 | use warnings; | ||
| 5587 | # use diagnostics; | ||
| 5588 | |||
| 5589 | use Glib qw(TRUE FALSE); | ||
| 5590 | |||
| 5591 | @Language::Axbasic::Function::Intrinsic::Numeric::getroomobjects::ISA = qw( | ||
| 5592 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5593 | ); | ||
| 5594 | |||
| 5595 | # Getroomobjects () | ||
| 5596 | # Getroomobjects (string) | ||
| 5597 | |||
| 5598 | ################## | ||
| 5599 | # Methods | ||
| 5600 | |||
| 5601 | sub evaluate { | ||
| 5602 | |||
| 5603 | # Called by LA::Expression::Function->evaluate (using arguments in the form ';S') | ||
| 5604 | # | ||
| 5605 | # Expected arguments | ||
| 5606 | # $arg - The first (and only) argument in the argument list | ||
| 5607 | # | ||
| 5608 | # Return values | ||
| 5609 | # The return value of the function | ||
| 5610 | |||
| 5611 | my ($self, $arg) = @_; | ||
| 5612 | |||
| 5613 | # Local variables | ||
| 5614 | my ($taskObj, $count); | ||
| 5615 | |||
| 5616 | # (No improper arguments to check) | ||
| 5617 | |||
| 5618 | # Evaluate the function and return the value | ||
| 5619 | $taskObj = $self->scriptObj->session->locatorTask; | ||
| 5620 | |||
| 5621 | if (! $taskObj || ! $taskObj->roomObj || ! $taskObj->roomObj->tempObjList) { | ||
| 5622 | |||
| 5623 | # Locator task not running, does not know current location, or current location is | ||
| 5624 | # empty | ||
| 5625 | return 0; | ||
| 5626 | |||
| 5627 | } elsif (! $arg) { | ||
| 5628 | |||
| 5629 | # Return number of objects in the room | ||
| 5630 | return (scalar $taskObj->roomObj->tempObjList); | ||
| 5631 | |||
| 5632 | } else { | ||
| 5633 | |||
| 5634 | # Count matching things | ||
| 5635 | $count = 0; | ||
| 5636 | |||
| 5637 | if ( | ||
| 5638 | $arg eq 'weapon' || $arg eq 'armour' || $arg eq 'garment' || $arg eq 'char' | ||
| 5639 | || $arg eq 'minion' || $arg eq 'sentient' || $arg eq 'creature' | ||
| 5640 | || $arg eq 'portable' || $arg eq 'decoration' || $arg eq 'custom' | ||
| 5641 | ) { | ||
| 5642 | foreach my $obj ($taskObj->roomObj->tempObjList) { | ||
| 5643 | |||
| 5644 | if ($obj->category eq $arg) { | ||
| 5645 | |||
| 5646 | $count++; | ||
| 5647 | } | ||
| 5648 | } | ||
| 5649 | |||
| 5650 | } elsif ($arg eq 'living') { | ||
| 5651 | |||
| 5652 | foreach my $obj ($taskObj->roomObj->tempObjList) { | ||
| 5653 | |||
| 5654 | if ($obj->aliveFlag) { | ||
| 5655 | |||
| 5656 | $count++; | ||
| 5657 | } | ||
| 5658 | } | ||
| 5659 | |||
| 5660 | } elsif ($arg eq 'not_living') { | ||
| 5661 | |||
| 5662 | foreach my $obj ($taskObj->roomObj->tempObjList) { | ||
| 5663 | |||
| 5664 | if (! $obj->aliveFlag) { | ||
| 5665 | |||
| 5666 | $count++; | ||
| 5667 | } | ||
| 5668 | } | ||
| 5669 | |||
| 5670 | } else { | ||
| 5671 | |||
| 5672 | # Unrecognised string | ||
| 5673 | return 0; | ||
| 5674 | } | ||
| 5675 | |||
| 5676 | # Return the number of matching objects (may be 0) | ||
| 5677 | return $count; | ||
| 5678 | } | ||
| 5679 | } | ||
| 5680 | } | ||
| 5681 | |||
| 5682 | { package Language::Axbasic::Function::Intrinsic::Numeric::ifacecount; | ||
| 5683 | |||
| 5684 | use strict; | ||
| 5685 | use warnings; | ||
| 5686 | # use diagnostics; | ||
| 5687 | |||
| 5688 | use Glib qw(TRUE FALSE); | ||
| 5689 | |||
| 5690 | @Language::Axbasic::Function::Intrinsic::Numeric::ifacecount::ISA = qw( | ||
| 5691 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5692 | ); | ||
| 5693 | |||
| 5694 | # Ifacecount () | ||
| 5695 | |||
| 5696 | ################## | ||
| 5697 | # Methods | ||
| 5698 | |||
| 5699 | sub evaluate { | ||
| 5700 | |||
| 5701 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5702 | # | ||
| 5703 | # Expected arguments | ||
| 5704 | # $arg - The first (and only) argument in the argument list | ||
| 5705 | # | ||
| 5706 | # Return values | ||
| 5707 | # The return value of the function | ||
| 5708 | |||
| 5709 | my ($self, $arg) = @_; | ||
| 5710 | |||
| 5711 | # (No improper arguments to check) | ||
| 5712 | |||
| 5713 | # Evaluate the function and return the value | ||
| 5714 | |||
| 5715 | # Return the number of LA::Notifications received and not yet processed | ||
| 5716 | return $self->scriptObj->ivNumber('notificationList'); | ||
| 5717 | } | ||
| 5718 | } | ||
| 5719 | |||
| 5720 | { package Language::Axbasic::Function::Intrinsic::Numeric::ifacedefined; | ||
| 5721 | |||
| 5722 | use strict; | ||
| 5723 | use warnings; | ||
| 5724 | # use diagnostics; | ||
| 5725 | |||
| 5726 | use Glib qw(TRUE FALSE); | ||
| 5727 | |||
| 5728 | @Language::Axbasic::Function::Intrinsic::Numeric::ifacedefined::ISA = qw( | ||
| 5729 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5730 | ); | ||
| 5731 | |||
| 5732 | # Ifacedefined (number) | ||
| 5733 | |||
| 5734 | ################## | ||
| 5735 | # Methods | ||
| 5736 | |||
| 5737 | sub evaluate { | ||
| 5738 | |||
| 5739 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5740 | # | ||
| 5741 | # Expected arguments | ||
| 5742 | # $arg - The first (and only) argument in the argument list | ||
| 5743 | # | ||
| 5744 | # Return values | ||
| 5745 | # The return value of the function | ||
| 5746 | |||
| 5747 | my ($self, $arg) = @_; | ||
| 5748 | |||
| 5749 | # Local variables | ||
| 5750 | my ($obj, $substr); | ||
| 5751 | |||
| 5752 | # (No improper arguments to check) | ||
| 5753 | |||
| 5754 | # Evaluate the function and return the value | ||
| 5755 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 5756 | |||
| 5757 | # The notification list is empty | ||
| 5758 | return 0; | ||
| 5759 | |||
| 5760 | } else { | ||
| 5761 | |||
| 5762 | # Get the current notification | ||
| 5763 | $obj = $self->scriptObj->ivIndex( | ||
| 5764 | 'notificationList', | ||
| 5765 | $self->scriptObj->currentNotification, | ||
| 5766 | ); | ||
| 5767 | |||
| 5768 | if (! $obj->dataList | ||
| 5769 | || $arg < 1 | ||
| 5770 | || $obj->ivNumber('dataList') > $arg | ||
| 5771 | ) { | ||
| 5772 | # No additional data to return | ||
| 5773 | return 0; | ||
| 5774 | |||
| 5775 | } else { | ||
| 5776 | |||
| 5777 | # For triggers and aliases, if a regex matching a line is in the form (...|...|...), | ||
| 5778 | # with each ... containing its own substrings, ->dataList will contain lots of | ||
| 5779 | # 'undef' values from the ... portions that didn't match the line | ||
| 5780 | # Return 1 if the specified argument is defined, and -1 if it is not defined | ||
| 5781 | $substr = $obj->ivIndex('dataList', ($arg - 1)); | ||
| 5782 | if (defined $substr) { | ||
| 5783 | return 1; | ||
| 5784 | } else { | ||
| 5785 | return -1; | ||
| 5786 | } | ||
| 5787 | } | ||
| 5788 | } | ||
| 5789 | } | ||
| 5790 | } | ||
| 5791 | |||
| 5792 | { package Language::Axbasic::Function::Intrinsic::Numeric::ifacenum; | ||
| 5793 | |||
| 5794 | use strict; | ||
| 5795 | use warnings; | ||
| 5796 | # use diagnostics; | ||
| 5797 | |||
| 5798 | use Glib qw(TRUE FALSE); | ||
| 5799 | |||
| 5800 | @Language::Axbasic::Function::Intrinsic::Numeric::ifacenum::ISA = qw( | ||
| 5801 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5802 | ); | ||
| 5803 | |||
| 5804 | # Ifacenum () | ||
| 5805 | |||
| 5806 | ################## | ||
| 5807 | # Methods | ||
| 5808 | |||
| 5809 | sub evaluate { | ||
| 5810 | |||
| 5811 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5812 | # | ||
| 5813 | # Expected arguments | ||
| 5814 | # $arg - The first (and only) argument in the argument list | ||
| 5815 | # | ||
| 5816 | # Return values | ||
| 5817 | # The return value of the function | ||
| 5818 | |||
| 5819 | my ($self, $arg) = @_; | ||
| 5820 | |||
| 5821 | # Local variables | ||
| 5822 | my $obj; | ||
| 5823 | |||
| 5824 | # (No improper arguments to check) | ||
| 5825 | |||
| 5826 | # Evaluate the function and return the value | ||
| 5827 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 5828 | |||
| 5829 | # The notification list is empty | ||
| 5830 | return -1; | ||
| 5831 | |||
| 5832 | } else { | ||
| 5833 | |||
| 5834 | # Get the current notification | ||
| 5835 | $obj = $self->scriptObj->ivIndex( | ||
| 5836 | 'notificationList', | ||
| 5837 | $self->scriptObj->currentNotification, | ||
| 5838 | ); | ||
| 5839 | |||
| 5840 | # Return its corresponding interface number | ||
| 5841 | return $obj->number; | ||
| 5842 | } | ||
| 5843 | } | ||
| 5844 | } | ||
| 5845 | |||
| 5846 | { package Language::Axbasic::Function::Intrinsic::Numeric::ifacepos; | ||
| 5847 | |||
| 5848 | use strict; | ||
| 5849 | use warnings; | ||
| 5850 | # use diagnostics; | ||
| 5851 | |||
| 5852 | use Glib qw(TRUE FALSE); | ||
| 5853 | |||
| 5854 | @Language::Axbasic::Function::Intrinsic::Numeric::ifacepos::ISA = qw( | ||
| 5855 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5856 | ); | ||
| 5857 | |||
| 5858 | # Ifacepos () | ||
| 5859 | |||
| 5860 | ################## | ||
| 5861 | # Methods | ||
| 5862 | |||
| 5863 | sub evaluate { | ||
| 5864 | |||
| 5865 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5866 | # | ||
| 5867 | # Expected arguments | ||
| 5868 | # $arg - The first (and only) argument in the argument list | ||
| 5869 | # | ||
| 5870 | # Return values | ||
| 5871 | # The return value of the function | ||
| 5872 | |||
| 5873 | my ($self, $arg) = @_; | ||
| 5874 | |||
| 5875 | # (No improper arguments to check) | ||
| 5876 | |||
| 5877 | # Evaluate the function and return the value | ||
| 5878 | |||
| 5879 | # Return the number of index of the current LA::Notification. Perl indexes start from 0, | ||
| 5880 | # but Axbasic indexes start from 1. (If the notification list is empty, | ||
| 5881 | # ->currentNotification is set to -1, and this function returns 0) | ||
| 5882 | return ($self->scriptObj->currentNotification + 1); | ||
| 5883 | } | ||
| 5884 | } | ||
| 5885 | |||
| 5886 | { package Language::Axbasic::Function::Intrinsic::Numeric::ifacestrings; | ||
| 5887 | |||
| 5888 | use strict; | ||
| 5889 | use warnings; | ||
| 5890 | # use diagnostics; | ||
| 5891 | |||
| 5892 | use Glib qw(TRUE FALSE); | ||
| 5893 | |||
| 5894 | @Language::Axbasic::Function::Intrinsic::Numeric::ifacestrings::ISA = qw( | ||
| 5895 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5896 | ); | ||
| 5897 | |||
| 5898 | # Ifacestrings () | ||
| 5899 | |||
| 5900 | ################## | ||
| 5901 | # Methods | ||
| 5902 | |||
| 5903 | sub evaluate { | ||
| 5904 | |||
| 5905 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5906 | # | ||
| 5907 | # Expected arguments | ||
| 5908 | # $arg - The first (and only) argument in the argument list | ||
| 5909 | # | ||
| 5910 | # Return values | ||
| 5911 | # The return value of the function | ||
| 5912 | |||
| 5913 | my ($self, $arg) = @_; | ||
| 5914 | |||
| 5915 | # Local variables | ||
| 5916 | my $obj; | ||
| 5917 | |||
| 5918 | # (No improper arguments to check) | ||
| 5919 | |||
| 5920 | # Evaluate the function and return the value | ||
| 5921 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 5922 | |||
| 5923 | # The notification list is empty | ||
| 5924 | return 0; | ||
| 5925 | |||
| 5926 | } else { | ||
| 5927 | |||
| 5928 | # Get the current notification | ||
| 5929 | $obj = $self->scriptObj->ivIndex( | ||
| 5930 | 'notificationList', | ||
| 5931 | $self->scriptObj->currentNotification, | ||
| 5932 | ); | ||
| 5933 | |||
| 5934 | # Return the number of group substrings stored in it | ||
| 5935 | return $obj->ivNumber('dataList'); | ||
| 5936 | } | ||
| 5937 | } | ||
| 5938 | } | ||
| 5939 | |||
| 5940 | { package Language::Axbasic::Function::Intrinsic::Numeric::ifacetime; | ||
| 5941 | |||
| 5942 | use strict; | ||
| 5943 | use warnings; | ||
| 5944 | # use diagnostics; | ||
| 5945 | |||
| 5946 | use Glib qw(TRUE FALSE); | ||
| 5947 | |||
| 5948 | @Language::Axbasic::Function::Intrinsic::Numeric::ifacetime::ISA = qw( | ||
| 5949 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 5950 | ); | ||
| 5951 | |||
| 5952 | # Ifacetime () | ||
| 5953 | |||
| 5954 | ################## | ||
| 5955 | # Methods | ||
| 5956 | |||
| 5957 | sub evaluate { | ||
| 5958 | |||
| 5959 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 5960 | # | ||
| 5961 | # Expected arguments | ||
| 5962 | # $arg - The first (and only) argument in the argument list | ||
| 5963 | # | ||
| 5964 | # Return values | ||
| 5965 | # The return value of the function | ||
| 5966 | |||
| 5967 | my ($self, $arg) = @_; | ||
| 5968 | |||
| 5969 | # Local variables | ||
| 5970 | my $obj; | ||
| 5971 | |||
| 5972 | # (No improper arguments to check) | ||
| 5973 | |||
| 5974 | # Evaluate the function and return the value | ||
| 5975 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 5976 | |||
| 5977 | # The notification list is empty | ||
| 5978 | return -1; | ||
| 5979 | |||
| 5980 | } else { | ||
| 5981 | |||
| 5982 | # Get the current notification | ||
| 5983 | $obj = $self->scriptObj->ivIndex( | ||
| 5984 | 'notificationList', | ||
| 5985 | $self->scriptObj->currentNotification, | ||
| 5986 | ); | ||
| 5987 | |||
| 5988 | # Return the time it was received | ||
| 5989 | return $obj->time; | ||
| 5990 | } | ||
| 5991 | } | ||
| 5992 | } | ||
| 5993 | |||
| 5994 | { package Language::Axbasic::Function::Intrinsic::Numeric::isexit; | ||
| 5995 | |||
| 5996 | use strict; | ||
| 5997 | use warnings; | ||
| 5998 | # use diagnostics; | ||
| 5999 | |||
| 6000 | use Glib qw(TRUE FALSE); | ||
| 6001 | |||
| 6002 | @Language::Axbasic::Function::Intrinsic::Numeric::isexit::ISA = qw( | ||
| 6003 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6004 | ); | ||
| 6005 | |||
| 6006 | # Isexit (number) | ||
| 6007 | |||
| 6008 | ################## | ||
| 6009 | # Methods | ||
| 6010 | |||
| 6011 | sub evaluate { | ||
| 6012 | |||
| 6013 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 6014 | # | ||
| 6015 | # Expected arguments | ||
| 6016 | # $arg - The first (and only) argument in the argument list | ||
| 6017 | # | ||
| 6018 | # Return values | ||
| 6019 | # The return value of the function | ||
| 6020 | |||
| 6021 | my ($self, $arg) = @_; | ||
| 6022 | |||
| 6023 | # Local variables | ||
| 6024 | my ($wmObj, $exitObj); | ||
| 6025 | |||
| 6026 | # (No improper arguments to check) | ||
| 6027 | |||
| 6028 | # Evaluate the function and return the value | ||
| 6029 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6030 | |||
| 6031 | # Find the specified room | ||
| 6032 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 6033 | if (! defined $exitObj) { | ||
| 6034 | return 0; | ||
| 6035 | } else { | ||
| 6036 | return 1; | ||
| 6037 | } | ||
| 6038 | } | ||
| 6039 | } | ||
| 6040 | |||
| 6041 | { package Language::Axbasic::Function::Intrinsic::Numeric::isfinished; | ||
| 6042 | |||
| 6043 | use strict; | ||
| 6044 | use warnings; | ||
| 6045 | # use diagnostics; | ||
| 6046 | |||
| 6047 | use Glib qw(TRUE FALSE); | ||
| 6048 | |||
| 6049 | @Language::Axbasic::Function::Intrinsic::Numeric::isfinished::ISA = qw( | ||
| 6050 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6051 | ); | ||
| 6052 | |||
| 6053 | # Isfinished (string) | ||
| 6054 | |||
| 6055 | ################## | ||
| 6056 | # Methods | ||
| 6057 | |||
| 6058 | sub evaluate { | ||
| 6059 | |||
| 6060 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 6061 | # | ||
| 6062 | # Expected arguments | ||
| 6063 | # $arg - The first (and only) argument in the argument list | ||
| 6064 | # | ||
| 6065 | # Return values | ||
| 6066 | # The return value of the function | ||
| 6067 | |||
| 6068 | my ($self, $arg) = @_; | ||
| 6069 | |||
| 6070 | # Local variables | ||
| 6071 | my ($wmObj, $regionmapObj, $regionObj); | ||
| 6072 | |||
| 6073 | # (No improper arguments to check) | ||
| 6074 | |||
| 6075 | # Evaluate the function and return the value | ||
| 6076 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6077 | |||
| 6078 | # Find the specified region | ||
| 6079 | $regionmapObj = $wmObj->ivShow('regionmapHash', $arg); | ||
| 6080 | if (! defined $regionmapObj) { | ||
| 6081 | |||
| 6082 | return 0; | ||
| 6083 | } | ||
| 6084 | |||
| 6085 | $regionObj = $wmObj->ivShow('regionModelHash', $regionmapObj->number); | ||
| 6086 | if (! defined $regionObj || ! $regionObj->finishedFlag) { | ||
| 6087 | return 0; | ||
| 6088 | } else { | ||
| 6089 | return 1; | ||
| 6090 | } | ||
| 6091 | } | ||
| 6092 | } | ||
| 6093 | |||
| 6094 | { package Language::Axbasic::Function::Intrinsic::Numeric::ishiddenexit; | ||
| 6095 | |||
| 6096 | use strict; | ||
| 6097 | use warnings; | ||
| 6098 | # use diagnostics; | ||
| 6099 | |||
| 6100 | use Glib qw(TRUE FALSE); | ||
| 6101 | |||
| 6102 | @Language::Axbasic::Function::Intrinsic::Numeric::ishiddenexit::ISA = qw( | ||
| 6103 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6104 | ); | ||
| 6105 | |||
| 6106 | # Ishiddenexit (number) | ||
| 6107 | |||
| 6108 | ################## | ||
| 6109 | # Methods | ||
| 6110 | |||
| 6111 | sub evaluate { | ||
| 6112 | |||
| 6113 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 6114 | # | ||
| 6115 | # Expected arguments | ||
| 6116 | # $arg - The first (and only) argument in the argument list | ||
| 6117 | # | ||
| 6118 | # Return values | ||
| 6119 | # The return value of the function | ||
| 6120 | |||
| 6121 | my ($self, $arg) = @_; | ||
| 6122 | |||
| 6123 | # Local variables | ||
| 6124 | my ($wmObj, $exitObj); | ||
| 6125 | |||
| 6126 | # (No improper arguments to check) | ||
| 6127 | |||
| 6128 | # Evaluate the function and return the value | ||
| 6129 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6130 | |||
| 6131 | # Find the specified exit | ||
| 6132 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 6133 | if (! defined $exitObj) { | ||
| 6134 | |||
| 6135 | return 0; | ||
| 6136 | } | ||
| 6137 | |||
| 6138 | # Return the exit's status | ||
| 6139 | if (! $exitObj->hiddenFlag) { | ||
| 6140 | return 0; | ||
| 6141 | } else { | ||
| 6142 | return 1; | ||
| 6143 | } | ||
| 6144 | } | ||
| 6145 | } | ||
| 6146 | |||
| 6147 | { package Language::Axbasic::Function::Intrinsic::Numeric::isregion; | ||
| 6148 | |||
| 6149 | use strict; | ||
| 6150 | use warnings; | ||
| 6151 | # use diagnostics; | ||
| 6152 | |||
| 6153 | use Glib qw(TRUE FALSE); | ||
| 6154 | |||
| 6155 | @Language::Axbasic::Function::Intrinsic::Numeric::isregion::ISA = qw( | ||
| 6156 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6157 | ); | ||
| 6158 | |||
| 6159 | # Isregion (string) | ||
| 6160 | |||
| 6161 | ################## | ||
| 6162 | # Methods | ||
| 6163 | |||
| 6164 | sub evaluate { | ||
| 6165 | |||
| 6166 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 6167 | # | ||
| 6168 | # Expected arguments | ||
| 6169 | # $arg - The first (and only) argument in the argument list | ||
| 6170 | # | ||
| 6171 | # Return values | ||
| 6172 | # The return value of the function | ||
| 6173 | |||
| 6174 | my ($self, $arg) = @_; | ||
| 6175 | |||
| 6176 | # Local variables | ||
| 6177 | my ($wmObj, $regionmapObj); | ||
| 6178 | |||
| 6179 | # (No improper arguments to check) | ||
| 6180 | |||
| 6181 | # Evaluate the function and return the value | ||
| 6182 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6183 | |||
| 6184 | # Find the specified region | ||
| 6185 | $regionmapObj = $wmObj->ivShow('regionmapHash', $arg); | ||
| 6186 | if (! defined $regionmapObj) { | ||
| 6187 | return 0; | ||
| 6188 | } else { | ||
| 6189 | return 1; | ||
| 6190 | } | ||
| 6191 | } | ||
| 6192 | } | ||
| 6193 | |||
| 6194 | { package Language::Axbasic::Function::Intrinsic::Numeric::isroom; | ||
| 6195 | |||
| 6196 | use strict; | ||
| 6197 | use warnings; | ||
| 6198 | # use diagnostics; | ||
| 6199 | |||
| 6200 | use Glib qw(TRUE FALSE); | ||
| 6201 | |||
| 6202 | @Language::Axbasic::Function::Intrinsic::Numeric::isroom::ISA = qw( | ||
| 6203 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6204 | ); | ||
| 6205 | |||
| 6206 | # Isroom (number) | ||
| 6207 | |||
| 6208 | ################## | ||
| 6209 | # Methods | ||
| 6210 | |||
| 6211 | sub evaluate { | ||
| 6212 | |||
| 6213 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 6214 | # | ||
| 6215 | # Expected arguments | ||
| 6216 | # $arg - The first (and only) argument in the argument list | ||
| 6217 | # | ||
| 6218 | # Return values | ||
| 6219 | # The return value of the function | ||
| 6220 | |||
| 6221 | my ($self, $arg) = @_; | ||
| 6222 | |||
| 6223 | # Local variables | ||
| 6224 | my ($wmObj, $roomObj); | ||
| 6225 | |||
| 6226 | # (No improper arguments to check) | ||
| 6227 | |||
| 6228 | # Evaluate the function and return the value | ||
| 6229 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6230 | |||
| 6231 | # Find the specified room | ||
| 6232 | $roomObj = $wmObj->ivShow('roomModelHash', $arg); | ||
| 6233 | if (! defined $roomObj) { | ||
| 6234 | return 0; | ||
| 6235 | } else { | ||
| 6236 | return 1; | ||
| 6237 | } | ||
| 6238 | } | ||
| 6239 | } | ||
| 6240 | |||
| 6241 | { package Language::Axbasic::Function::Intrinsic::Numeric::ismap; | ||
| 6242 | |||
| 6243 | use strict; | ||
| 6244 | use warnings; | ||
| 6245 | # use diagnostics; | ||
| 6246 | |||
| 6247 | use Glib qw(TRUE FALSE); | ||
| 6248 | |||
| 6249 | @Language::Axbasic::Function::Intrinsic::Numeric::ismap::ISA = qw( | ||
| 6250 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6251 | ); | ||
| 6252 | |||
| 6253 | # Ismap | ||
| 6254 | |||
| 6255 | ################## | ||
| 6256 | # Methods | ||
| 6257 | |||
| 6258 | sub evaluate { | ||
| 6259 | |||
| 6260 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 6261 | # | ||
| 6262 | # Expected arguments | ||
| 6263 | # $arg - The first (and only) argument in the argument list | ||
| 6264 | # | ||
| 6265 | # Return values | ||
| 6266 | # The return value of the function | ||
| 6267 | |||
| 6268 | my ($self, $arg) = @_; | ||
| 6269 | |||
| 6270 | # (No improper arguments to check) | ||
| 6271 | |||
| 6272 | # Evaluate the function and return the value | ||
| 6273 | |||
| 6274 | # Test whether the Automapper window is open | ||
| 6275 | if (! $self->scriptObj->session->mapWin) { | ||
| 6276 | |||
| 6277 | # Window not open | ||
| 6278 | return 0; | ||
| 6279 | |||
| 6280 | } else { | ||
| 6281 | |||
| 6282 | # Window open | ||
| 6283 | return 1; | ||
| 6284 | } | ||
| 6285 | } | ||
| 6286 | } | ||
| 6287 | |||
| 6288 | { package Language::Axbasic::Function::Intrinsic::Numeric::isscript; | ||
| 6289 | |||
| 6290 | use strict; | ||
| 6291 | use warnings; | ||
| 6292 | # use diagnostics; | ||
| 6293 | |||
| 6294 | use Glib qw(TRUE FALSE); | ||
| 6295 | |||
| 6296 | @Language::Axbasic::Function::Intrinsic::Numeric::isscript::ISA = qw( | ||
| 6297 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6298 | ); | ||
| 6299 | |||
| 6300 | # Isscript (string) | ||
| 6301 | |||
| 6302 | ################## | ||
| 6303 | # Methods | ||
| 6304 | |||
| 6305 | sub evaluate { | ||
| 6306 | |||
| 6307 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 6308 | # | ||
| 6309 | # Expected arguments | ||
| 6310 | # $arg - The first (and only) argument in the argument list | ||
| 6311 | # | ||
| 6312 | # Return values | ||
| 6313 | # The return value of the function | ||
| 6314 | |||
| 6315 | my ($self, $arg) = @_; | ||
| 6316 | |||
| 6317 | # Local variables | ||
| 6318 | my @list; | ||
| 6319 | |||
| 6320 | # (No improper arguments to check) | ||
| 6321 | |||
| 6322 | # Evaluate the function and return the value | ||
| 6323 | |||
| 6324 | # Get a list of currently-running Script tasks | ||
| 6325 | @list = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, 'script_task'); | ||
| 6326 | foreach my $taskObj (@list) { | ||
| 6327 | |||
| 6328 | # If this task is running a script called $arg, return 1 | ||
| 6329 | if ($taskObj->scriptName eq $arg) { | ||
| 6330 | |||
| 6331 | return 1; | ||
| 6332 | } | ||
| 6333 | } | ||
| 6334 | |||
| 6335 | # No Script tasks running scripts called $arg | ||
| 6336 | return 0; | ||
| 6337 | } | ||
| 6338 | } | ||
| 6339 | |||
| 6340 | { package Language::Axbasic::Function::Intrinsic::Numeric::istask; | ||
| 6341 | |||
| 6342 | use strict; | ||
| 6343 | use warnings; | ||
| 6344 | # use diagnostics; | ||
| 6345 | |||
| 6346 | use Glib qw(TRUE FALSE); | ||
| 6347 | |||
| 6348 | @Language::Axbasic::Function::Intrinsic::Numeric::istask::ISA = qw( | ||
| 6349 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6350 | ); | ||
| 6351 | |||
| 6352 | # Istask () | ||
| 6353 | |||
| 6354 | ################## | ||
| 6355 | # Methods | ||
| 6356 | |||
| 6357 | sub evaluate { | ||
| 6358 | |||
| 6359 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 6360 | # | ||
| 6361 | # Expected arguments | ||
| 6362 | # $arg - The first (and only) argument in the argument list | ||
| 6363 | # | ||
| 6364 | # Return values | ||
| 6365 | # The return value of the function | ||
| 6366 | |||
| 6367 | my ($self, $arg) = @_; | ||
| 6368 | |||
| 6369 | # (No improper arguments to check) | ||
| 6370 | |||
| 6371 | # Evaluate the function and return the value | ||
| 6372 | |||
| 6373 | # Test whether the script is being run by a task | ||
| 6374 | if ($self->scriptObj->parentTask) { | ||
| 6375 | |||
| 6376 | # Window open | ||
| 6377 | return 1; | ||
| 6378 | |||
| 6379 | } else { | ||
| 6380 | |||
| 6381 | # Window not open | ||
| 6382 | return 0; | ||
| 6383 | } | ||
| 6384 | } | ||
| 6385 | } | ||
| 6386 | |||
| 6387 | { package Language::Axbasic::Function::Intrinsic::Numeric::istempregion; | ||
| 6388 | |||
| 6389 | use strict; | ||
| 6390 | use warnings; | ||
| 6391 | # use diagnostics; | ||
| 6392 | |||
| 6393 | use Glib qw(TRUE FALSE); | ||
| 6394 | |||
| 6395 | @Language::Axbasic::Function::Intrinsic::Numeric::istempregion::ISA = qw( | ||
| 6396 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6397 | ); | ||
| 6398 | |||
| 6399 | # Istempregion (string) | ||
| 6400 | |||
| 6401 | ################## | ||
| 6402 | # Methods | ||
| 6403 | |||
| 6404 | sub evaluate { | ||
| 6405 | |||
| 6406 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 6407 | # | ||
| 6408 | # Expected arguments | ||
| 6409 | # $arg - The first (and only) argument in the argument list | ||
| 6410 | # | ||
| 6411 | # Return values | ||
| 6412 | # The return value of the function | ||
| 6413 | |||
| 6414 | my ($self, $arg) = @_; | ||
| 6415 | |||
| 6416 | # Local variables | ||
| 6417 | my ($wmObj, $regionmapObj, $regionObj); | ||
| 6418 | |||
| 6419 | # (No improper arguments to check) | ||
| 6420 | |||
| 6421 | # Evaluate the function and return the value | ||
| 6422 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6423 | |||
| 6424 | # Find the specified region | ||
| 6425 | $regionmapObj = $wmObj->ivShow('regionmapHash', $arg); | ||
| 6426 | if (! defined $regionmapObj) { | ||
| 6427 | |||
| 6428 | return 0; | ||
| 6429 | } | ||
| 6430 | |||
| 6431 | $regionObj = $wmObj->ivShow('regionModelHash', $regionmapObj->number); | ||
| 6432 | if (! defined $regionObj || ! $regionObj->tempRegionFlag) { | ||
| 6433 | return 0; | ||
| 6434 | } else { | ||
| 6435 | return 1; | ||
| 6436 | } | ||
| 6437 | } | ||
| 6438 | } | ||
| 6439 | |||
| 6440 | { package Language::Axbasic::Function::Intrinsic::Numeric::iswin; | ||
| 6441 | |||
| 6442 | use strict; | ||
| 6443 | use warnings; | ||
| 6444 | # use diagnostics; | ||
| 6445 | |||
| 6446 | use Glib qw(TRUE FALSE); | ||
| 6447 | |||
| 6448 | @Language::Axbasic::Function::Intrinsic::Numeric::iswin::ISA = qw( | ||
| 6449 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6450 | ); | ||
| 6451 | |||
| 6452 | # Iswin () | ||
| 6453 | |||
| 6454 | ################## | ||
| 6455 | # Methods | ||
| 6456 | |||
| 6457 | sub evaluate { | ||
| 6458 | |||
| 6459 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 6460 | # | ||
| 6461 | # Expected arguments | ||
| 6462 | # $arg - The first (and only) argument in the argument list | ||
| 6463 | # | ||
| 6464 | # Return values | ||
| 6465 | # The return value of the function | ||
| 6466 | |||
| 6467 | my ($self, $arg) = @_; | ||
| 6468 | |||
| 6469 | # (No improper arguments to check) | ||
| 6470 | |||
| 6471 | # Evaluate the function and return the value | ||
| 6472 | |||
| 6473 | # Test whether the script is being run by a task and, if so, the task window is open | ||
| 6474 | if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) { | ||
| 6475 | |||
| 6476 | # Window open | ||
| 6477 | return 1; | ||
| 6478 | |||
| 6479 | } else { | ||
| 6480 | |||
| 6481 | # Window not open | ||
| 6482 | return 0; | ||
| 6483 | } | ||
| 6484 | } | ||
| 6485 | } | ||
| 6486 | |||
| 6487 | { package Language::Axbasic::Function::Intrinsic::Numeric::openmap; | ||
| 6488 | |||
| 6489 | use strict; | ||
| 6490 | use warnings; | ||
| 6491 | # use diagnostics; | ||
| 6492 | |||
| 6493 | use Glib qw(TRUE FALSE); | ||
| 6494 | |||
| 6495 | @Language::Axbasic::Function::Intrinsic::Numeric::openmap::ISA = qw( | ||
| 6496 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6497 | ); | ||
| 6498 | |||
| 6499 | # Openmap () | ||
| 6500 | |||
| 6501 | ################## | ||
| 6502 | # Methods | ||
| 6503 | |||
| 6504 | sub evaluate { | ||
| 6505 | |||
| 6506 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 6507 | # | ||
| 6508 | # Expected arguments | ||
| 6509 | # $arg - The first (and only) argument in the argument list | ||
| 6510 | # | ||
| 6511 | # Return values | ||
| 6512 | # The return value of the function | ||
| 6513 | |||
| 6514 | my ($self, $arg) = @_; | ||
| 6515 | |||
| 6516 | # (No improper arguments to check) | ||
| 6517 | |||
| 6518 | # Evaluate the function and return the value | ||
| 6519 | if ($self->scriptObj->session->mapWin) { | ||
| 6520 | |||
| 6521 | # The window is already open | ||
| 6522 | return 1; | ||
| 6523 | |||
| 6524 | } else { | ||
| 6525 | |||
| 6526 | # Try to open the window | ||
| 6527 | $self->scriptObj->session->mapObj->openWin(); | ||
| 6528 | if ($self->scriptObj->session->mapWin) { | ||
| 6529 | |||
| 6530 | # Window opened successfully | ||
| 6531 | return 1; | ||
| 6532 | |||
| 6533 | } else { | ||
| 6534 | |||
| 6535 | # Could not open window | ||
| 6536 | return 0; | ||
| 6537 | } | ||
| 6538 | } | ||
| 6539 | } | ||
| 6540 | } | ||
| 6541 | |||
| 6542 | { package Language::Axbasic::Function::Intrinsic::Numeric::sethiddenexit; | ||
| 6543 | |||
| 6544 | use strict; | ||
| 6545 | use warnings; | ||
| 6546 | # use diagnostics; | ||
| 6547 | |||
| 6548 | use Glib qw(TRUE FALSE); | ||
| 6549 | |||
| 6550 | @Language::Axbasic::Function::Intrinsic::Numeric::sethiddenexit::ISA = qw( | ||
| 6551 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6552 | ); | ||
| 6553 | |||
| 6554 | # Sethiddenexit (number) | ||
| 6555 | |||
| 6556 | ################## | ||
| 6557 | # Methods | ||
| 6558 | |||
| 6559 | sub evaluate { | ||
| 6560 | |||
| 6561 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 6562 | # | ||
| 6563 | # Expected arguments | ||
| 6564 | # $arg - The first (and only) argument in the argument list | ||
| 6565 | # | ||
| 6566 | # Return values | ||
| 6567 | # The return value of the function | ||
| 6568 | |||
| 6569 | my ($self, $arg) = @_; | ||
| 6570 | |||
| 6571 | # Local variables | ||
| 6572 | my ($wmObj, $exitObj); | ||
| 6573 | |||
| 6574 | # (No improper arguments to check) | ||
| 6575 | |||
| 6576 | # Evaluate the function and return the value | ||
| 6577 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6578 | |||
| 6579 | # Find the specified exit | ||
| 6580 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 6581 | if (! defined $exitObj) { | ||
| 6582 | |||
| 6583 | return 0; | ||
| 6584 | } | ||
| 6585 | |||
| 6586 | # Toggle the exit's hidden status | ||
| 6587 | if ( | ||
| 6588 | ! $wmObj->setHiddenExit( | ||
| 6589 | TRUE, # Update Automapper windows now | ||
| 6590 | $exitObj, | ||
| 6591 | ! $exitObj->hiddenFlag, | ||
| 6592 | ) | ||
| 6593 | ) { | ||
| 6594 | return 0; | ||
| 6595 | } else { | ||
| 6596 | return 1; | ||
| 6597 | } | ||
| 6598 | } | ||
| 6599 | } | ||
| 6600 | |||
| 6601 | { package Language::Axbasic::Function::Intrinsic::Numeric::setlight; | ||
| 6602 | |||
| 6603 | use strict; | ||
| 6604 | use warnings; | ||
| 6605 | # use diagnostics; | ||
| 6606 | |||
| 6607 | use Glib qw(TRUE FALSE); | ||
| 6608 | |||
| 6609 | @Language::Axbasic::Function::Intrinsic::Numeric::setlight::ISA = qw( | ||
| 6610 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6611 | ); | ||
| 6612 | |||
| 6613 | # Setlight (string) | ||
| 6614 | |||
| 6615 | ################## | ||
| 6616 | # Methods | ||
| 6617 | |||
| 6618 | sub evaluate { | ||
| 6619 | |||
| 6620 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 6621 | # | ||
| 6622 | # Expected arguments | ||
| 6623 | # $arg - The first (and only) argument in the argument list | ||
| 6624 | # | ||
| 6625 | # Return values | ||
| 6626 | # The return value of the function | ||
| 6627 | |||
| 6628 | my ($self, $arg) = @_; | ||
| 6629 | |||
| 6630 | # Local variables | ||
| 6631 | my $wmObj; | ||
| 6632 | |||
| 6633 | # (No improper arguments to check) | ||
| 6634 | |||
| 6635 | # Evaluate the function and return the value | ||
| 6636 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6637 | |||
| 6638 | # Set the light status | ||
| 6639 | $wmObj->set_lightStatus($arg); | ||
| 6640 | if ($wmObj->lightStatus ne $arg) { | ||
| 6641 | |||
| 6642 | # Operation failed | ||
| 6643 | return 0; | ||
| 6644 | |||
| 6645 | } else { | ||
| 6646 | |||
| 6647 | # Operation succeeded | ||
| 6648 | return 1; | ||
| 6649 | } | ||
| 6650 | } | ||
| 6651 | } | ||
| 6652 | |||
| 6653 | { package Language::Axbasic::Function::Intrinsic::Numeric::setmapmode; | ||
| 6654 | |||
| 6655 | use strict; | ||
| 6656 | use warnings; | ||
| 6657 | # use diagnostics; | ||
| 6658 | |||
| 6659 | use Glib qw(TRUE FALSE); | ||
| 6660 | |||
| 6661 | @Language::Axbasic::Function::Intrinsic::Numeric::setmapmode::ISA = qw( | ||
| 6662 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6663 | ); | ||
| 6664 | |||
| 6665 | # Setmapmode (string) | ||
| 6666 | |||
| 6667 | ################## | ||
| 6668 | # Methods | ||
| 6669 | |||
| 6670 | sub evaluate { | ||
| 6671 | |||
| 6672 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 6673 | # | ||
| 6674 | # Expected arguments | ||
| 6675 | # $arg - The first (and only) argument in the argument list | ||
| 6676 | # | ||
| 6677 | # Return values | ||
| 6678 | # The return value of the function | ||
| 6679 | |||
| 6680 | my ($self, $arg) = @_; | ||
| 6681 | |||
| 6682 | # Local variables | ||
| 6683 | my $mapWin; | ||
| 6684 | |||
| 6685 | # (No improper arguments to check) | ||
| 6686 | |||
| 6687 | # Evaluate the function and return the value | ||
| 6688 | |||
| 6689 | # Check that the Automapper window is open, and that a recognised string has been used | ||
| 6690 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 6691 | |||
| 6692 | if (! $mapWin || ($arg ne 'wait' && $arg ne 'follow' && $arg ne 'update')) { | ||
| 6693 | |||
| 6694 | return 0; | ||
| 6695 | |||
| 6696 | } else { | ||
| 6697 | |||
| 6698 | # Make sure that the specified mode is in its lower-case form | ||
| 6699 | $arg = lc($arg); | ||
| 6700 | # Try to set the current mode | ||
| 6701 | $mapWin->setMode($arg); | ||
| 6702 | |||
| 6703 | # See if the mode was correctly set | ||
| 6704 | if ($mapWin->mode eq $arg) { | ||
| 6705 | |||
| 6706 | # Mode correctly set, or mode was already set | ||
| 6707 | return 1; | ||
| 6708 | |||
| 6709 | } else { | ||
| 6710 | |||
| 6711 | # Mode not set | ||
| 6712 | return 0; | ||
| 6713 | } | ||
| 6714 | } | ||
| 6715 | } | ||
| 6716 | } | ||
| 6717 | |||
| 6718 | { package Language::Axbasic::Function::Intrinsic::Numeric::setornament; | ||
| 6719 | |||
| 6720 | use strict; | ||
| 6721 | use warnings; | ||
| 6722 | # use diagnostics; | ||
| 6723 | |||
| 6724 | use Glib qw(TRUE FALSE); | ||
| 6725 | |||
| 6726 | @Language::Axbasic::Function::Intrinsic::Numeric::setornament::ISA = qw( | ||
| 6727 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6728 | ); | ||
| 6729 | |||
| 6730 | # Setornament (number) | ||
| 6731 | # Setornament (number, string) | ||
| 6732 | |||
| 6733 | ################## | ||
| 6734 | # Methods | ||
| 6735 | |||
| 6736 | sub evaluate { | ||
| 6737 | |||
| 6738 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N;S') | ||
| 6739 | # | ||
| 6740 | # Expected arguments | ||
| 6741 | # @args - The list of arguments supplied to the function | ||
| 6742 | # | ||
| 6743 | # Return values | ||
| 6744 | # The return value of the function | ||
| 6745 | |||
| 6746 | my ($self, @args) = @_; | ||
| 6747 | |||
| 6748 | # Local variables | ||
| 6749 | my ($wmObj, $exitNum, $type, $exitObj); | ||
| 6750 | |||
| 6751 | # (No improper arguments to check) | ||
| 6752 | |||
| 6753 | # Evaluate the function and return the value | ||
| 6754 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6755 | |||
| 6756 | $exitNum = $args[0]; | ||
| 6757 | $type = $args[1]; | ||
| 6758 | |||
| 6759 | if (! defined $type) { | ||
| 6760 | $type = 'none'; | ||
| 6761 | } elsif ( | ||
| 6762 | $type ne 'break' | ||
| 6763 | && $type ne 'pick' | ||
| 6764 | && $type ne 'lock' | ||
| 6765 | && $type ne 'open' | ||
| 6766 | && $type ne 'impass' | ||
| 6767 | && $type ne 'mystery' | ||
| 6768 | ) { | ||
| 6769 | return 0; | ||
| 6770 | } | ||
| 6771 | |||
| 6772 | # Find the specified exit | ||
| 6773 | $exitObj = $wmObj->ivShow('exitModelHash', $exitNum); | ||
| 6774 | if (! defined $exitObj) { | ||
| 6775 | |||
| 6776 | return 0; | ||
| 6777 | } | ||
| 6778 | |||
| 6779 | # Set (or reset) the exit ornament | ||
| 6780 | if ( | ||
| 6781 | ! $wmObj->setExitOrnament( | ||
| 6782 | TRUE, # Update Automapper windows now | ||
| 6783 | $exitObj, | ||
| 6784 | $type, | ||
| 6785 | TRUE, # Set twin as well | ||
| 6786 | ) | ||
| 6787 | ) { | ||
| 6788 | return 0; | ||
| 6789 | } else { | ||
| 6790 | return 1; | ||
| 6791 | } | ||
| 6792 | } | ||
| 6793 | } | ||
| 6794 | |||
| 6795 | { package Language::Axbasic::Function::Intrinsic::Numeric::setrandomexit; | ||
| 6796 | |||
| 6797 | use strict; | ||
| 6798 | use warnings; | ||
| 6799 | # use diagnostics; | ||
| 6800 | |||
| 6801 | use Glib qw(TRUE FALSE); | ||
| 6802 | |||
| 6803 | @Language::Axbasic::Function::Intrinsic::Numeric::setrandomexit::ISA = qw( | ||
| 6804 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6805 | ); | ||
| 6806 | |||
| 6807 | # Setrandomexit (number) | ||
| 6808 | # Setrandomexit (number, string) | ||
| 6809 | |||
| 6810 | ################## | ||
| 6811 | # Methods | ||
| 6812 | |||
| 6813 | sub evaluate { | ||
| 6814 | |||
| 6815 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N;S') | ||
| 6816 | # | ||
| 6817 | # Expected arguments | ||
| 6818 | # @args - The list of arguments supplied to the function | ||
| 6819 | # | ||
| 6820 | # Return values | ||
| 6821 | # The return value of the function | ||
| 6822 | |||
| 6823 | my ($self, @args) = @_; | ||
| 6824 | |||
| 6825 | # Local variables | ||
| 6826 | my ($wmObj, $exitNum, $type, $exitObj); | ||
| 6827 | |||
| 6828 | # (No improper arguments to check) | ||
| 6829 | |||
| 6830 | # Evaluate the function and return the value | ||
| 6831 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 6832 | |||
| 6833 | $exitNum = $args[0]; | ||
| 6834 | $type = $args[1]; | ||
| 6835 | |||
| 6836 | if (defined $type && $type ne 'same' && $type ne 'any' && $type ne 'temp') { | ||
| 6837 | return 0; | ||
| 6838 | } | ||
| 6839 | |||
| 6840 | # Find the specified exit | ||
| 6841 | $exitObj = $wmObj->ivShow('exitModelHash', $exitNum); | ||
| 6842 | if (! defined $exitObj) { | ||
| 6843 | |||
| 6844 | return 0; | ||
| 6845 | } | ||
| 6846 | |||
| 6847 | # Set (or reset) the random exit | ||
| 6848 | if (! defined $type) { | ||
| 6849 | |||
| 6850 | if ( | ||
| 6851 | ! $wmObj->restoreRandomExit( | ||
| 6852 | TRUE, # Update Automapper windows now | ||
| 6853 | $exitObj, | ||
| 6854 | ) | ||
| 6855 | ) { | ||
| 6856 | return 0; | ||
| 6857 | } else { | ||
| 6858 | return 1; | ||
| 6859 | } | ||
| 6860 | |||
| 6861 | } else { | ||
| 6862 | |||
| 6863 | if ( | ||
| 6864 | ! $wmObj->setRandomExit( | ||
| 6865 | TRUE, # Update Automapper windows now | ||
| 6866 | $exitObj, | ||
| 6867 | $type . '_region', # e.g. 'same_region' | ||
| 6868 | ) | ||
| 6869 | ) { | ||
| 6870 | return 0; | ||
| 6871 | } else { | ||
| 6872 | return 1; | ||
| 6873 | } | ||
| 6874 | } | ||
| 6875 | } | ||
| 6876 | } | ||
| 6877 | |||
| 6878 | { package Language::Axbasic::Function::Intrinsic::Numeric::setregion; | ||
| 6879 | |||
| 6880 | use strict; | ||
| 6881 | use warnings; | ||
| 6882 | # use diagnostics; | ||
| 6883 | |||
| 6884 | use Glib qw(TRUE FALSE); | ||
| 6885 | |||
| 6886 | @Language::Axbasic::Function::Intrinsic::Numeric::setregion::ISA = qw( | ||
| 6887 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6888 | ); | ||
| 6889 | |||
| 6890 | # Setregion (string) | ||
| 6891 | |||
| 6892 | ################## | ||
| 6893 | # Methods | ||
| 6894 | |||
| 6895 | sub evaluate { | ||
| 6896 | |||
| 6897 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 6898 | # | ||
| 6899 | # Expected arguments | ||
| 6900 | # $arg - The first (and only) argument in the argument list | ||
| 6901 | # | ||
| 6902 | # Return values | ||
| 6903 | # The return value of the function | ||
| 6904 | |||
| 6905 | my ($self, $arg) = @_; | ||
| 6906 | |||
| 6907 | # Local variables | ||
| 6908 | my $mapWin; | ||
| 6909 | |||
| 6910 | # (No improper arguments to check) | ||
| 6911 | |||
| 6912 | # Evaluate the function and return the value | ||
| 6913 | |||
| 6914 | # Check that the Automapper window is open | ||
| 6915 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 6916 | if (! $mapWin) { | ||
| 6917 | |||
| 6918 | return 0; | ||
| 6919 | |||
| 6920 | } else { | ||
| 6921 | |||
| 6922 | # Set the current region. Return 1 on success, 0 on failure | ||
| 6923 | if (! $mapWin->setCurrentRegion($arg)) { | ||
| 6924 | return 0; | ||
| 6925 | } else { | ||
| 6926 | return 1; | ||
| 6927 | } | ||
| 6928 | } | ||
| 6929 | } | ||
| 6930 | } | ||
| 6931 | |||
| 6932 | { package Language::Axbasic::Function::Intrinsic::Numeric::setregionnum; | ||
| 6933 | |||
| 6934 | use strict; | ||
| 6935 | use warnings; | ||
| 6936 | # use diagnostics; | ||
| 6937 | |||
| 6938 | use Glib qw(TRUE FALSE); | ||
| 6939 | |||
| 6940 | @Language::Axbasic::Function::Intrinsic::Numeric::setregionnum::ISA = qw( | ||
| 6941 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 6942 | ); | ||
| 6943 | |||
| 6944 | # Setregionnum (number) | ||
| 6945 | |||
| 6946 | ################## | ||
| 6947 | # Methods | ||
| 6948 | |||
| 6949 | sub evaluate { | ||
| 6950 | |||
| 6951 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 6952 | # | ||
| 6953 | # Expected arguments | ||
| 6954 | # $arg - The first (and only) argument in the argument list | ||
| 6955 | # | ||
| 6956 | # Return values | ||
| 6957 | # The return value of the function | ||
| 6958 | |||
| 6959 | my ($self, $arg) = @_; | ||
| 6960 | |||
| 6961 | # Local variables | ||
| 6962 | my ($mapWin, $obj); | ||
| 6963 | |||
| 6964 | # (No improper arguments to check) | ||
| 6965 | |||
| 6966 | # Evaluate the function and return the value | ||
| 6967 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 6968 | |||
| 6969 | # Check that the Automapper window is open | ||
| 6970 | if (! $mapWin) { | ||
| 6971 | |||
| 6972 | return 0; | ||
| 6973 | |||
| 6974 | } else { | ||
| 6975 | |||
| 6976 | # Check that the world model number $arg exists, and that it is a region | ||
| 6977 | $obj = $self->scriptObj->session->worldModelObj->ivShow('modelHash', $arg); | ||
| 6978 | if (! $obj || $obj->category ne 'region') { | ||
| 6979 | |||
| 6980 | return 0; | ||
| 6981 | |||
| 6982 | } else { | ||
| 6983 | |||
| 6984 | # Set the current region. Return 1 on success, 0 on failure | ||
| 6985 | if (! $mapWin->setCurrentRegion($obj->name)) { | ||
| 6986 | return 0; | ||
| 6987 | } else { | ||
| 6988 | return 1; | ||
| 6989 | } | ||
| 6990 | } | ||
| 6991 | } | ||
| 6992 | } | ||
| 6993 | } | ||
| 6994 | |||
| 6995 | { package Language::Axbasic::Function::Intrinsic::Numeric::setroomnum; | ||
| 6996 | |||
| 6997 | use strict; | ||
| 6998 | use warnings; | ||
| 6999 | # use diagnostics; | ||
| 7000 | |||
| 7001 | use Glib qw(TRUE FALSE); | ||
| 7002 | |||
| 7003 | @Language::Axbasic::Function::Intrinsic::Numeric::setroomnum::ISA = qw( | ||
| 7004 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 7005 | ); | ||
| 7006 | |||
| 7007 | # Setroomnum () | ||
| 7008 | # Setroomnum (number) | ||
| 7009 | |||
| 7010 | ################## | ||
| 7011 | # Methods | ||
| 7012 | |||
| 7013 | sub evaluate { | ||
| 7014 | |||
| 7015 | # Called by LA::Expression::Function->evaluate (using arguments in the form ';N') | ||
| 7016 | # | ||
| 7017 | # Expected arguments | ||
| 7018 | # $arg - The first (and only) argument in the argument list | ||
| 7019 | # | ||
| 7020 | # Return values | ||
| 7021 | # The return value of the function | ||
| 7022 | |||
| 7023 | my ($self, $arg) = @_; | ||
| 7024 | |||
| 7025 | # Local variables | ||
| 7026 | my ($mapObj, $obj); | ||
| 7027 | |||
| 7028 | # (No improper arguments to check) | ||
| 7029 | |||
| 7030 | # Evaluate the function and return the value | ||
| 7031 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 7032 | |||
| 7033 | # Check that a valid value for $arg (if specified at all) was supplied | ||
| 7034 | if ($arg && $arg < 1) { | ||
| 7035 | |||
| 7036 | return 0; | ||
| 7037 | } | ||
| 7038 | |||
| 7039 | # If $arg was specified... | ||
| 7040 | if ($arg) { | ||
| 7041 | |||
| 7042 | # ...check it's a valid room model object | ||
| 7043 | $obj = $self->scriptObj->session->worldModelObj->ivShow('modelHash', $arg); | ||
| 7044 | if (! $obj || $obj->category ne 'room') { | ||
| 7045 | |||
| 7046 | return 0; | ||
| 7047 | } | ||
| 7048 | |||
| 7049 | # Attempt to set the current room | ||
| 7050 | $mapObj->setCurrentRoom($obj); | ||
| 7051 | if (! $mapObj->currentRoom || $mapObj->currentRoom ne $obj) { | ||
| 7052 | |||
| 7053 | # Set operation failed | ||
| 7054 | return 0; | ||
| 7055 | |||
| 7056 | } else { | ||
| 7057 | |||
| 7058 | # Set operation succeeded | ||
| 7059 | return 1; | ||
| 7060 | } | ||
| 7061 | |||
| 7062 | } else { | ||
| 7063 | |||
| 7064 | # Attempt to usnet the current room | ||
| 7065 | $mapObj->setCurrentRoom(); | ||
| 7066 | if ($mapObj->currentRoom) { | ||
| 7067 | |||
| 7068 | # Unset operation failed | ||
| 7069 | return 0; | ||
| 7070 | |||
| 7071 | } else { | ||
| 7072 | |||
| 7073 | # Unset operation succeeded | ||
| 7074 | return 1; | ||
| 7075 | } | ||
| 7076 | } | ||
| 7077 | } | ||
| 7078 | } | ||
| 7079 | |||
| 7080 | { package Language::Axbasic::Function::Intrinsic::Numeric::setroomtagged; | ||
| 7081 | |||
| 7082 | use strict; | ||
| 7083 | use warnings; | ||
| 7084 | # use diagnostics; | ||
| 7085 | |||
| 7086 | use Glib qw(TRUE FALSE); | ||
| 7087 | |||
| 7088 | @Language::Axbasic::Function::Intrinsic::Numeric::setroomtagged::ISA = qw( | ||
| 7089 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 7090 | ); | ||
| 7091 | |||
| 7092 | # Setroomtagged (string) | ||
| 7093 | |||
| 7094 | ################## | ||
| 7095 | # Methods | ||
| 7096 | |||
| 7097 | sub evaluate { | ||
| 7098 | |||
| 7099 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 7100 | # | ||
| 7101 | # Expected arguments | ||
| 7102 | # $arg - The first (and only) argument in the argument list | ||
| 7103 | # | ||
| 7104 | # Return values | ||
| 7105 | # The return value of the function | ||
| 7106 | |||
| 7107 | my ($self, $arg) = @_; | ||
| 7108 | |||
| 7109 | # Local variables | ||
| 7110 | my ($mapObj, $wmObj, $number, $obj); | ||
| 7111 | |||
| 7112 | # (No improper arguments to check) | ||
| 7113 | |||
| 7114 | # Evaluate the function and return the value | ||
| 7115 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 7116 | $wmObj = $mapObj->worldModelObj; | ||
| 7117 | |||
| 7118 | # Room tags are stored as lower-case letters | ||
| 7119 | $arg = lc($arg); | ||
| 7120 | |||
| 7121 | # Check that $arg is a tag used by a world model room, if it was specified | ||
| 7122 | if ($arg && ! $wmObj->ivExists('roomTagHash', $arg)) { | ||
| 7123 | |||
| 7124 | # The room tag isn't valid | ||
| 7125 | return 0; | ||
| 7126 | } | ||
| 7127 | |||
| 7128 | # If $arg was specified... | ||
| 7129 | if ($arg) { | ||
| 7130 | |||
| 7131 | # Get the corresponding room | ||
| 7132 | $number = $wmObj->ivShow('roomTagHash', $arg); | ||
| 7133 | $obj = $wmObj->ivShow('modelHash', $number); | ||
| 7134 | if (! $obj) { | ||
| 7135 | |||
| 7136 | return 0; | ||
| 7137 | } | ||
| 7138 | |||
| 7139 | # Attempt to set the current room | ||
| 7140 | $mapObj->setCurrentRoom($obj); | ||
| 7141 | if (! $mapObj->currentRoom || $mapObj->currentRoom ne $obj) { | ||
| 7142 | |||
| 7143 | # Set operation failed | ||
| 7144 | return 0; | ||
| 7145 | |||
| 7146 | } else { | ||
| 7147 | |||
| 7148 | # Set operation succeeded | ||
| 7149 | return 1; | ||
| 7150 | } | ||
| 7151 | |||
| 7152 | } else { | ||
| 7153 | |||
| 7154 | # Attempt to usnet the current room | ||
| 7155 | $mapObj->setCurrentRoom(); | ||
| 7156 | if ($mapObj->currentRoom) { | ||
| 7157 | |||
| 7158 | # Unset operation failed | ||
| 7159 | return 0; | ||
| 7160 | |||
| 7161 | } else { | ||
| 7162 | |||
| 7163 | # Unset operation succeeded | ||
| 7164 | return 1; | ||
| 7165 | } | ||
| 7166 | } | ||
| 7167 | } | ||
| 7168 | } | ||
| 7169 | |||
| 7170 | { package Language::Axbasic::Function::Intrinsic::Numeric::timestamp; | ||
| 7171 | |||
| 7172 | use strict; | ||
| 7173 | use warnings; | ||
| 7174 | # use diagnostics; | ||
| 7175 | |||
| 7176 | use Glib qw(TRUE FALSE); | ||
| 7177 | |||
| 7178 | @Language::Axbasic::Function::Intrinsic::Numeric::timestamp::ISA = qw( | ||
| 7179 | Language::Axbasic::Function::Intrinsic::Numeric | ||
| 7180 | ); | ||
| 7181 | |||
| 7182 | # Timestamp () | ||
| 7183 | |||
| 7184 | ################## | ||
| 7185 | # Methods | ||
| 7186 | |||
| 7187 | sub evaluate { | ||
| 7188 | |||
| 7189 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 7190 | # | ||
| 7191 | # Expected arguments | ||
| 7192 | # $arg - The first (and only) argument in the argument list | ||
| 7193 | # | ||
| 7194 | # Return values | ||
| 7195 | # The return value of the function | ||
| 7196 | |||
| 7197 | my ($self, $arg) = @_; | ||
| 7198 | |||
| 7199 | # (No improper arguments to check) | ||
| 7200 | |||
| 7201 | # Evaluate the function and return the value | ||
| 7202 | return int($self->scriptObj->session->sessionLoopObj->spinTime); | ||
| 7203 | } | ||
| 7204 | } | ||
| 7205 | |||
| 7206 | ### Axmud-dependent functions (string) ### | ||
| 7207 | |||
| 7208 | { package Language::Axbasic::Function::Intrinsic::String::abbrevdir; | ||
| 7209 | |||
| 7210 | use strict; | ||
| 7211 | use warnings; | ||
| 7212 | # use diagnostics; | ||
| 7213 | |||
| 7214 | use Glib qw(TRUE FALSE); | ||
| 7215 | |||
| 7216 | @Language::Axbasic::Function::Intrinsic::String::abbrevdir::ISA = qw( | ||
| 7217 | Language::Axbasic::Function::Intrinsic::String | ||
| 7218 | ); | ||
| 7219 | |||
| 7220 | # Abbrevdir$ () | ||
| 7221 | |||
| 7222 | ################## | ||
| 7223 | # Methods | ||
| 7224 | |||
| 7225 | sub evaluate { | ||
| 7226 | |||
| 7227 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 7228 | # | ||
| 7229 | # Expected arguments | ||
| 7230 | # $arg - The first (and only) argument in the argument list | ||
| 7231 | # | ||
| 7232 | # Return values | ||
| 7233 | # The return value of the function | ||
| 7234 | |||
| 7235 | my ($self, $arg) = @_; | ||
| 7236 | |||
| 7237 | # (No improper arguments to check) | ||
| 7238 | |||
| 7239 | # Evaluate the function and return the value | ||
| 7240 | return $self->scriptObj->session->currentDict->abbrevDir($arg); | ||
| 7241 | } | ||
| 7242 | } | ||
| 7243 | |||
| 7244 | { package Language::Axbasic::Function::Intrinsic::String::clientdate; | ||
| 7245 | |||
| 7246 | use strict; | ||
| 7247 | use warnings; | ||
| 7248 | # use diagnostics; | ||
| 7249 | |||
| 7250 | use Glib qw(TRUE FALSE); | ||
| 7251 | |||
| 7252 | @Language::Axbasic::Function::Intrinsic::String::clientdate::ISA = qw( | ||
| 7253 | Language::Axbasic::Function::Intrinsic::String | ||
| 7254 | ); | ||
| 7255 | |||
| 7256 | # Clientdate$ () | ||
| 7257 | |||
| 7258 | ################## | ||
| 7259 | # Methods | ||
| 7260 | |||
| 7261 | sub evaluate { | ||
| 7262 | |||
| 7263 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 7264 | # | ||
| 7265 | # Expected arguments | ||
| 7266 | # $arg - The first (and only) argument in the argument list | ||
| 7267 | # | ||
| 7268 | # Return values | ||
| 7269 | # The return value of the function | ||
| 7270 | |||
| 7271 | my ($self, $arg) = @_; | ||
| 7272 | |||
| 7273 | # (No improper arguments to check) | ||
| 7274 | |||
| 7275 | # Evaluate the function and return the value | ||
| 7276 | return $axmud::DATE; | ||
| 7277 | } | ||
| 7278 | } | ||
| 7279 | |||
| 7280 | { package Language::Axbasic::Function::Intrinsic::String::clientname; | ||
| 7281 | |||
| 7282 | use strict; | ||
| 7283 | use warnings; | ||
| 7284 | # use diagnostics; | ||
| 7285 | |||
| 7286 | use Glib qw(TRUE FALSE); | ||
| 7287 | |||
| 7288 | @Language::Axbasic::Function::Intrinsic::String::clientname::ISA = qw( | ||
| 7289 | Language::Axbasic::Function::Intrinsic::String | ||
| 7290 | ); | ||
| 7291 | |||
| 7292 | # Clientname$ () | ||
| 7293 | |||
| 7294 | ################## | ||
| 7295 | # Methods | ||
| 7296 | |||
| 7297 | sub evaluate { | ||
| 7298 | |||
| 7299 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 7300 | # | ||
| 7301 | # Expected arguments | ||
| 7302 | # $arg - The first (and only) argument in the argument list | ||
| 7303 | # | ||
| 7304 | # Return values | ||
| 7305 | # The return value of the function | ||
| 7306 | |||
| 7307 | my ($self, $arg) = @_; | ||
| 7308 | |||
| 7309 | # (No improper arguments to check) | ||
| 7310 | |||
| 7311 | # Evaluate the function and return the value | ||
| 7312 | return $axmud::SCRIPT; | ||
| 7313 | } | ||
| 7314 | } | ||
| 7315 | |||
| 7316 | { package Language::Axbasic::Function::Intrinsic::String::clientversion; | ||
| 7317 | |||
| 7318 | use strict; | ||
| 7319 | use warnings; | ||
| 7320 | # use diagnostics; | ||
| 7321 | |||
| 7322 | use Glib qw(TRUE FALSE); | ||
| 7323 | |||
| 7324 | @Language::Axbasic::Function::Intrinsic::String::clientversion::ISA = qw( | ||
| 7325 | Language::Axbasic::Function::Intrinsic::String | ||
| 7326 | ); | ||
| 7327 | |||
| 7328 | # Clientversion$ () | ||
| 7329 | |||
| 7330 | ################## | ||
| 7331 | # Methods | ||
| 7332 | |||
| 7333 | sub evaluate { | ||
| 7334 | |||
| 7335 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 7336 | # | ||
| 7337 | # Expected arguments | ||
| 7338 | # $arg - The first (and only) argument in the argument list | ||
| 7339 | # | ||
| 7340 | # Return values | ||
| 7341 | # The return value of the function | ||
| 7342 | |||
| 7343 | my ($self, $arg) = @_; | ||
| 7344 | |||
| 7345 | # (No improper arguments to check) | ||
| 7346 | |||
| 7347 | # Evaluate the function and return the value | ||
| 7348 | return $axmud::VERSION; | ||
| 7349 | } | ||
| 7350 | } | ||
| 7351 | |||
| 7352 | { package Language::Axbasic::Function::Intrinsic::String::findtask; | ||
| 7353 | |||
| 7354 | use strict; | ||
| 7355 | use warnings; | ||
| 7356 | # use diagnostics; | ||
| 7357 | |||
| 7358 | use Glib qw(TRUE FALSE); | ||
| 7359 | |||
| 7360 | @Language::Axbasic::Function::Intrinsic::String::findtask::ISA = qw( | ||
| 7361 | Language::Axbasic::Function::Intrinsic::String | ||
| 7362 | ); | ||
| 7363 | |||
| 7364 | # Findtask$ (string) | ||
| 7365 | |||
| 7366 | ################## | ||
| 7367 | # Methods | ||
| 7368 | |||
| 7369 | sub evaluate { | ||
| 7370 | |||
| 7371 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'S') | ||
| 7372 | # | ||
| 7373 | # Expected arguments | ||
| 7374 | # $arg - The first (and only) argument in the argument list | ||
| 7375 | # | ||
| 7376 | # Return values | ||
| 7377 | # The return value of the function | ||
| 7378 | |||
| 7379 | my ($self, $arg) = @_; | ||
| 7380 | |||
| 7381 | # Local variables | ||
| 7382 | my ( | ||
| 7383 | $taskObj, | ||
| 7384 | @list, | ||
| 7385 | ); | ||
| 7386 | |||
| 7387 | # (No improper arguments to check) | ||
| 7388 | |||
| 7389 | # Evaluate the function and return the value | ||
| 7390 | |||
| 7391 | # Get a list of tasks in the current tasklist which match $arg. The ->findTask function | ||
| 7392 | # usually accepts the string '-a', but this Axbasic function does not | ||
| 7393 | if ($arg ne '-a') { | ||
| 7394 | |||
| 7395 | @list = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $arg); | ||
| 7396 | } | ||
| 7397 | |||
| 7398 | if (! @list) { | ||
| 7399 | |||
| 7400 | # No matching tasks found | ||
| 7401 | return ''; | ||
| 7402 | |||
| 7403 | } else { | ||
| 7404 | |||
| 7405 | # One or more matching tasks found. Return the first one | ||
| 7406 | $taskObj = $list[0]; | ||
| 7407 | return $taskObj->uniqueName; | ||
| 7408 | } | ||
| 7409 | } | ||
| 7410 | } | ||
| 7411 | |||
| 7412 | { package Language::Axbasic::Function::Intrinsic::String::getexit; | ||
| 7413 | |||
| 7414 | use strict; | ||
| 7415 | use warnings; | ||
| 7416 | # use diagnostics; | ||
| 7417 | |||
| 7418 | use Glib qw(TRUE FALSE); | ||
| 7419 | |||
| 7420 | @Language::Axbasic::Function::Intrinsic::String::getexit::ISA = qw( | ||
| 7421 | Language::Axbasic::Function::Intrinsic::String | ||
| 7422 | ); | ||
| 7423 | |||
| 7424 | # Getexit$ (number) | ||
| 7425 | |||
| 7426 | ################## | ||
| 7427 | # Methods | ||
| 7428 | |||
| 7429 | sub evaluate { | ||
| 7430 | |||
| 7431 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 7432 | # | ||
| 7433 | # Expected arguments | ||
| 7434 | # $arg - The first (and only) argument in the argument list | ||
| 7435 | # | ||
| 7436 | # Return values | ||
| 7437 | # The return value of the function | ||
| 7438 | |||
| 7439 | my ($self, $arg) = @_; | ||
| 7440 | |||
| 7441 | # Local variables | ||
| 7442 | my $mapObj; | ||
| 7443 | |||
| 7444 | # (No improper arguments to check) | ||
| 7445 | |||
| 7446 | # Evaluate the function and return the value | ||
| 7447 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 7448 | |||
| 7449 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 7450 | $arg--; | ||
| 7451 | |||
| 7452 | if ( | ||
| 7453 | ! $mapObj->currentRoom | ||
| 7454 | || ! $mapObj->currentRoom->sortedExitList | ||
| 7455 | || $arg < 0 | ||
| 7456 | || $arg >= scalar ($mapObj->currentRoom->sortedExitList) | ||
| 7457 | ) { | ||
| 7458 | # No current room, no exits in current room, invalid exit number or numbered exit | ||
| 7459 | # doesn't exist | ||
| 7460 | return ''; | ||
| 7461 | |||
| 7462 | } else { | ||
| 7463 | |||
| 7464 | # Return the numbered exit | ||
| 7465 | return $mapObj->currentRoom->ivIndex('sortedExitList', $arg); | ||
| 7466 | } | ||
| 7467 | } | ||
| 7468 | } | ||
| 7469 | |||
| 7470 | { package Language::Axbasic::Function::Intrinsic::String::getexitdrawn; | ||
| 7471 | |||
| 7472 | use strict; | ||
| 7473 | use warnings; | ||
| 7474 | # use diagnostics; | ||
| 7475 | |||
| 7476 | use Glib qw(TRUE FALSE); | ||
| 7477 | |||
| 7478 | @Language::Axbasic::Function::Intrinsic::String::getexitdrawn::ISA = qw( | ||
| 7479 | Language::Axbasic::Function::Intrinsic::String | ||
| 7480 | ); | ||
| 7481 | |||
| 7482 | # Getexitdrawn$ (number) | ||
| 7483 | |||
| 7484 | ################## | ||
| 7485 | # Methods | ||
| 7486 | |||
| 7487 | sub evaluate { | ||
| 7488 | |||
| 7489 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 7490 | # | ||
| 7491 | # Expected arguments | ||
| 7492 | # $arg - The first (and only) argument in the argument list | ||
| 7493 | # | ||
| 7494 | # Return values | ||
| 7495 | # The return value of the function | ||
| 7496 | |||
| 7497 | my ($self, $arg) = @_; | ||
| 7498 | |||
| 7499 | # Local variables | ||
| 7500 | my ($mapObj, $wmObj, $dir, $exitNum, $obj); | ||
| 7501 | |||
| 7502 | # (No improper arguments to check) | ||
| 7503 | |||
| 7504 | # Evaluate the function and return the value | ||
| 7505 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 7506 | $wmObj = $mapObj->worldModelObj; | ||
| 7507 | |||
| 7508 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 7509 | $arg--; | ||
| 7510 | |||
| 7511 | if ( | ||
| 7512 | ! $mapObj->currentRoom | ||
| 7513 | || ! $mapObj->currentRoom->sortedExitList | ||
| 7514 | || $arg < 0 | ||
| 7515 | || $arg >= scalar ($mapObj->currentRoom->sortedExitList) | ||
| 7516 | ) { | ||
| 7517 | # No current room, no exits in current room, invalid exit number or numbered exit | ||
| 7518 | # doesn't exist | ||
| 7519 | return ''; | ||
| 7520 | |||
| 7521 | } else { | ||
| 7522 | |||
| 7523 | # Get the exit model object | ||
| 7524 | $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg); | ||
| 7525 | $exitNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir); | ||
| 7526 | if (! $exitNum || ! $wmObj->ivExists('exitModelHash', $exitNum)) { | ||
| 7527 | |||
| 7528 | # Exit model object not found | ||
| 7529 | return ''; | ||
| 7530 | |||
| 7531 | } else { | ||
| 7532 | |||
| 7533 | $obj = $wmObj->ivShow('exitModelHash', $exitNum); | ||
| 7534 | if (! $obj->mapDir) { | ||
| 7535 | |||
| 7536 | # Exit is unallocatable | ||
| 7537 | return ''; | ||
| 7538 | |||
| 7539 | } else { | ||
| 7540 | |||
| 7541 | # Return the numbered exit's primary direction | ||
| 7542 | return $obj->mapDir; | ||
| 7543 | } | ||
| 7544 | } | ||
| 7545 | } | ||
| 7546 | } | ||
| 7547 | } | ||
| 7548 | |||
| 7549 | { package Language::Axbasic::Function::Intrinsic::String::getexitstatus; | ||
| 7550 | |||
| 7551 | use strict; | ||
| 7552 | use warnings; | ||
| 7553 | # use diagnostics; | ||
| 7554 | |||
| 7555 | use Glib qw(TRUE FALSE); | ||
| 7556 | |||
| 7557 | @Language::Axbasic::Function::Intrinsic::String::getexitstatus::ISA = qw( | ||
| 7558 | Language::Axbasic::Function::Intrinsic::String | ||
| 7559 | ); | ||
| 7560 | |||
| 7561 | # Getexitstatus$ (number) | ||
| 7562 | |||
| 7563 | ################## | ||
| 7564 | # Methods | ||
| 7565 | |||
| 7566 | sub evaluate { | ||
| 7567 | |||
| 7568 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 7569 | # | ||
| 7570 | # Expected arguments | ||
| 7571 | # $arg - The first (and only) argument in the argument list | ||
| 7572 | # | ||
| 7573 | # Return values | ||
| 7574 | # The return value of the function | ||
| 7575 | |||
| 7576 | my ($self, $arg) = @_; | ||
| 7577 | |||
| 7578 | # Local variables | ||
| 7579 | my ($mapObj, $wmObj, $dir, $exitNum, $obj); | ||
| 7580 | |||
| 7581 | # (No improper arguments to check) | ||
| 7582 | |||
| 7583 | # Evaluate the function and return the value | ||
| 7584 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 7585 | $wmObj = $mapObj->worldModelObj; | ||
| 7586 | |||
| 7587 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 7588 | $arg--; | ||
| 7589 | |||
| 7590 | if ( | ||
| 7591 | ! $mapObj->currentRoom | ||
| 7592 | || ! $mapObj->currentRoom->sortedExitList | ||
| 7593 | || $arg < 0 | ||
| 7594 | || $arg >= scalar ($mapObj->currentRoom->sortedExitList) | ||
| 7595 | ) { | ||
| 7596 | # No current room, no exits in current room, invalid exit number or numbered exit | ||
| 7597 | # doesn't exist | ||
| 7598 | return ''; | ||
| 7599 | |||
| 7600 | } else { | ||
| 7601 | |||
| 7602 | # Get the exit model object | ||
| 7603 | $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg); | ||
| 7604 | $exitNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir); | ||
| 7605 | if (! $exitNum || ! $wmObj->ivExists('exitModelHash', $exitNum)) { | ||
| 7606 | |||
| 7607 | # Exit model object not found | ||
| 7608 | return ''; | ||
| 7609 | |||
| 7610 | } else { | ||
| 7611 | |||
| 7612 | $obj = $wmObj->ivShow('exitModelHash', $exitNum); | ||
| 7613 | |||
| 7614 | # Return the exit's status | ||
| 7615 | if ($obj->superFlag) { | ||
| 7616 | return 'super'; | ||
| 7617 | } elsif ($obj->regionFlag) { | ||
| 7618 | return 'region'; | ||
| 7619 | } elsif ($obj->brokenFlag) { | ||
| 7620 | return 'broken'; | ||
| 7621 | } else { | ||
| 7622 | return 'normal'; | ||
| 7623 | } | ||
| 7624 | } | ||
| 7625 | } | ||
| 7626 | } | ||
| 7627 | } | ||
| 7628 | |||
| 7629 | { package Language::Axbasic::Function::Intrinsic::String::getexittype; | ||
| 7630 | |||
| 7631 | use strict; | ||
| 7632 | use warnings; | ||
| 7633 | # use diagnostics; | ||
| 7634 | |||
| 7635 | use Glib qw(TRUE FALSE); | ||
| 7636 | |||
| 7637 | @Language::Axbasic::Function::Intrinsic::String::getexittype::ISA = qw( | ||
| 7638 | Language::Axbasic::Function::Intrinsic::String | ||
| 7639 | ); | ||
| 7640 | |||
| 7641 | # Getexittype$ (number) | ||
| 7642 | |||
| 7643 | ################## | ||
| 7644 | # Methods | ||
| 7645 | |||
| 7646 | sub evaluate { | ||
| 7647 | |||
| 7648 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 7649 | # | ||
| 7650 | # Expected arguments | ||
| 7651 | # $arg - The first (and only) argument in the argument list | ||
| 7652 | # | ||
| 7653 | # Return values | ||
| 7654 | # The return value of the function | ||
| 7655 | |||
| 7656 | my ($self, $arg) = @_; | ||
| 7657 | |||
| 7658 | # Local variables | ||
| 7659 | my ($mapObj, $wmObj, $dir, $exitNum, $obj); | ||
| 7660 | |||
| 7661 | # (No improper arguments to check) | ||
| 7662 | |||
| 7663 | # Evaluate the function and return the value | ||
| 7664 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 7665 | $wmObj = $mapObj->worldModelObj; | ||
| 7666 | |||
| 7667 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 7668 | $arg--; | ||
| 7669 | |||
| 7670 | if ( | ||
| 7671 | ! $mapObj->currentRoom | ||
| 7672 | || ! $mapObj->currentRoom->sortedExitList | ||
| 7673 | || $arg < 0 | ||
| 7674 | || $arg >= scalar ($mapObj->currentRoom->sortedExitList) | ||
| 7675 | ) { | ||
| 7676 | # No current room, no exits in current room, invalid exit number or numbered exit | ||
| 7677 | # doesn't exist | ||
| 7678 | return ''; | ||
| 7679 | |||
| 7680 | } else { | ||
| 7681 | |||
| 7682 | # Get the exit model object | ||
| 7683 | $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg); | ||
| 7684 | $exitNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir); | ||
| 7685 | if (! $exitNum || ! $wmObj->ivExists('exitModelHash', $exitNum)) { | ||
| 7686 | |||
| 7687 | # Exit model object not found | ||
| 7688 | return ''; | ||
| 7689 | |||
| 7690 | } else { | ||
| 7691 | |||
| 7692 | $obj = $wmObj->ivShow('exitModelHash', $exitNum); | ||
| 7693 | |||
| 7694 | # Return the type of exit | ||
| 7695 | if ($obj->exitOrnament eq 'impass') { | ||
| 7696 | |||
| 7697 | return 'impassable'; | ||
| 7698 | |||
| 7699 | } elsif ($obj->exitOrnament eq 'mystery') { | ||
| 7700 | |||
| 7701 | return 'mystery'; | ||
| 7702 | |||
| 7703 | } elsif ($obj->drawMode eq 'temp_alloc' || $obj->drawMode eq 'temp_unalloc') { | ||
| 7704 | |||
| 7705 | return 'unallocated'; | ||
| 7706 | |||
| 7707 | } elsif ($obj->destRoom) { | ||
| 7708 | |||
| 7709 | if ($obj->twinExit) { | ||
| 7710 | return 'two_way'; | ||
| 7711 | } elsif ($obj->retraceFlag) { | ||
| 7712 | return 'retrace'; | ||
| 7713 | } elsif ($obj->oneWayFlag) { | ||
| 7714 | return 'one_way'; | ||
| 7715 | } elsif ($obj->randomType ne 'none') { | ||
| 7716 | return 'random'; | ||
| 7717 | } else { | ||
| 7718 | return 'uncertain'; | ||
| 7719 | } | ||
| 7720 | |||
| 7721 | } elsif ($obj->randomType ne 'none') { | ||
| 7722 | |||
| 7723 | return 'random'; | ||
| 7724 | |||
| 7725 | } else { | ||
| 7726 | |||
| 7727 | return 'incomplete'; | ||
| 7728 | } | ||
| 7729 | } | ||
| 7730 | } | ||
| 7731 | } | ||
| 7732 | } | ||
| 7733 | |||
| 7734 | { package Language::Axbasic::Function::Intrinsic::String::getlight; | ||
| 7735 | |||
| 7736 | use strict; | ||
| 7737 | use warnings; | ||
| 7738 | # use diagnostics; | ||
| 7739 | |||
| 7740 | use Glib qw(TRUE FALSE); | ||
| 7741 | |||
| 7742 | @Language::Axbasic::Function::Intrinsic::String::getlight::ISA = qw( | ||
| 7743 | Language::Axbasic::Function::Intrinsic::String | ||
| 7744 | ); | ||
| 7745 | |||
| 7746 | # Getlight$ () | ||
| 7747 | |||
| 7748 | ################## | ||
| 7749 | # Methods | ||
| 7750 | |||
| 7751 | sub evaluate { | ||
| 7752 | |||
| 7753 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 7754 | # | ||
| 7755 | # Expected arguments | ||
| 7756 | # $arg - The first (and only) argument in the argument list | ||
| 7757 | # | ||
| 7758 | # Return values | ||
| 7759 | # The return value of the function | ||
| 7760 | |||
| 7761 | my ($self, $arg) = @_; | ||
| 7762 | |||
| 7763 | # (No improper arguments to check) | ||
| 7764 | |||
| 7765 | # Evaluate the function and return the value | ||
| 7766 | return $self->scriptObj->session->worldModelObj->lightStatus; | ||
| 7767 | } | ||
| 7768 | } | ||
| 7769 | |||
| 7770 | { package Language::Axbasic::Function::Intrinsic::String::getmapmode; | ||
| 7771 | |||
| 7772 | use strict; | ||
| 7773 | use warnings; | ||
| 7774 | # use diagnostics; | ||
| 7775 | |||
| 7776 | use Glib qw(TRUE FALSE); | ||
| 7777 | |||
| 7778 | @Language::Axbasic::Function::Intrinsic::String::getmapmode::ISA = qw( | ||
| 7779 | Language::Axbasic::Function::Intrinsic::String | ||
| 7780 | ); | ||
| 7781 | |||
| 7782 | # Getmapmode$ () | ||
| 7783 | |||
| 7784 | ################## | ||
| 7785 | # Methods | ||
| 7786 | |||
| 7787 | sub evaluate { | ||
| 7788 | |||
| 7789 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 7790 | # | ||
| 7791 | # Expected arguments | ||
| 7792 | # $arg - The first (and only) argument in the argument list | ||
| 7793 | # | ||
| 7794 | # Return values | ||
| 7795 | # The return value of the function | ||
| 7796 | |||
| 7797 | my ($self, $arg) = @_; | ||
| 7798 | |||
| 7799 | # Local variables | ||
| 7800 | my $mapWin; | ||
| 7801 | |||
| 7802 | # (No improper arguments to check) | ||
| 7803 | |||
| 7804 | # Evaluate the function and return the value | ||
| 7805 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 7806 | |||
| 7807 | if (! $mapWin || ! $mapWin->mode) { | ||
| 7808 | |||
| 7809 | # Automapper window closed, or no mode set (unlikely) | ||
| 7810 | return ''; | ||
| 7811 | |||
| 7812 | } else { | ||
| 7813 | |||
| 7814 | # Return the mode | ||
| 7815 | return $mapWin->mode; | ||
| 7816 | } | ||
| 7817 | } | ||
| 7818 | } | ||
| 7819 | |||
| 7820 | { package Language::Axbasic::Function::Intrinsic::String::getobject; | ||
| 7821 | |||
| 7822 | use strict; | ||
| 7823 | use warnings; | ||
| 7824 | # use diagnostics; | ||
| 7825 | |||
| 7826 | use Glib qw(TRUE FALSE); | ||
| 7827 | |||
| 7828 | @Language::Axbasic::Function::Intrinsic::String::getobject::ISA = qw( | ||
| 7829 | Language::Axbasic::Function::Intrinsic::String | ||
| 7830 | ); | ||
| 7831 | |||
| 7832 | # Getobject$ (number) | ||
| 7833 | |||
| 7834 | ################## | ||
| 7835 | # Methods | ||
| 7836 | |||
| 7837 | sub evaluate { | ||
| 7838 | |||
| 7839 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 7840 | # | ||
| 7841 | # Expected arguments | ||
| 7842 | # $arg - The first (and only) argument in the argument list | ||
| 7843 | # | ||
| 7844 | # Return values | ||
| 7845 | # The return value of the function | ||
| 7846 | |||
| 7847 | my ($self, $arg) = @_; | ||
| 7848 | |||
| 7849 | # Local variables | ||
| 7850 | my ($taskObj, $roomObj, $thisObj); | ||
| 7851 | |||
| 7852 | # (No improper arguments to check) | ||
| 7853 | |||
| 7854 | # Evaluate the function and return the value | ||
| 7855 | $taskObj = $self->scriptObj->session->locatorTask; | ||
| 7856 | if (! $taskObj) { | ||
| 7857 | |||
| 7858 | # Locator task not running | ||
| 7859 | return ''; | ||
| 7860 | } | ||
| 7861 | |||
| 7862 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 7863 | $arg--; | ||
| 7864 | |||
| 7865 | $roomObj = $taskObj->roomObj; | ||
| 7866 | if ( | ||
| 7867 | ! $roomObj | ||
| 7868 | || ! $roomObj->tempObjList | ||
| 7869 | || $arg < 0 | ||
| 7870 | || scalar $roomObj->tempObjList <= $arg | ||
| 7871 | ) { | ||
| 7872 | # Locator task doesn't know current location, current location is empty or the | ||
| 7873 | # numbered object doesn't exist | ||
| 7874 | return ''; | ||
| 7875 | |||
| 7876 | } else { | ||
| 7877 | |||
| 7878 | # Return the object's base string | ||
| 7879 | $thisObj = $roomObj->ivIndex('tempObjList', $arg); | ||
| 7880 | |||
| 7881 | if (defined $thisObj->baseString) { | ||
| 7882 | return $thisObj->baseString; | ||
| 7883 | } else { | ||
| 7884 | return ''; | ||
| 7885 | } | ||
| 7886 | } | ||
| 7887 | } | ||
| 7888 | } | ||
| 7889 | |||
| 7890 | { package Language::Axbasic::Function::Intrinsic::String::getobjectnoun; | ||
| 7891 | |||
| 7892 | use strict; | ||
| 7893 | use warnings; | ||
| 7894 | # use diagnostics; | ||
| 7895 | |||
| 7896 | use Glib qw(TRUE FALSE); | ||
| 7897 | |||
| 7898 | @Language::Axbasic::Function::Intrinsic::String::getobjectnoun::ISA = qw( | ||
| 7899 | Language::Axbasic::Function::Intrinsic::String | ||
| 7900 | ); | ||
| 7901 | |||
| 7902 | # Getobjectnoun$ (number) | ||
| 7903 | |||
| 7904 | ################## | ||
| 7905 | # Methods | ||
| 7906 | |||
| 7907 | sub evaluate { | ||
| 7908 | |||
| 7909 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 7910 | # | ||
| 7911 | # Expected arguments | ||
| 7912 | # $arg - The first (and only) argument in the argument list | ||
| 7913 | # | ||
| 7914 | # Return values | ||
| 7915 | # The return value of the function | ||
| 7916 | |||
| 7917 | my ($self, $arg) = @_; | ||
| 7918 | |||
| 7919 | # Local variables | ||
| 7920 | my ($taskObj, $roomObj, $thisObj); | ||
| 7921 | |||
| 7922 | # (No improper arguments to check) | ||
| 7923 | |||
| 7924 | # Evaluate the function and return the value | ||
| 7925 | $taskObj = $self->scriptObj->session->locatorTask; | ||
| 7926 | if (! $taskObj) { | ||
| 7927 | |||
| 7928 | # Locator task not running | ||
| 7929 | return ''; | ||
| 7930 | } | ||
| 7931 | |||
| 7932 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 7933 | $arg--; | ||
| 7934 | |||
| 7935 | $roomObj = $taskObj->roomObj; | ||
| 7936 | if ( | ||
| 7937 | ! $roomObj | ||
| 7938 | || ! $roomObj->tempObjList | ||
| 7939 | || $arg < 0 | ||
| 7940 | || scalar $roomObj->tempObjList <= $arg | ||
| 7941 | ) { | ||
| 7942 | # Locator task doesn't know current location, current location is empty or the | ||
| 7943 | # numbered object doesn't exist | ||
| 7944 | return ''; | ||
| 7945 | |||
| 7946 | } else { | ||
| 7947 | |||
| 7948 | # Return the object's main noun, if set | ||
| 7949 | $thisObj = $roomObj->ivIndex('tempObjList', $arg); | ||
| 7950 | |||
| 7951 | if (defined $thisObj->noun) { | ||
| 7952 | return $thisObj->noun; | ||
| 7953 | } else { | ||
| 7954 | return ''; | ||
| 7955 | } | ||
| 7956 | } | ||
| 7957 | } | ||
| 7958 | } | ||
| 7959 | |||
| 7960 | { package Language::Axbasic::Function::Intrinsic::String::getobjecttype; | ||
| 7961 | |||
| 7962 | use strict; | ||
| 7963 | use warnings; | ||
| 7964 | # use diagnostics; | ||
| 7965 | |||
| 7966 | use Glib qw(TRUE FALSE); | ||
| 7967 | |||
| 7968 | @Language::Axbasic::Function::Intrinsic::String::getobjecttype::ISA = qw( | ||
| 7969 | Language::Axbasic::Function::Intrinsic::String | ||
| 7970 | ); | ||
| 7971 | |||
| 7972 | # Getobjecttype$ (number) | ||
| 7973 | |||
| 7974 | ################## | ||
| 7975 | # Methods | ||
| 7976 | |||
| 7977 | sub evaluate { | ||
| 7978 | |||
| 7979 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 7980 | # | ||
| 7981 | # Expected arguments | ||
| 7982 | # $arg - The first (and only) argument in the argument list | ||
| 7983 | # | ||
| 7984 | # Return values | ||
| 7985 | # The return value of the function | ||
| 7986 | |||
| 7987 | my ($self, $arg) = @_; | ||
| 7988 | |||
| 7989 | # Local variables | ||
| 7990 | my ($taskObj, $roomObj, $thisObj); | ||
| 7991 | |||
| 7992 | # (No improper arguments to check) | ||
| 7993 | |||
| 7994 | # Evaluate the function and return the value | ||
| 7995 | $taskObj = $self->scriptObj->session->locatorTask; | ||
| 7996 | if (! $taskObj) { | ||
| 7997 | |||
| 7998 | # Locator task not running | ||
| 7999 | return ''; | ||
| 8000 | } | ||
| 8001 | |||
| 8002 | # Perl indexes start at 0, but Axbasic indexes start at 1 | ||
| 8003 | $arg--; | ||
| 8004 | |||
| 8005 | $roomObj = $taskObj->roomObj; | ||
| 8006 | if ( | ||
| 8007 | ! $roomObj | ||
| 8008 | || ! $roomObj->tempObjList | ||
| 8009 | || $arg < 0 | ||
| 8010 | || scalar $roomObj->tempObjList <= $arg | ||
| 8011 | ) { | ||
| 8012 | # Locator task doesn't know current location, current location is empty or the | ||
| 8013 | # numbered object doesn't exist | ||
| 8014 | return ''; | ||
| 8015 | |||
| 8016 | } else { | ||
| 8017 | |||
| 8018 | # Return the object's category | ||
| 8019 | $thisObj = $roomObj->ivIndex('tempObjList', $arg); | ||
| 8020 | |||
| 8021 | if (defined $thisObj) { | ||
| 8022 | return $thisObj->category; | ||
| 8023 | } else { | ||
| 8024 | return ''; | ||
| 8025 | } | ||
| 8026 | } | ||
| 8027 | } | ||
| 8028 | } | ||
| 8029 | |||
| 8030 | { package Language::Axbasic::Function::Intrinsic::String::getornament; | ||
| 8031 | |||
| 8032 | use strict; | ||
| 8033 | use warnings; | ||
| 8034 | # use diagnostics; | ||
| 8035 | |||
| 8036 | use Glib qw(TRUE FALSE); | ||
| 8037 | |||
| 8038 | @Language::Axbasic::Function::Intrinsic::String::getornament::ISA = qw( | ||
| 8039 | Language::Axbasic::Function::Intrinsic::String | ||
| 8040 | ); | ||
| 8041 | |||
| 8042 | # Getornament$ (number) | ||
| 8043 | |||
| 8044 | ################## | ||
| 8045 | # Methods | ||
| 8046 | |||
| 8047 | sub evaluate { | ||
| 8048 | |||
| 8049 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 8050 | # | ||
| 8051 | # Expected arguments | ||
| 8052 | # $arg - The first (and only) argument in the argument list | ||
| 8053 | # | ||
| 8054 | # Return values | ||
| 8055 | # The return value of the function | ||
| 8056 | |||
| 8057 | my ($self, $arg) = @_; | ||
| 8058 | |||
| 8059 | # Local variables | ||
| 8060 | my ($mapObj, $wmObj, $exitObj); | ||
| 8061 | |||
| 8062 | # (No improper arguments to check) | ||
| 8063 | |||
| 8064 | # Evaluate the function and return the value | ||
| 8065 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 8066 | |||
| 8067 | # Find the specified exit | ||
| 8068 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 8069 | if (! defined $exitObj) { | ||
| 8070 | |||
| 8071 | return 'none'; | ||
| 8072 | } | ||
| 8073 | |||
| 8074 | # Return the exit's ornament, if any | ||
| 8075 | return $exitObj->exitOrnament; | ||
| 8076 | } | ||
| 8077 | } | ||
| 8078 | |||
| 8079 | { package Language::Axbasic::Function::Intrinsic::String::getrandomexit; | ||
| 8080 | |||
| 8081 | use strict; | ||
| 8082 | use warnings; | ||
| 8083 | # use diagnostics; | ||
| 8084 | |||
| 8085 | use Glib qw(TRUE FALSE); | ||
| 8086 | |||
| 8087 | @Language::Axbasic::Function::Intrinsic::String::getrandomexit::ISA = qw( | ||
| 8088 | Language::Axbasic::Function::Intrinsic::String | ||
| 8089 | ); | ||
| 8090 | |||
| 8091 | # Getrandomexit$ (number) | ||
| 8092 | |||
| 8093 | ################## | ||
| 8094 | # Methods | ||
| 8095 | |||
| 8096 | sub evaluate { | ||
| 8097 | |||
| 8098 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'N') | ||
| 8099 | # | ||
| 8100 | # Expected arguments | ||
| 8101 | # $arg - The first (and only) argument in the argument list | ||
| 8102 | # | ||
| 8103 | # Return values | ||
| 8104 | # The return value of the function | ||
| 8105 | |||
| 8106 | my ($self, $arg) = @_; | ||
| 8107 | |||
| 8108 | # Local variables | ||
| 8109 | my ($mapObj, $wmObj, $exitObj); | ||
| 8110 | |||
| 8111 | # (No improper arguments to check) | ||
| 8112 | |||
| 8113 | # Evaluate the function and return the value | ||
| 8114 | $wmObj = $self->scriptObj->session->worldModelObj; | ||
| 8115 | |||
| 8116 | # Find the specified exit | ||
| 8117 | $exitObj = $wmObj->ivShow('exitModelHash', $arg); | ||
| 8118 | if (! defined $exitObj) { | ||
| 8119 | |||
| 8120 | return 'none'; | ||
| 8121 | } | ||
| 8122 | |||
| 8123 | # Return the exit's random status, if any | ||
| 8124 | if ($exitObj->randomType eq 'same_region') { | ||
| 8125 | return 'same'; | ||
| 8126 | } elsif ($exitObj->randomType eq 'any_region') { | ||
| 8127 | return 'any'; | ||
| 8128 | } elsif ($exitObj->randomType eq 'temp_region') { | ||
| 8129 | return 'temp'; | ||
| 8130 | } elsif ($exitObj->randomType eq 'room_list') { | ||
| 8131 | return 'room'; | ||
| 8132 | } else { | ||
| 8133 | return 'none'; | ||
| 8134 | } | ||
| 8135 | } | ||
| 8136 | } | ||
| 8137 | |||
| 8138 | { package Language::Axbasic::Function::Intrinsic::String::getregion; | ||
| 8139 | |||
| 8140 | use strict; | ||
| 8141 | use warnings; | ||
| 8142 | # use diagnostics; | ||
| 8143 | |||
| 8144 | use Glib qw(TRUE FALSE); | ||
| 8145 | |||
| 8146 | @Language::Axbasic::Function::Intrinsic::String::getregion::ISA = qw( | ||
| 8147 | Language::Axbasic::Function::Intrinsic::String | ||
| 8148 | ); | ||
| 8149 | |||
| 8150 | # Getregion$ () | ||
| 8151 | |||
| 8152 | ################## | ||
| 8153 | # Methods | ||
| 8154 | |||
| 8155 | sub evaluate { | ||
| 8156 | |||
| 8157 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8158 | # | ||
| 8159 | # Expected arguments | ||
| 8160 | # $arg - The first (and only) argument in the argument list | ||
| 8161 | # | ||
| 8162 | # Return values | ||
| 8163 | # The return value of the function | ||
| 8164 | |||
| 8165 | my ($self, $arg) = @_; | ||
| 8166 | |||
| 8167 | # Local variables | ||
| 8168 | my $mapWin; | ||
| 8169 | |||
| 8170 | # (No improper arguments to check) | ||
| 8171 | |||
| 8172 | # Evaluate the function and return the value | ||
| 8173 | $mapWin = $self->scriptObj->session->mapWin; | ||
| 8174 | if (! $mapWin || ! $mapWin->currentRegionmap) { | ||
| 8175 | |||
| 8176 | # Automapper window closed, or no current region | ||
| 8177 | return ''; | ||
| 8178 | |||
| 8179 | } else { | ||
| 8180 | |||
| 8181 | # Return the name of the current region | ||
| 8182 | return $mapWin->currentRegionmap->name; | ||
| 8183 | } | ||
| 8184 | } | ||
| 8185 | } | ||
| 8186 | |||
| 8187 | { package Language::Axbasic::Function::Intrinsic::String::getroomdescrip; | ||
| 8188 | |||
| 8189 | use strict; | ||
| 8190 | use warnings; | ||
| 8191 | # use diagnostics; | ||
| 8192 | |||
| 8193 | use Glib qw(TRUE FALSE); | ||
| 8194 | |||
| 8195 | @Language::Axbasic::Function::Intrinsic::String::getroomdescrip::ISA = qw( | ||
| 8196 | Language::Axbasic::Function::Intrinsic::String | ||
| 8197 | ); | ||
| 8198 | |||
| 8199 | # Getroomdescrip$ () | ||
| 8200 | # Getroomdescrip$ (string) | ||
| 8201 | |||
| 8202 | ################## | ||
| 8203 | # Methods | ||
| 8204 | |||
| 8205 | sub evaluate { | ||
| 8206 | |||
| 8207 | # Called by LA::Expression::Function->evaluate (using arguments in the form ';S') | ||
| 8208 | # | ||
| 8209 | # Expected arguments | ||
| 8210 | # $arg - The first (and only) argument in the argument list | ||
| 8211 | # | ||
| 8212 | # Return values | ||
| 8213 | # The return value of the function | ||
| 8214 | |||
| 8215 | my ($self, $arg) = @_; | ||
| 8216 | |||
| 8217 | # Local variables | ||
| 8218 | my $mapObj; | ||
| 8219 | |||
| 8220 | # (No improper arguments to check) | ||
| 8221 | |||
| 8222 | # Evaluate the function and return the value | ||
| 8223 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 8224 | if (! $mapObj->currentRoom) { | ||
| 8225 | |||
| 8226 | # No current room | ||
| 8227 | return ''; | ||
| 8228 | |||
| 8229 | } else { | ||
| 8230 | |||
| 8231 | # If the user didn't specify a light status, use the current light status | ||
| 8232 | if (! $arg) { | ||
| 8233 | |||
| 8234 | $arg = $mapObj->worldModelObj->lightStatus; | ||
| 8235 | } | ||
| 8236 | |||
| 8237 | # Return the matching verbose descrip (if there is one) or an empty string otherwise | ||
| 8238 | if ($mapObj->currentRoom->ivExists('descripHash', $arg)) { | ||
| 8239 | |||
| 8240 | return $mapObj->currentRoom->ivShow('descripHash', $arg) | ||
| 8241 | |||
| 8242 | } else { | ||
| 8243 | |||
| 8244 | return ''; | ||
| 8245 | } | ||
| 8246 | } | ||
| 8247 | } | ||
| 8248 | } | ||
| 8249 | |||
| 8250 | { package Language::Axbasic::Function::Intrinsic::String::getroomguild; | ||
| 8251 | |||
| 8252 | use strict; | ||
| 8253 | use warnings; | ||
| 8254 | # use diagnostics; | ||
| 8255 | |||
| 8256 | use Glib qw(TRUE FALSE); | ||
| 8257 | |||
| 8258 | @Language::Axbasic::Function::Intrinsic::String::getroomguild::ISA = qw( | ||
| 8259 | Language::Axbasic::Function::Intrinsic::String | ||
| 8260 | ); | ||
| 8261 | |||
| 8262 | # Getroomguild$ () | ||
| 8263 | |||
| 8264 | ################## | ||
| 8265 | # Methods | ||
| 8266 | |||
| 8267 | sub evaluate { | ||
| 8268 | |||
| 8269 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8270 | # | ||
| 8271 | # Expected arguments | ||
| 8272 | # $arg - The first (and only) argument in the argument list | ||
| 8273 | # | ||
| 8274 | # Return values | ||
| 8275 | # The return value of the function | ||
| 8276 | |||
| 8277 | my ($self, $arg) = @_; | ||
| 8278 | |||
| 8279 | # Local variables | ||
| 8280 | my $mapObj; | ||
| 8281 | |||
| 8282 | # (No improper arguments to check) | ||
| 8283 | |||
| 8284 | # Evaluate the function and return the value | ||
| 8285 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 8286 | |||
| 8287 | if (! $mapObj->currentRoom || ! $mapObj->currentRoom->roomGuild) { | ||
| 8288 | |||
| 8289 | # No current room, or current room has no room guild | ||
| 8290 | return ''; | ||
| 8291 | |||
| 8292 | } else { | ||
| 8293 | |||
| 8294 | # Return the current room's room guild | ||
| 8295 | return $mapObj->currentRoom->roomGuild; | ||
| 8296 | } | ||
| 8297 | } | ||
| 8298 | } | ||
| 8299 | |||
| 8300 | { package Language::Axbasic::Function::Intrinsic::String::getroomsource; | ||
| 8301 | |||
| 8302 | use strict; | ||
| 8303 | use warnings; | ||
| 8304 | # use diagnostics; | ||
| 8305 | |||
| 8306 | use Glib qw(TRUE FALSE); | ||
| 8307 | |||
| 8308 | @Language::Axbasic::Function::Intrinsic::String::getroomsource::ISA = qw( | ||
| 8309 | Language::Axbasic::Function::Intrinsic::String | ||
| 8310 | ); | ||
| 8311 | |||
| 8312 | # Getroomsource$ () | ||
| 8313 | |||
| 8314 | ################## | ||
| 8315 | # Methods | ||
| 8316 | |||
| 8317 | sub evaluate { | ||
| 8318 | |||
| 8319 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8320 | # | ||
| 8321 | # Expected arguments | ||
| 8322 | # $arg - The first (and only) argument in the argument list | ||
| 8323 | # | ||
| 8324 | # Return values | ||
| 8325 | # The return value of the function | ||
| 8326 | |||
| 8327 | my ($self, $arg) = @_; | ||
| 8328 | |||
| 8329 | # Local variables | ||
| 8330 | my $mapObj; | ||
| 8331 | |||
| 8332 | # (No improper arguments to check) | ||
| 8333 | |||
| 8334 | # Evaluate the function and return the value | ||
| 8335 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 8336 | |||
| 8337 | if ( | ||
| 8338 | ! $mapObj->currentRoom | ||
| 8339 | || (! $mapObj->currentRoom->sourceCodePath && ! $mapObj->currentRoom->virtualAreaPath) | ||
| 8340 | ) { | ||
| 8341 | # No current room, or current room has no source code path set | ||
| 8342 | return ''; | ||
| 8343 | |||
| 8344 | } else { | ||
| 8345 | |||
| 8346 | # Return the current room's virtual area path, if set; otherwise return its source code | ||
| 8347 | # path | ||
| 8348 | if ($mapObj->currentRoom->virtualAreaPath) { | ||
| 8349 | return $mapObj->currentRoom->virtualAreaPath; | ||
| 8350 | } else { | ||
| 8351 | return $mapObj->currentRoom->sourceCodePath; | ||
| 8352 | } | ||
| 8353 | } | ||
| 8354 | } | ||
| 8355 | } | ||
| 8356 | |||
| 8357 | { package Language::Axbasic::Function::Intrinsic::String::getroomtag; | ||
| 8358 | |||
| 8359 | use strict; | ||
| 8360 | use warnings; | ||
| 8361 | # use diagnostics; | ||
| 8362 | |||
| 8363 | use Glib qw(TRUE FALSE); | ||
| 8364 | |||
| 8365 | @Language::Axbasic::Function::Intrinsic::String::getroomtag::ISA = qw( | ||
| 8366 | Language::Axbasic::Function::Intrinsic::String | ||
| 8367 | ); | ||
| 8368 | |||
| 8369 | # Getroomtag$ () | ||
| 8370 | |||
| 8371 | ################## | ||
| 8372 | # Methods | ||
| 8373 | |||
| 8374 | sub evaluate { | ||
| 8375 | |||
| 8376 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8377 | # | ||
| 8378 | # Expected arguments | ||
| 8379 | # $arg - The first (and only) argument in the argument list | ||
| 8380 | # | ||
| 8381 | # Return values | ||
| 8382 | # The return value of the function | ||
| 8383 | |||
| 8384 | my ($self, $arg) = @_; | ||
| 8385 | |||
| 8386 | # Local variables | ||
| 8387 | my $mapObj; | ||
| 8388 | |||
| 8389 | # (No improper arguments to check) | ||
| 8390 | |||
| 8391 | # Evaluate the function and return the value | ||
| 8392 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 8393 | |||
| 8394 | if (! $mapObj->currentRoom || ! $mapObj->currentRoom->roomTag) { | ||
| 8395 | |||
| 8396 | # No current room, or current room has no room tag | ||
| 8397 | return ''; | ||
| 8398 | |||
| 8399 | } else { | ||
| 8400 | |||
| 8401 | # Return the current room's room tag | ||
| 8402 | return $mapObj->currentRoom->roomTag; | ||
| 8403 | } | ||
| 8404 | } | ||
| 8405 | } | ||
| 8406 | |||
| 8407 | { package Language::Axbasic::Function::Intrinsic::String::getroomtitle; | ||
| 8408 | |||
| 8409 | use strict; | ||
| 8410 | use warnings; | ||
| 8411 | # use diagnostics; | ||
| 8412 | |||
| 8413 | use Glib qw(TRUE FALSE); | ||
| 8414 | |||
| 8415 | @Language::Axbasic::Function::Intrinsic::String::getroomtitle::ISA = qw( | ||
| 8416 | Language::Axbasic::Function::Intrinsic::String | ||
| 8417 | ); | ||
| 8418 | |||
| 8419 | # Getroomtitle$ () | ||
| 8420 | |||
| 8421 | ################## | ||
| 8422 | # Methods | ||
| 8423 | |||
| 8424 | sub evaluate { | ||
| 8425 | |||
| 8426 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8427 | # | ||
| 8428 | # Expected arguments | ||
| 8429 | # $arg - The first (and only) argument in the argument list | ||
| 8430 | # | ||
| 8431 | # Return values | ||
| 8432 | # The return value of the function | ||
| 8433 | |||
| 8434 | my ($self, $arg) = @_; | ||
| 8435 | |||
| 8436 | # Local variables | ||
| 8437 | my $mapObj; | ||
| 8438 | |||
| 8439 | # (No improper arguments to check) | ||
| 8440 | |||
| 8441 | # Evaluate the function and return the value | ||
| 8442 | $mapObj = $self->scriptObj->session->mapObj; | ||
| 8443 | |||
| 8444 | if ( | ||
| 8445 | ! $mapObj->currentRoom | ||
| 8446 | || ! $mapObj->currentRoom->titleList | ||
| 8447 | ) { | ||
| 8448 | # No current room, or current room has no title set | ||
| 8449 | return ''; | ||
| 8450 | |||
| 8451 | } else { | ||
| 8452 | |||
| 8453 | # Return the current room's (first) title | ||
| 8454 | return $mapObj->currentRoom->ivFirst('titleList'); | ||
| 8455 | } | ||
| 8456 | } | ||
| 8457 | } | ||
| 8458 | |||
| 8459 | { package Language::Axbasic::Function::Intrinsic::String::iface; | ||
| 8460 | |||
| 8461 | use strict; | ||
| 8462 | use warnings; | ||
| 8463 | # use diagnostics; | ||
| 8464 | |||
| 8465 | use Glib qw(TRUE FALSE); | ||
| 8466 | |||
| 8467 | @Language::Axbasic::Function::Intrinsic::String::iface::ISA = qw( | ||
| 8468 | Language::Axbasic::Function::Intrinsic::String | ||
| 8469 | ); | ||
| 8470 | |||
| 8471 | # Iface$ () | ||
| 8472 | |||
| 8473 | ################## | ||
| 8474 | # Methods | ||
| 8475 | |||
| 8476 | sub evaluate { | ||
| 8477 | |||
| 8478 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8479 | # | ||
| 8480 | # Expected arguments | ||
| 8481 | # $arg - The first (and only) argument in the argument list | ||
| 8482 | # | ||
| 8483 | # Return values | ||
| 8484 | # The return value of the function | ||
| 8485 | |||
| 8486 | my ($self, $arg) = @_; | ||
| 8487 | |||
| 8488 | # (No improper arguments to check) | ||
| 8489 | |||
| 8490 | # Evaluate the function and return the value | ||
| 8491 | if (! $self->scriptObj->depInterfaceName) { | ||
| 8492 | |||
| 8493 | # Either no dependent interface has been created by this script, or the last attempt | ||
| 8494 | # failed | ||
| 8495 | return ''; | ||
| 8496 | |||
| 8497 | } else { | ||
| 8498 | |||
| 8499 | # The IV contains the name of the most recently-created dependent interface | ||
| 8500 | return $self->scriptObj->depInterfaceName; | ||
| 8501 | } | ||
| 8502 | } | ||
| 8503 | } | ||
| 8504 | |||
| 8505 | { package Language::Axbasic::Function::Intrinsic::String::ifacedata; | ||
| 8506 | |||
| 8507 | use strict; | ||
| 8508 | use warnings; | ||
| 8509 | # use diagnostics; | ||
| 8510 | |||
| 8511 | use Glib qw(TRUE FALSE); | ||
| 8512 | |||
| 8513 | @Language::Axbasic::Function::Intrinsic::String::ifacedata::ISA = qw( | ||
| 8514 | Language::Axbasic::Function::Intrinsic::String | ||
| 8515 | ); | ||
| 8516 | |||
| 8517 | # Ifacedata$ () | ||
| 8518 | |||
| 8519 | ################## | ||
| 8520 | # Methods | ||
| 8521 | |||
| 8522 | sub evaluate { | ||
| 8523 | |||
| 8524 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8525 | # | ||
| 8526 | # Expected arguments | ||
| 8527 | # $arg - The first (and only) argument in the argument list | ||
| 8528 | # | ||
| 8529 | # Return values | ||
| 8530 | # The return value of the function | ||
| 8531 | |||
| 8532 | my ($self, $arg) = @_; | ||
| 8533 | |||
| 8534 | # Local variables | ||
| 8535 | my ($obj, $substr); | ||
| 8536 | |||
| 8537 | # (No improper arguments to check) | ||
| 8538 | |||
| 8539 | # Evaluate the function and return the value | ||
| 8540 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 8541 | |||
| 8542 | # The notification list is empty, so return an empty string | ||
| 8543 | return ''; | ||
| 8544 | |||
| 8545 | } else { | ||
| 8546 | |||
| 8547 | # Get the current notification | ||
| 8548 | $obj = $self->scriptObj->ivIndex( | ||
| 8549 | 'notificationList', | ||
| 8550 | $self->scriptObj->currentNotification, | ||
| 8551 | ); | ||
| 8552 | |||
| 8553 | # Return the first item in ->dataList. If it's an undefined value, returns an empty | ||
| 8554 | # string instead | ||
| 8555 | # For triggers/aliases, it's the first substring (which might be 'undef', which is | ||
| 8556 | # converted to an empty string) | ||
| 8557 | # For macros, ->dataList is always empty, so an empty string will be returned | ||
| 8558 | # For timers whose stimulus is a clock string (in the form "HH:MM" or "99::MM"), returns | ||
| 8559 | # the clock string, otherwise returns an empty string, returns the | ||
| 8560 | # For hooks, if the hook event has hook data, returns it; otherwise returns an empty | ||
| 8561 | # string | ||
| 8562 | if (! $obj->dataList) { | ||
| 8563 | |||
| 8564 | # No meaningful value to return | ||
| 8565 | return ''; | ||
| 8566 | |||
| 8567 | } else { | ||
| 8568 | |||
| 8569 | # If a regex matching a line is in the form (...|...|...), with each ... containing | ||
| 8570 | # its own substrings, ->dataList will contain lots of 'undef' values from | ||
| 8571 | # the ... portions that didn't match the line | ||
| 8572 | # We can't return the 'undef' because it will cause an Axbasic 'Undefined function | ||
| 8573 | # error'. Therefore, return an empty string instead | ||
| 8574 | $substr = $obj->ivFirst('dataList'); | ||
| 8575 | if (defined $substr) { | ||
| 8576 | return $substr | ||
| 8577 | } else { | ||
| 8578 | return ''; | ||
| 8579 | } | ||
| 8580 | } | ||
| 8581 | } | ||
| 8582 | } | ||
| 8583 | } | ||
| 8584 | |||
| 8585 | { package Language::Axbasic::Function::Intrinsic::String::ifacename; | ||
| 8586 | |||
| 8587 | use strict; | ||
| 8588 | use warnings; | ||
| 8589 | # use diagnostics; | ||
| 8590 | |||
| 8591 | use Glib qw(TRUE FALSE); | ||
| 8592 | |||
| 8593 | @Language::Axbasic::Function::Intrinsic::String::ifacename::ISA = qw( | ||
| 8594 | Language::Axbasic::Function::Intrinsic::String | ||
| 8595 | ); | ||
| 8596 | |||
| 8597 | # Ifacename$ () | ||
| 8598 | |||
| 8599 | ################## | ||
| 8600 | # Methods | ||
| 8601 | |||
| 8602 | sub evaluate { | ||
| 8603 | |||
| 8604 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8605 | # | ||
| 8606 | # Expected arguments | ||
| 8607 | # $arg - The first (and only) argument in the argument list | ||
| 8608 | # | ||
| 8609 | # Return values | ||
| 8610 | # The return value of the function | ||
| 8611 | |||
| 8612 | my ($self, $arg) = @_; | ||
| 8613 | |||
| 8614 | # Local variables | ||
| 8615 | my $obj; | ||
| 8616 | |||
| 8617 | # (No improper arguments to check) | ||
| 8618 | |||
| 8619 | # Evaluate the function and return the value | ||
| 8620 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 8621 | |||
| 8622 | # The notification list is empty, so return an empty string | ||
| 8623 | return ''; | ||
| 8624 | |||
| 8625 | } else { | ||
| 8626 | |||
| 8627 | # Get the current notification | ||
| 8628 | $obj = $self->scriptObj->ivIndex( | ||
| 8629 | 'notificationList', | ||
| 8630 | $self->scriptObj->currentNotification, | ||
| 8631 | ); | ||
| 8632 | |||
| 8633 | # Return its name of the corresponding interface | ||
| 8634 | return $obj->name; | ||
| 8635 | } | ||
| 8636 | } | ||
| 8637 | } | ||
| 8638 | |||
| 8639 | { package Language::Axbasic::Function::Intrinsic::String::ifacepop; | ||
| 8640 | |||
| 8641 | use strict; | ||
| 8642 | use warnings; | ||
| 8643 | # use diagnostics; | ||
| 8644 | |||
| 8645 | use Glib qw(TRUE FALSE); | ||
| 8646 | |||
| 8647 | @Language::Axbasic::Function::Intrinsic::String::ifacepop::ISA = qw( | ||
| 8648 | Language::Axbasic::Function::Intrinsic::String | ||
| 8649 | ); | ||
| 8650 | |||
| 8651 | # Ifacepop$ () | ||
| 8652 | |||
| 8653 | ################## | ||
| 8654 | # Methods | ||
| 8655 | |||
| 8656 | sub evaluate { | ||
| 8657 | |||
| 8658 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8659 | # | ||
| 8660 | # Expected arguments | ||
| 8661 | # $arg - The first (and only) argument in the argument list | ||
| 8662 | # | ||
| 8663 | # Return values | ||
| 8664 | # The return value of the function | ||
| 8665 | |||
| 8666 | my ($self, $arg) = @_; | ||
| 8667 | |||
| 8668 | # Local variables | ||
| 8669 | my ($obj, $substr); | ||
| 8670 | |||
| 8671 | # (No improper arguments to check) | ||
| 8672 | |||
| 8673 | # Evaluate the function and return the value | ||
| 8674 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 8675 | |||
| 8676 | # The notification list is empty, so return an empty string | ||
| 8677 | return ''; | ||
| 8678 | |||
| 8679 | } else { | ||
| 8680 | |||
| 8681 | # Get the current notification | ||
| 8682 | $obj = $self->scriptObj->ivIndex( | ||
| 8683 | 'notificationList', | ||
| 8684 | $self->scriptObj->currentNotification, | ||
| 8685 | ); | ||
| 8686 | |||
| 8687 | if (! $obj->dataList) { | ||
| 8688 | |||
| 8689 | # No additional data to return | ||
| 8690 | return ''; | ||
| 8691 | |||
| 8692 | } else { | ||
| 8693 | |||
| 8694 | # If a regex matching a line is in the form (...|...|...), with each ... containing | ||
| 8695 | # its own substrings, ->dataList will contain lots of 'undef' values from | ||
| 8696 | # the ... portions that didn't match the line | ||
| 8697 | # We can't return the 'undef' because it will cause an Axbasic 'Undefined function | ||
| 8698 | # error'. Therefore, return an empty string instead | ||
| 8699 | $substr = $obj->ivPop('dataList'); | ||
| 8700 | if (defined $substr) { | ||
| 8701 | return $substr | ||
| 8702 | } else { | ||
| 8703 | return ''; | ||
| 8704 | } | ||
| 8705 | } | ||
| 8706 | } | ||
| 8707 | } | ||
| 8708 | } | ||
| 8709 | |||
| 8710 | { package Language::Axbasic::Function::Intrinsic::String::ifaceselect; | ||
| 8711 | |||
| 8712 | use strict; | ||
| 8713 | use warnings; | ||
| 8714 | # use diagnostics; | ||
| 8715 | |||
| 8716 | use Glib qw(TRUE FALSE); | ||
| 8717 | |||
| 8718 | @Language::Axbasic::Function::Intrinsic::String::ifaceselect::ISA = qw( | ||
| 8719 | Language::Axbasic::Function::Intrinsic::String | ||
| 8720 | ); | ||
| 8721 | |||
| 8722 | # Ifaceselect$ (number) | ||
| 8723 | |||
| 8724 | ################## | ||
| 8725 | # Methods | ||
| 8726 | |||
| 8727 | sub evaluate { | ||
| 8728 | |||
| 8729 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8730 | # | ||
| 8731 | # Expected arguments | ||
| 8732 | # $arg - The first (and only) argument in the argument list | ||
| 8733 | # | ||
| 8734 | # Return values | ||
| 8735 | # The return value of the function | ||
| 8736 | |||
| 8737 | my ($self, $arg) = @_; | ||
| 8738 | |||
| 8739 | # Local variables | ||
| 8740 | my ($obj, $substr); | ||
| 8741 | |||
| 8742 | # (No improper arguments to check) | ||
| 8743 | |||
| 8744 | # Evaluate the function and return the value | ||
| 8745 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 8746 | |||
| 8747 | # The notification list is empty, so return an empty string | ||
| 8748 | return ''; | ||
| 8749 | |||
| 8750 | } else { | ||
| 8751 | |||
| 8752 | # Get the current notification | ||
| 8753 | $obj = $self->scriptObj->ivIndex( | ||
| 8754 | 'notificationList', | ||
| 8755 | $self->scriptObj->currentNotification, | ||
| 8756 | ); | ||
| 8757 | |||
| 8758 | if (! $obj->dataList) { | ||
| 8759 | |||
| 8760 | # No additional data to return | ||
| 8761 | return ''; | ||
| 8762 | |||
| 8763 | } else { | ||
| 8764 | |||
| 8765 | # If a regex matching a line is in the form (...|...|...), with each ... containing | ||
| 8766 | # its own substrings, ->dataList will contain lots of 'undef' values from | ||
| 8767 | # the ... portions that didn't match the line | ||
| 8768 | # We can't return the 'undef' because it will cause an Axbasic 'Undefined function | ||
| 8769 | # error'. Therefore, return an empty string instead | ||
| 8770 | $substr = $obj->ivIndex('dataList', ($arg - 1)); | ||
| 8771 | if (defined $substr) { | ||
| 8772 | return $substr | ||
| 8773 | } else { | ||
| 8774 | return ''; | ||
| 8775 | } | ||
| 8776 | } | ||
| 8777 | } | ||
| 8778 | } | ||
| 8779 | } | ||
| 8780 | |||
| 8781 | { package Language::Axbasic::Function::Intrinsic::String::ifaceshift; | ||
| 8782 | |||
| 8783 | use strict; | ||
| 8784 | use warnings; | ||
| 8785 | # use diagnostics; | ||
| 8786 | |||
| 8787 | use Glib qw(TRUE FALSE); | ||
| 8788 | |||
| 8789 | @Language::Axbasic::Function::Intrinsic::String::ifaceshift::ISA = qw( | ||
| 8790 | Language::Axbasic::Function::Intrinsic::String | ||
| 8791 | ); | ||
| 8792 | |||
| 8793 | # Ifaceshift$ () | ||
| 8794 | |||
| 8795 | ################## | ||
| 8796 | # Methods | ||
| 8797 | |||
| 8798 | sub evaluate { | ||
| 8799 | |||
| 8800 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8801 | # | ||
| 8802 | # Expected arguments | ||
| 8803 | # $arg - The first (and only) argument in the argument list | ||
| 8804 | # | ||
| 8805 | # Return values | ||
| 8806 | # The return value of the function | ||
| 8807 | |||
| 8808 | my ($self, $arg) = @_; | ||
| 8809 | |||
| 8810 | # Local variables | ||
| 8811 | my ($obj, $substr); | ||
| 8812 | |||
| 8813 | # (No improper arguments to check) | ||
| 8814 | |||
| 8815 | # Evaluate the function and return the value | ||
| 8816 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 8817 | |||
| 8818 | # The notification list is empty, so return an empty string | ||
| 8819 | return ''; | ||
| 8820 | |||
| 8821 | } else { | ||
| 8822 | |||
| 8823 | # Get the current notification | ||
| 8824 | $obj = $self->scriptObj->ivIndex( | ||
| 8825 | 'notificationList', | ||
| 8826 | $self->scriptObj->currentNotification, | ||
| 8827 | ); | ||
| 8828 | |||
| 8829 | if (! $obj->dataList) { | ||
| 8830 | |||
| 8831 | # No additional data to return | ||
| 8832 | return ''; | ||
| 8833 | |||
| 8834 | } else { | ||
| 8835 | |||
| 8836 | # If a regex matching a line is in the form (...|...|...), with each ... containing | ||
| 8837 | # its own substrings, ->dataList will contain lots of 'undef' values from | ||
| 8838 | # the ... portions that didn't match the line | ||
| 8839 | # We can't return the 'undef' because it will cause an Axbasic 'Undefined function | ||
| 8840 | # error'. Therefore, return an empty string instead | ||
| 8841 | $substr = $obj->ivShift('dataList'); | ||
| 8842 | if (defined $substr) { | ||
| 8843 | return $substr | ||
| 8844 | } else { | ||
| 8845 | return ''; | ||
| 8846 | } | ||
| 8847 | } | ||
| 8848 | } | ||
| 8849 | } | ||
| 8850 | } | ||
| 8851 | |||
| 8852 | { package Language::Axbasic::Function::Intrinsic::String::ifacetext; | ||
| 8853 | |||
| 8854 | use strict; | ||
| 8855 | use warnings; | ||
| 8856 | # use diagnostics; | ||
| 8857 | |||
| 8858 | use Glib qw(TRUE FALSE); | ||
| 8859 | |||
| 8860 | @Language::Axbasic::Function::Intrinsic::String::ifacetext::ISA = qw( | ||
| 8861 | Language::Axbasic::Function::Intrinsic::String | ||
| 8862 | ); | ||
| 8863 | |||
| 8864 | # Ifacetext$ () | ||
| 8865 | |||
| 8866 | ################## | ||
| 8867 | # Methods | ||
| 8868 | |||
| 8869 | sub evaluate { | ||
| 8870 | |||
| 8871 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8872 | # | ||
| 8873 | # Expected arguments | ||
| 8874 | # $arg - The first (and only) argument in the argument list | ||
| 8875 | # | ||
| 8876 | # Return values | ||
| 8877 | # The return value of the function | ||
| 8878 | |||
| 8879 | my ($self, $arg) = @_; | ||
| 8880 | |||
| 8881 | # Local variables | ||
| 8882 | my $obj; | ||
| 8883 | |||
| 8884 | # (No improper arguments to check) | ||
| 8885 | |||
| 8886 | # Evaluate the function and return the value | ||
| 8887 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 8888 | |||
| 8889 | # The notification list is empty, so return an empty string | ||
| 8890 | return ''; | ||
| 8891 | |||
| 8892 | } else { | ||
| 8893 | |||
| 8894 | # Get the current notification | ||
| 8895 | $obj = $self->scriptObj->ivIndex( | ||
| 8896 | 'notificationList', | ||
| 8897 | $self->scriptObj->currentNotification, | ||
| 8898 | ); | ||
| 8899 | |||
| 8900 | # Return the cause for the fired interface | ||
| 8901 | return $obj->fireBecause; | ||
| 8902 | } | ||
| 8903 | } | ||
| 8904 | } | ||
| 8905 | |||
| 8906 | { package Language::Axbasic::Function::Intrinsic::String::ifacetype; | ||
| 8907 | |||
| 8908 | use strict; | ||
| 8909 | use warnings; | ||
| 8910 | # use diagnostics; | ||
| 8911 | |||
| 8912 | use Glib qw(TRUE FALSE); | ||
| 8913 | |||
| 8914 | @Language::Axbasic::Function::Intrinsic::String::ifacetype::ISA = qw( | ||
| 8915 | Language::Axbasic::Function::Intrinsic::String | ||
| 8916 | ); | ||
| 8917 | |||
| 8918 | # Ifacetype$ () | ||
| 8919 | |||
| 8920 | ################## | ||
| 8921 | # Methods | ||
| 8922 | |||
| 8923 | sub evaluate { | ||
| 8924 | |||
| 8925 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 8926 | # | ||
| 8927 | # Expected arguments | ||
| 8928 | # $arg - The first (and only) argument in the argument list | ||
| 8929 | # | ||
| 8930 | # Return values | ||
| 8931 | # The return value of the function | ||
| 8932 | |||
| 8933 | my ($self, $arg) = @_; | ||
| 8934 | |||
| 8935 | # Local variables | ||
| 8936 | my $obj; | ||
| 8937 | |||
| 8938 | # (No improper arguments to check) | ||
| 8939 | |||
| 8940 | # Evaluate the function and return the value | ||
| 8941 | if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) { | ||
| 8942 | |||
| 8943 | # The notification list is empty, so return an empty string | ||
| 8944 | return ''; | ||
| 8945 | |||
| 8946 | } else { | ||
| 8947 | |||
| 8948 | # Get the current notification | ||
| 8949 | $obj = $self->scriptObj->ivIndex( | ||
| 8950 | 'notificationList', | ||
| 8951 | $self->scriptObj->currentNotification, | ||
| 8952 | ); | ||
| 8953 | |||
| 8954 | # Return its category | ||
| 8955 | return $obj->category; | ||
| 8956 | } | ||
| 8957 | } | ||
| 8958 | } | ||
| 8959 | |||
| 8960 | { package Language::Axbasic::Function::Intrinsic::String::popup; | ||
| 8961 | |||
| 8962 | use strict; | ||
| 8963 | use warnings; | ||
| 8964 | # use diagnostics; | ||
| 8965 | |||
| 8966 | use Glib qw(TRUE FALSE); | ||
| 8967 | |||
| 8968 | @Language::Axbasic::Function::Intrinsic::String::popup::ISA = qw( | ||
| 8969 | Language::Axbasic::Function::Intrinsic::String | ||
| 8970 | ); | ||
| 8971 | |||
| 8972 | # Popup$ (type, text, response) | ||
| 8973 | |||
| 8974 | ################## | ||
| 8975 | # Methods | ||
| 8976 | |||
| 8977 | sub evaluate { | ||
| 8978 | |||
| 8979 | # Called by LA::Expression::Function->evaluate (using arguments in the form 'SSS') | ||
| 8980 | # | ||
| 8981 | # Expected arguments | ||
| 8982 | # @args - The list of arguments supplied to the function | ||
| 8983 | # | ||
| 8984 | # Return values | ||
| 8985 | # The return value of the function | ||
| 8986 | |||
| 8987 | my ($self, @args) = @_; | ||
| 8988 | |||
| 8989 | # Local variables | ||
| 8990 | my ($type, $response, $choice); | ||
| 8991 | |||
| 8992 | # (No improper arguments to check) | ||
| 8993 | |||
| 8994 | # Evaluate the function and return the value | ||
| 8995 | |||
| 8996 | # Check that the type is one of the values permitted by GA::Generic::Win->showMsgDialogue | ||
| 8997 | # and, if not, use a default type | ||
| 8998 | $type = $args[0]; | ||
| 8999 | if ( | ||
| 9000 | $type ne 'info' && $type ne 'warning' && $type ne 'error' && $type ne 'question' | ||
| 9001 | ) { | ||
| 9002 | $type = 'info'; | ||
| 9003 | } | ||
| 9004 | |||
| 9005 | # Substitute a hyphen for any underlines or spaces in the response | ||
| 9006 | $response = $args[2]; | ||
| 9007 | $response =~ s/_/-/; | ||
| 9008 | $response =~ s/\s/-/; | ||
| 9009 | # Check that the response is one of the values permitted by | ||
| 9010 | # GA::Generic::Win->showMsgDialogue and, if not, use a default respone | ||
| 9011 | if ( | ||
| 9012 | $response ne 'none' && $response ne 'ok' && $response ne 'close' | ||
| 9013 | && $response ne 'cancel' && $response ne 'yes-no' && $response ne 'ok-cancel' | ||
| 9014 | ) { | ||
| 9015 | $response = 'ok'; | ||
| 9016 | } | ||
| 9017 | |||
| 9018 | # Open a 'dialogue' window to prompt the user | ||
| 9019 | $choice = $self->scriptObj->session->mainWin->showMsgDialogue( | ||
| 9020 | $self->scriptObj->name, # Use the script name as the window's title | ||
| 9021 | $type, | ||
| 9022 | $args[1], | ||
| 9023 | $response, | ||
| 9024 | ); | ||
| 9025 | |||
| 9026 | if (! $choice || $choice eq 'delete-event') { | ||
| 9027 | return ""; | ||
| 9028 | } else { | ||
| 9029 | return $choice; | ||
| 9030 | } | ||
| 9031 | } | ||
| 9032 | } | ||
| 9033 | |||
| 9034 | { package Language::Axbasic::Function::Intrinsic::String::scriptname; | ||
| 9035 | |||
| 9036 | use strict; | ||
| 9037 | use warnings; | ||
| 9038 | # use diagnostics; | ||
| 9039 | |||
| 9040 | use Glib qw(TRUE FALSE); | ||
| 9041 | |||
| 9042 | @Language::Axbasic::Function::Intrinsic::String::scriptname::ISA = qw( | ||
| 9043 | Language::Axbasic::Function::Intrinsic::String | ||
| 9044 | ); | ||
| 9045 | |||
| 9046 | # Scriptname$ () | ||
| 9047 | |||
| 9048 | ################## | ||
| 9049 | # Methods | ||
| 9050 | |||
| 9051 | sub evaluate { | ||
| 9052 | |||
| 9053 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 9054 | # | ||
| 9055 | # Expected arguments | ||
| 9056 | # $arg - The first (and only) argument in the argument list | ||
| 9057 | # | ||
| 9058 | # Return values | ||
| 9059 | # The return value of the function | ||
| 9060 | |||
| 9061 | my ($self, $arg) = @_; | ||
| 9062 | |||
| 9063 | # Local variables | ||
| 9064 | my $obj; | ||
| 9065 | |||
| 9066 | # (No improper arguments to check) | ||
| 9067 | |||
| 9068 | # Evaluate the function and return the value | ||
| 9069 | return $self->scriptObj->name; | ||
| 9070 | } | ||
| 9071 | } | ||
| 9072 | |||
| 9073 | { package Language::Axbasic::Function::Intrinsic::String::showprofile; | ||
| 9074 | |||
| 9075 | use strict; | ||
| 9076 | use warnings; | ||
| 9077 | # use diagnostics; | ||
| 9078 | |||
| 9079 | use Glib qw(TRUE FALSE); | ||
| 9080 | |||
| 9081 | @Language::Axbasic::Function::Intrinsic::String::showprofile::ISA = qw( | ||
| 9082 | Language::Axbasic::Function::Intrinsic::String | ||
| 9083 | ); | ||
| 9084 | |||
| 9085 | # Showprofile$ () | ||
| 9086 | |||
| 9087 | ################## | ||
| 9088 | # Methods | ||
| 9089 | |||
| 9090 | sub evaluate { | ||
| 9091 | |||
| 9092 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 9093 | # | ||
| 9094 | # Expected arguments | ||
| 9095 | # $arg - The first (and only) argument in the argument list | ||
| 9096 | # | ||
| 9097 | # Return values | ||
| 9098 | # The return value of the function | ||
| 9099 | |||
| 9100 | my ($self, $arg) = @_; | ||
| 9101 | |||
| 9102 | # (No improper arguments to check) | ||
| 9103 | |||
| 9104 | # Evaluate the function and return the value | ||
| 9105 | |||
| 9106 | # A value of 'undef' means 'use the current world' | ||
| 9107 | if (! defined $self->scriptObj->useProfile) { | ||
| 9108 | |||
| 9109 | return $self->scriptObj->session->currentWorld->name; | ||
| 9110 | |||
| 9111 | } else { | ||
| 9112 | |||
| 9113 | return $self->scriptObj->useProfile; | ||
| 9114 | } | ||
| 9115 | } | ||
| 9116 | } | ||
| 9117 | |||
| 9118 | { package Language::Axbasic::Function::Intrinsic::String::unabbrevdir; | ||
| 9119 | |||
| 9120 | use strict; | ||
| 9121 | use warnings; | ||
| 9122 | # use diagnostics; | ||
| 9123 | |||
| 9124 | use Glib qw(TRUE FALSE); | ||
| 9125 | |||
| 9126 | @Language::Axbasic::Function::Intrinsic::String::unabbrevdir::ISA = qw( | ||
| 9127 | Language::Axbasic::Function::Intrinsic::String | ||
| 9128 | ); | ||
| 9129 | |||
| 9130 | # Unabbrevdir$ () | ||
| 9131 | |||
| 9132 | ################## | ||
| 9133 | # Methods | ||
| 9134 | |||
| 9135 | sub evaluate { | ||
| 9136 | |||
| 9137 | # Called by LA::Expression::Function->evaluate (using arguments in the form '') | ||
| 9138 | # | ||
| 9139 | # Expected arguments | ||
| 9140 | # $arg - The first (and only) argument in the argument list | ||
| 9141 | # | ||
| 9142 | # Return values | ||
| 9143 | # The return value of the function | ||
| 9144 | |||
| 9145 | my ($self, $arg) = @_; | ||
| 9146 | |||
| 9147 | # (No improper arguments to check) | ||
| 9148 | |||
| 9149 | # Evaluate the function and return the value | ||
| 9150 | return $self->scriptObj->session->currentDict->unabbrevDir($arg); | ||
| 9151 | } | ||
| 9152 | } | ||
| 9153 | |||
| 9154 | # Package must return a true value | ||
| 9155 | 1 |