… | |
… | |
15 | use Crossfire::Protocol::Base 0.95; |
15 | use Crossfire::Protocol::Base 0.95; |
16 | |
16 | |
17 | use base 'Crossfire::Protocol::Base'; |
17 | use base 'Crossfire::Protocol::Base'; |
18 | |
18 | |
19 | sub new { |
19 | sub new { |
20 | my $class = shift; |
20 | my ($class, %arg) = @_; |
21 | |
21 | |
22 | my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); |
22 | my $self = $class->SUPER::new (%arg, |
|
|
23 | setup_req => { |
|
|
24 | extmap => 1, |
|
|
25 | excmd => 1, |
|
|
26 | %{$arg{setup_req} || {}}, |
|
|
27 | }, |
|
|
28 | ); |
23 | |
29 | |
24 | $self->{map_widget}->clr_commands; |
30 | $self->{map_widget}->clr_commands; |
25 | |
31 | |
26 | my @cmd_help = map { |
32 | my @cmd_help = map { |
27 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
33 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
415 | } while $self->{texture}[$id]; |
421 | } while $self->{texture}[$id]; |
416 | |
422 | |
417 | CFPlus::DB::get tilecache => $id, sub { |
423 | CFPlus::DB::get tilecache => $id, sub { |
418 | my ($data) = @_; |
424 | my ($data) = @_; |
419 | |
425 | |
|
|
426 | return unless $self->{map}; # stop when destroyed |
|
|
427 | |
420 | $self->set_texture ($id => $data) |
428 | $self->set_texture ($id => $data) |
421 | if defined $data; |
429 | if defined $data; |
422 | |
430 | |
423 | $self->bg_fetch; |
431 | $self->bg_fetch; |
424 | }; |
432 | }; |
425 | } |
433 | } |
426 | |
434 | |
427 | sub load_map($$$) { |
435 | sub load_map($$$) { |
428 | my ($self, $hash, $x, $y) = @_; |
436 | my ($self, $hash, $x, $y) = @_; |
429 | |
437 | |
|
|
438 | my $gen = $self->{map_change_gen}; |
|
|
439 | |
430 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
440 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
|
|
441 | return unless $gen == $self->{map_change_gen}; |
|
|
442 | |
431 | my ($data) = @_; |
443 | my ($data) = @_; |
432 | |
444 | |
433 | if (defined $data) { |
445 | if (defined $data) { |
434 | $data = Compress::LZF::decompress $data; |
446 | $data = Compress::LZF::decompress $data; |
435 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
447 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
436 | |
448 | |
437 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
449 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
438 | push @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
450 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
439 | $self->bg_fetch unless $inprogress; |
451 | $self->bg_fetch unless $inprogress; |
440 | } |
452 | } |
441 | }; |
453 | }; |
442 | } |
454 | } |
443 | |
455 | |
… | |
… | |
510 | |
522 | |
511 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
523 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
512 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
524 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
513 | |
525 | |
514 | } else { |
526 | } else { |
|
|
527 | my $gen = $self->{map_change_gen}; |
515 | $self->send_mapinfo ("spatial $path$tile", sub { |
528 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
529 | return unless $gen == $self->{map_change_gen}; |
|
|
530 | |
516 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
531 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
517 | |
532 | |
518 | return if $mode ne "spatial"; |
533 | return if $mode ne "spatial"; |
519 | |
534 | |
520 | $x += $self->{map}->ox; |
535 | $x += $self->{map}->ox; |
… | |
… | |
534 | |
549 | |
535 | sub map_change { |
550 | sub map_change { |
536 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
551 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
537 | |
552 | |
538 | $self->flush_map; |
553 | $self->flush_map; |
|
|
554 | |
|
|
555 | ++$self->{map_change_gen}; |
539 | |
556 | |
540 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
557 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
541 | |
558 | |
542 | my $mapmapw = $self->{mapmap}->{w}; |
559 | my $mapmapw = $self->{mapmap}->{w}; |
543 | my $mapmaph = $self->{mapmap}->{h}; |
560 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
583 | if $changed; |
600 | if $changed; |
584 | |
601 | |
585 | $self->set_texture ($face->{id} => delete $face->{image}); |
602 | $self->set_texture ($face->{id} => delete $face->{image}); |
586 | } |
603 | } |
587 | |
604 | |
|
|
605 | sub smooth_update { |
|
|
606 | my ($self, $facenum, $face) = @_; |
|
|
607 | |
|
|
608 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
|
|
609 | } |
|
|
610 | |
588 | sub set_texture { |
611 | sub set_texture { |
589 | my ($self, $id, $data) = @_; |
612 | my ($self, $id, $data) = @_; |
590 | |
613 | |
591 | $self->{texture}[$id] ||= do { |
614 | $self->{texture}[$id] = my $tex = |
592 | my $tex = |
|
|
593 | new_from_image CFPlus::Texture |
615 | new_from_image CFPlus::Texture |
594 | $data, minify => 1, mipmap => 1; |
616 | $data, minify => 1, mipmap => 1; |
595 | |
617 | |
596 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
618 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
597 | $self->{map_widget}->update; |
619 | $self->{map_widget}->update; |
598 | |
|
|
599 | $tex |
|
|
600 | }; |
|
|
601 | } |
620 | } |
602 | |
621 | |
603 | sub sound_play { |
622 | sub sound_play { |
604 | my ($self, $x, $y, $soundnum, $type) = @_; |
623 | my ($self, $x, $y, $soundnum, $type) = @_; |
605 | |
624 | |
… | |
… | |
615 | $LAST_QUERY = $prompt; |
634 | $LAST_QUERY = $prompt; |
616 | |
635 | |
617 | $self->{query}-> ($self, $flags, $prompt); |
636 | $self->{query}-> ($self, $flags, $prompt); |
618 | } |
637 | } |
619 | |
638 | |
620 | sub drawinfo { |
639 | our %NAME_TO_COLOR = ( |
621 | my ($self, $color, $text) = @_; |
640 | black => 0, |
|
|
641 | white => 1, |
|
|
642 | darkblue => 2, |
|
|
643 | red => 3, |
|
|
644 | orange => 4, |
|
|
645 | lightblue => 5, |
|
|
646 | darkorange => 6, |
|
|
647 | green => 7, |
|
|
648 | darkgreen => 8, |
|
|
649 | grey => 9, |
|
|
650 | brown => 10, |
|
|
651 | yellow => 11, |
|
|
652 | tan => 12, |
|
|
653 | ); |
622 | |
654 | |
623 | my @color = ( |
655 | our @CF_COLOR = ( |
624 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
656 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
625 | [1.00, 1.00, 1.00], |
657 | [1.00, 1.00, 1.00], |
626 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
658 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
627 | [1.00, 0.00, 0.00], |
659 | [1.00, 0.00, 0.00], |
628 | [1.00, 0.54, 0.00], |
660 | [1.00, 0.54, 0.00], |
629 | [0.11, 0.56, 1.00], |
661 | [0.11, 0.56, 1.00], |
630 | [0.93, 0.46, 0.00], |
662 | [0.93, 0.46, 0.00], |
631 | [0.18, 0.54, 0.34], |
663 | [0.18, 0.54, 0.34], |
632 | [0.56, 0.73, 0.56], |
664 | [0.56, 0.73, 0.56], |
633 | [0.80, 0.80, 0.80], |
665 | [0.80, 0.80, 0.80], |
634 | [0.75, 0.61, 0.20], |
666 | [0.75, 0.61, 0.20], |
635 | [0.99, 0.77, 0.26], |
667 | [0.99, 0.77, 0.26], |
636 | [0.74, 0.65, 0.41], |
668 | [0.74, 0.65, 0.41], |
637 | ); |
669 | ); |
638 | |
670 | |
639 | my $fg = $color[$color % @color]; |
671 | sub msg { |
|
|
672 | my ($self, $color, $type, $text, @extra) = @_; |
640 | |
673 | |
|
|
674 | if (my $cb = $self->{cb_msg}{$type}) { |
|
|
675 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
|
|
676 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
|
|
677 | $type =~ s/-/_/g; |
|
|
678 | $self->{$type} = $text; |
|
|
679 | } else { |
641 | $self->logprint ("info: ", $text); |
680 | $self->logprint ("msg: ", $text); |
|
|
681 | return if $color < 0; # negative color == ignore if not understood |
642 | |
682 | |
|
|
683 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
|
|
684 | |
643 | # try to create single paragraphs of multiple lines sent by the server |
685 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
686 | # no longer neecssary with TRT servers |
644 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
687 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
645 | |
688 | |
646 | $text = CFPlus::asxml $text; |
|
|
647 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
|
|
648 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
|
|
649 | |
|
|
650 | ::message ({ fg => $fg, markup => $_ }) |
689 | ::message ({ fg => $fg, markup => $_ }) |
651 | for split /\n/, $text; |
690 | for split /\n/, $text; |
652 | |
691 | |
653 | $self->{statusbox}->add ($text, |
692 | $self->{statusbox}->add ($text, |
654 | group => $text, |
693 | group => $text, |
655 | fg => $fg, |
694 | fg => $fg, |
656 | timeout => $color >= 2 ? 180 : 10, |
695 | timeout => $color >= 2 ? 180 : 10, |
657 | tooltip_font => $::FONT_FIXED, |
696 | tooltip_font => $::FONT_FIXED, |
658 | ); |
697 | ); |
659 | } |
698 | } |
660 | |
|
|
661 | sub drawextinfo { |
|
|
662 | my ($self, $color, $type, $subtype, $message) = @_; |
|
|
663 | |
|
|
664 | $self->drawinfo ($color, $message); |
|
|
665 | } |
699 | } |
666 | |
700 | |
667 | sub spell_add { |
701 | sub spell_add { |
668 | my ($self, $spell) = @_; |
702 | my ($self, $spell) = @_; |
669 | |
703 | |
… | |
… | |
902 | $::SERVER_INFO->set_markup ( |
936 | $::SERVER_INFO->set_markup ( |
903 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
937 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
904 | . "protocol version <tt>$self->{version}</tt>\n" |
938 | . "protocol version <tt>$self->{version}</tt>\n" |
905 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
939 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
906 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
940 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
941 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
907 | . "editing support $yesno[!!$self->{editor_support}]\n" |
942 | . "editing support $yesno[!!$self->{editor_support}]\n" |
908 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
943 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
944 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
909 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
945 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
910 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
946 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
911 | . "map size $self->{mapw}×$self->{maph}\n" |
947 | . "map size $self->{mapw}×$self->{maph}\n" |
912 | ); |
948 | ); |
913 | |
949 | |