1#!/usr/bin/perl 2 3use strict; 4 5die "usage: $0 <tilename> <base> <image>" if @ARGV < 3; 6 7open DATE, "date |" or die; 8my $date = ''; 9while(my $line = <DATE>) { 10 chomp $line; 11 $date .= $line; 12} 13close DATE; 14 15my $command_line = "$0 " . (join ' ', @ARGV); 16print "# Generated on $date using:\n# $command_line\n"; 17 18print "{\n"; 19 20my $tilename = shift @ARGV; 21my $base = shift @ARGV; 22my $image = shift @ARGV; 23 24$tilename = "($tilename)" if $tilename =~ /[a-zA-Z0-9]+/; 25 26my $solid = ''; 27my $grass = ''; 28my $friend = $tilename; 29my $noslopes = 0; 30 31while(my $arg = shift @ARGV) { 32 if($arg eq '--solid') { 33 $solid = "solid=" . (shift @ARGV); 34 } elsif($arg eq '--friend') { 35 $friend = shift @ARGV; 36 } elsif($arg eq '--noslopes') { 37 $noslopes = 1; 38 } else { 39 die "Unrecognized argument: $arg"; 40 } 41} 42 43while((length $tilename) < 3) { 44 $tilename = " $tilename"; 45} 46 47print "tile_pattern: [\n"; 48 49printf qq~ 50{ 51#horizontal tile 52image=$image 53tiles=%s 54%s 55pattern=" 56.* , ,.* , 57$friend,$tilename,$friend, 58.* , ,.* " 59}, 60~, &coord($base, 3, 1), $solid ; 61 62printf qq~ 63#horizontal tile with one tile below but not on either side 64{ 65image=$image 66tiles=%s 67%s 68pattern=" 69.* , ,.* , 70$friend,$tilename,$friend, 71 ,$friend, " 72}, 73~, &coord($base, 0, 5), $solid; 74 75printf qq~ 76#horizontal tile with one tile above but not on either side 77{ 78image=$image 79tiles=%s 80%s 81pattern=" 82 ,$friend, , 83$friend,$tilename,$friend, 84.* , , .*" 85}, 86~, &coord($base, 2, 5), $solid; 87 88printf qq~ 89#overhang 90{ 91image=$image 92reverse=no 93tiles=%s 94%s 95pattern=" 96.* , ,.* , 97 ,$tilename,$friend, 98.* , ,.* " 99}, 100~, &coord($base, 3, 0), $solid; 101 102printf qq~ 103#overhang - reversed 104{ 105image=$image 106reverse=no 107tiles=%s 108%s 109pattern=" 110.* , ,.* , 111$friend,$tilename, , 112.* , ,.* " 113}, 114~, &coord($base, 3, 2), $solid; 115 116printf qq~ 117#sloped 118{ 119image=$image 120reverse=no 121tiles=%s 122%s 123pattern=" 124 , ,$friend?, 125 ,$tilename,$friend, 126$friend,$friend,$friend" 127}, 128~, &coord($base, 0, $noslopes ? 0 : 7), (($solid eq 'solid=yes' and not $noslopes) ? 'solid=diagonal' : $solid); 129 130printf qq~ 131#sloped - tile immediately beneath 132{ 133image=$image 134reverse=no 135tiles=%s 136%s 137pattern=" 138.*, , ,$friend?,.*, 139.*, ,$friend,$friend,.*, 140.*,$friend,$tilename,$friend,.*, 141.*,$friend,$friend,$friend,.*, 142.*,.*,.*,.*,.*" 143}, 144~, &coord($base, $noslopes ? 5 : 1, $noslopes ? 1 : 7), $solid; 145 146 147printf qq~ 148#sloped - reversed 149{ 150image=$image 151reverse=no 152tiles=%s 153%s 154pattern=" 155$friend?, , , 156$friend,$tilename, , 157$friend,$friend,$friend" 158}, 159~, &coord($base, 0, $noslopes ? 2 : 8), (($solid eq 'solid=yes' and not $noslopes) ? 'solid=reverse_diagonal' : $solid); 160 161printf qq~ 162#sloped - reversed - tile immediately beneath 163{ 164image=$image 165reverse=no 166tiles=%s 167%s 168pattern=" 169.*,$friend?, , ,.*, 170.*,$friend,$friend, ,.*, 171.*,$friend,$tilename,$friend,.*, 172.*,$friend,$friend,$friend,.*, 173.*,.*,.*,.*,.*" 174}, 175~, &coord($base, $noslopes ? 5 : 1, $noslopes ? 0 : 8), $solid; 176 177 178printf qq~ 179#single tile by itself 180{ 181image=$image 182tiles=%s 183%s 184pattern=" 185 .*, , .*, 186 ,$tilename, , 187 .*, , .*" 188}, 189~, &coord($base, 3, 3), $solid; 190 191printf qq~ 192#top of thin platform 193{ 194image=$image 195tiles=%s 196%s 197pattern=" 198 .*, , .*, 199 ,$tilename, , 200 .*,$friend, .*" 201}, 202~, &coord($base, 0, 3), $solid; 203 204printf qq~ 205#part of thin platform 206{ 207image=$image 208tiles=%s 209$solid 210pattern=" 211 .*,$friend, .*, 212 ,$tilename, , 213 .*,$friend, .*" 214}, 215~, &coord($base, 1, 3); 216 217printf qq~ 218#bottom of thin platform 219{ 220image=$image 221tiles=%s 222$solid 223pattern=" 224 .*,$friend, .*, 225 ,$tilename, , 226 .*, , .*" 227}, 228~, &coord($base, 2, 3); 229 230printf qq~ 231#cliff edge 232{ 233image=$image 234reverse=no 235tiles=%s 236%s 237pattern=" 238 .*, ,$friend?, 239 ,$tilename,$friend , 240$friend?,$friend,$friend " 241}, 242~, &coord($base, 0, 0), $solid; 243 244printf qq~ 245#cliff edge - reverse 246{ 247image=$image 248reverse=no 249tiles=%s 250%s 251pattern=" 252$friend?, ,.* , 253$friend,$tilename, , 254$friend,$friend,$friend?" 255}, 256~, &coord($base, 0, 2), $solid; 257 258printf qq~ 259#cliff edge -- version with a corner underneath/opposite 260{ 261image=$image 262reverse=no 263tiles=%s 264%s 265pattern=" 266 .*, ,$friend?, 267 ,$tilename,$friend , 268$friend?,$friend, " 269}, 270~, &coord($base, 0, 6), $solid; 271 272printf qq~ 273#cliff edge (reversed) -- version with a corner underneath/opposite 274{ 275image=$image 276reverse=no 277tiles=%s 278%s 279pattern=" 280$friend?, ,.*, 281$friend,$tilename, , 282 ,$friend,$friend?" 283}, 284~, &coord($base, 0, 4), $solid; 285 286printf qq~ 287#middle of a cross 288{ 289image=$image 290tiles=%s 291$solid 292pattern=" 293 ,$friend, , 294$friend,$tilename,$friend , 295 ,$friend, " 296}, 297~, &coord($base, 1, 5); 298 299printf qq~ 300#corner at two angles 301{ 302image=$image 303reverse=no 304tiles=%s 305$solid 306pattern=" 307$friend,$friend, , 308$friend,$tilename,$friend, 309 ,$friend,$friend" 310}, 311~, &coord($base, 3, 5); 312 313printf qq~ 314#corner at two angles (reversed) 315{ 316image=$image 317reverse=no 318tiles=%s 319$solid 320pattern=" 321 ,$friend,$friend, 322$friend,$tilename,$friend, 323$friend,$friend, " 324}, 325~, &coord($base, 3, 4); 326 327printf qq~ 328#corners on the top 329{ 330image=$image 331tiles=%s 332$solid 333pattern=" 334 ,$friend, , 335$friend,$tilename,$friend, 336$friend,$friend,$friend" 337}, 338~, &coord($base, 5, 8); 339 340printf qq~ 341#corners on the bottom 342{ 343image=$image 344tiles=%s 345$solid 346pattern=" 347$friend,$tilename,$friend, 348$friend,$tilename,$friend, 349 ,$friend, " 350}, 351~, &coord($base, 4, 8); 352 353printf qq~ 354#corners both on the same side 355{ 356image=$image 357reverse=no 358tiles=%s 359$solid 360pattern=" 361 ,$friend,$friend, 362$friend,$tilename,$friend, 363 ,$friend,$friend" 364}, 365~, &coord($base, 4, 7); 366 367printf qq~ 368#corners both on the same side (reversed) 369{ 370image=$image 371reverse=no 372tiles=%s 373$solid 374pattern=" 375$friend,$friend, , 376$friend,$tilename,$friend, 377$friend,$friend, " 378}, 379~, &coord($base, 4, 6); 380 381printf qq~ 382#inner top corner piece 383{ 384image=$image 385reverse=no 386tiles=%s 387$solid 388pattern=" 389$friend,$friend,$friend, 390$friend,$tilename,$friend, 391 ,$friend,$friend" 392}, 393~, &coord($base, 4, 1); 394 395printf qq~ 396#inner top corner piece (reversed) 397{ 398image=$image 399reverse=no 400tiles=%s 401$solid 402pattern=" 403$friend,$friend,$friend, 404$friend,$tilename,$friend, 405$friend,$friend, " 406}, 407~, &coord($base, 4, 0); 408 409printf qq~ 410#inner bottom corner piece 411{ 412image=$image 413reverse=no 414tiles=%s 415$solid 416pattern=" 417 ,$friend,$friend, 418$friend,$tilename,$friend, 419$friend,$friend,$friend" 420}, 421~, &coord($base, 5, 1); 422 423printf qq~ 424#inner bottom corner piece (reversed) 425{ 426image=$image 427reverse=no 428tiles=%s 429$solid 430pattern=" 431$friend,$friend, , 432$friend,$tilename,$friend, 433$friend,$friend,$friend" 434}, 435~, &coord($base, 5, 0); 436 437printf qq~ 438#corner at three sides 439{ 440image=$image 441reverse=no 442tiles=%s 443$solid 444pattern=" 445 ,$friend,$friend, 446$friend,$tilename,$friend, 447 ,$friend, " 448}, 449~, &coord($base, 4, 3); 450 451printf qq~ 452#corner at three sides (reversed) 453{ 454image=$image 455reverse=no 456tiles=%s 457$solid 458pattern=" 459$friend,$friend, , 460$friend,$tilename,$friend, 461 ,$friend, " 462}, 463~, &coord($base, 4, 2); 464 465printf qq~ 466#corner at three sides 467{ 468image=$image 469reverse=no 470tiles=%s 471$solid 472pattern=" 473 ,$friend, , 474$friend,$tilename,$friend, 475 ,$friend,$friend" 476}, 477~, &coord($base, 5, 3); 478 479printf qq~ 480#corner at three sides (reversed) 481{ 482image=$image 483reverse=no 484tiles=%s 485$solid 486pattern=" 487 ,$friend, , 488$friend,$tilename,$friend, 489$friend,$friend, " 490}, 491~, &coord($base, 5, 2); 492 493printf qq~ 494#roof at a corner 495{ 496image=$image 497reverse=no 498tiles=%s 499$solid 500pattern=" 501 ,$friend,$friend, 502$friend,$tilename,$friend, 503 .*, , .*" 504}, 505~, &coord($base, 5, 7); 506 507printf qq~ 508#roof at a corner (reversed) 509{ 510image=$image 511reverse=no 512tiles=%s 513$solid 514pattern=" 515$friend,$friend, , 516$friend,$tilename,$friend, 517 .*, , .*" 518}, 519~, &coord($base, 5, 6); 520 521printf qq~ 522#roof 523{ 524image=$image 525tiles=%s 526$solid 527pattern=" 528.* ,$friend, .*, 529$friend,$tilename,$friend, 530 .*, , .*" 531}, 532~, &coord($base, 2, 1); 533 534printf qq~ 535#bottom corner 536{ 537image=$image 538reverse=no 539tiles=%s 540$solid 541pattern=" 542$friend?,$friend,$friend, 543 ,$tilename,$friend, 544.* , , .*" 545}, 546~, &coord($base, 2, 0); 547 548printf qq~ 549#bottom corner (reversed) 550{ 551image=$image 552reverse=no 553tiles=%s 554$solid 555pattern=" 556$friend,$friend,$friend?, 557$friend,$tilename, , 558.* , , .*" 559}, 560~, &coord($base, 2, 2); 561 562printf qq~ 563#bottom corner with corner on opposite side 564{ 565image=$image 566reverse=no 567tiles=%s 568$solid 569pattern=" 570$friend?,$friend, , 571 ,$tilename,$friend, 572.* , , .*" 573}, 574~, &coord($base, 2, 6); 575 576printf qq~ 577#bottom corner with corner on opposite side (reversed) 578{ 579image=$image 580reverse=no 581tiles=%s 582$solid 583pattern=" 584 ,$friend,$friend?, 585$friend,$tilename, , 586.* , , .*" 587}, 588~, &coord($base, 2, 4); 589 590printf qq~ 591#solid 592{ 593image=$image 594tiles=%s 595$solid 596pattern=" 597$friend?,$friend,$friend?, 598$friend,$tilename,$friend, 599$friend?,$friend,$friend?" 600}, 601~, &coord($base, 1, 1); 602 603printf qq~ 604#cliff face coming up from a one-tile thick cliff and expanding out 605#in one direction 606{ 607image=$image 608reverse=no 609tiles=%s 610$solid 611pattern=" 612$friend,$friend,.* , 613$friend,$tilename, , 614 ,$friend,.* " 615}, 616~, &coord($base, 4, 5); 617 618printf qq~ 619#cliff face coming up from a one-tile thick cliff and expanding out 620#in one direction (reversed) 621{ 622image=$image 623reverse=no 624tiles=%s 625$solid 626pattern=" 627.* ,$friend,$friend, 628 ,$tilename,$friend, 629.* ,$friend, " 630}, 631~, &coord($base, 4, 4); 632 633printf qq~ 634#cliff face coming down from a one-tile thick cliff and expanding out 635#in one direction 636{ 637image=$image 638reverse=no 639tiles=%s 640$solid 641pattern=" 642 ,$friend,.* , 643$friend,$tilename, , 644$friend,$friend,.* " 645}, 646~, &coord($base, 5, 5); 647 648printf qq~ 649#cliff face coming down from a one-tile thick cliff and expanding out 650#in one direction (reversed) 651{ 652image=$image 653reverse=no 654tiles=%s 655$solid 656pattern=" 657.* ,$friend, , 658 ,$tilename,$friend, 659.* ,$friend,$friend" 660}, 661~, &coord($base, 5, 4); 662 663printf qq~ 664#cliff face coming both up and down from a one-tile thick cliff and expanding 665#out into a ledge in one direction 666{ 667image=$image 668reverse=no 669tiles=%s 670$solid 671pattern=" 672 ,$friend,.* , 673$friend,$tilename, , 674 ,$friend,.* " 675}, 676~, &coord($base, 1, 4); 677 678printf qq~ 679#cliff face coming both up and down from a one-tile thick cliff and expanding 680#out into a ledge in one direction (reversed) 681{ 682image=$image 683reverse=no 684tiles=%s 685$solid 686pattern=" 687.* ,$friend, , 688 ,$tilename,$friend, 689.* ,$friend, " 690}, 691~, &coord($base, 1, 6); 692 693printf qq~ 694#cliff face 695{ 696image=$image 697reverse=no 698tiles=%s 699$solid 700pattern=" 701.* ,$friend,.* , 702 ,$tilename,$friend, 703.* ,$friend,.* " 704}, 705~, &coord($base, 1, 0); 706 707printf qq~ 708#cliff face (reversed) 709{ 710image=$image 711reverse=no 712tiles=%s 713$solid 714pattern=" 715.* ,$friend,.* , 716$friend,$tilename, , 717.* ,$friend,.* " 718}, 719~, &coord($base, 1, 2); 720 721printf qq~ 722#ground - with a corner on one side beneath 723{ 724image=$image 725reverse=no 726tiles=%s 727%s 728pattern=" 729.* , ,.* , 730$friend,$tilename,$friend, 731 ,$friend,$friend" 732}, 733~, &coord($base, 3, 7), $solid; 734 735printf qq~ 736#ground - with a corner on one side beneath (reversed) 737{ 738image=$image 739reverse=no 740tiles=%s 741%s 742pattern=" 743.* , ,.* , 744$friend,$tilename,$friend, 745$friend,$friend, " 746}, 747~, &coord($base, 3, 6), $solid; 748 749printf qq~ 750#ground 751{ 752image=$image 753tiles=%s 754%s 755pattern=" 756$friend?, ,$friend?, 757$friend ,$tilename ,$friend , 758$friend?,$friend?,$friend?" 759}, 760~, &coord($base, 0, 1), $solid; 761 762sub base_unencode($) { 763 my $base = lc(shift @_); 764 $base = 10 + ord($base) - ord('a') if ord($base) >= ord('a') and ord($base) <= ord('z'); 765 return $base; 766} 767 768sub base_encode($) { 769 my $val = shift @_; 770 $val = chr(ord('a') + ($val - 10)) if $val >= 10; 771 return $val; 772} 773 774sub coord($$$) { 775 my ($base, $row, $col) = @_; 776 my @base = split //, $base; 777 $row += &base_unencode($base[0]); 778 $col += &base_unencode($base[1]); 779 780 return &base_encode($row) . &base_encode($col); 781} 782 783print "]\n}\n"; 784