… | |
… | |
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 |
… | |
… | |
243 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
249 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
244 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
250 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
245 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
251 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
246 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
252 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
247 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
253 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
248 | my $rng = $stats->{+CS_STAT_RANGE}; |
254 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
249 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
250 | $::GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
251 | my $title = $stats->{+CS_STAT_TITLE}; |
255 | my $title = $stats->{+CS_STAT_TITLE}; |
252 | $title =~ s/^Player: //; |
256 | $title =~ s/^Player: //; |
253 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
257 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
254 | |
258 | |
255 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
259 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
… | |
… | |
402 | |
406 | |
403 | $self->{map}->clear; |
407 | $self->{map}->clear; |
404 | delete $self->{map_widget}{magicmap}; |
408 | delete $self->{map_widget}{magicmap}; |
405 | } |
409 | } |
406 | |
410 | |
|
|
411 | sub bg_fetch { |
|
|
412 | my ($self) = @_; |
|
|
413 | |
|
|
414 | my $id; |
|
|
415 | |
|
|
416 | do { |
|
|
417 | $id = pop @{$self->{bg_fetch}} |
|
|
418 | or return; |
|
|
419 | } while $self->{texture}[$id]; |
|
|
420 | |
|
|
421 | CFPlus::DB::get tilecache => $id, sub { |
|
|
422 | my ($data) = @_; |
|
|
423 | |
|
|
424 | return unless $self->{map}; # stop when destroyed |
|
|
425 | |
|
|
426 | $self->set_texture ($id => $data) |
|
|
427 | if defined $data; |
|
|
428 | |
|
|
429 | $self->bg_fetch; |
|
|
430 | }; |
|
|
431 | } |
407 | |
432 | |
408 | sub load_map($$$) { |
433 | sub load_map($$$) { |
409 | my ($self, $hash, $x, $y) = @_; |
434 | my ($self, $hash, $x, $y) = @_; |
410 | |
435 | |
|
|
436 | my $gen = $self->{map_change_gen}; |
|
|
437 | |
411 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
438 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
|
|
439 | return unless $gen == $self->{map_change_gen}; |
|
|
440 | |
412 | my ($data) = @_; |
441 | my ($data) = @_; |
413 | |
442 | |
414 | if (defined $data) { |
443 | if (defined $data) { |
415 | $data = Compress::LZF::decompress $data; |
444 | $data = Compress::LZF::decompress $data; |
416 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
445 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
417 | for my $id ($self->{map}->set_rect ($x, $y, $data)) { |
|
|
418 | CFPlus::DB::get tilecache => $id, sub { |
|
|
419 | my ($data) = @_; |
|
|
420 | |
446 | |
421 | $self->set_texture ($id => $data) |
447 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
422 | if defined $data; |
448 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
423 | }; |
449 | $self->bg_fetch unless $inprogress; |
424 | } |
|
|
425 | } |
450 | } |
426 | }; |
451 | }; |
427 | } |
452 | } |
428 | |
453 | |
429 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
454 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
… | |
… | |
495 | |
520 | |
496 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
521 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
497 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
522 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
498 | |
523 | |
499 | } else { |
524 | } else { |
|
|
525 | my $gen = $self->{map_change_gen}; |
500 | $self->send_mapinfo ("spatial $path$tile", sub { |
526 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
527 | return unless $gen == $self->{map_change_gen}; |
|
|
528 | |
501 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
529 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
502 | |
530 | |
503 | return if $mode ne "spatial"; |
531 | return if $mode ne "spatial"; |
504 | |
532 | |
505 | $x += $self->{map}->ox; |
533 | $x += $self->{map}->ox; |
… | |
… | |
519 | |
547 | |
520 | sub map_change { |
548 | sub map_change { |
521 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
549 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
522 | |
550 | |
523 | $self->flush_map; |
551 | $self->flush_map; |
|
|
552 | |
|
|
553 | ++$self->{map_change_gen}; |
524 | |
554 | |
525 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
555 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
526 | |
556 | |
527 | my $mapmapw = $self->{mapmap}->{w}; |
557 | my $mapmapw = $self->{mapmap}->{w}; |
528 | my $mapmaph = $self->{mapmap}->{h}; |
558 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
568 | if $changed; |
598 | if $changed; |
569 | |
599 | |
570 | $self->set_texture ($face->{id} => delete $face->{image}); |
600 | $self->set_texture ($face->{id} => delete $face->{image}); |
571 | } |
601 | } |
572 | |
602 | |
|
|
603 | sub smooth_update { |
|
|
604 | my ($self, $facenum, $face) = @_; |
|
|
605 | |
|
|
606 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
|
|
607 | } |
|
|
608 | |
573 | sub set_texture { |
609 | sub set_texture { |
574 | my ($self, $id, $data) = @_; |
610 | my ($self, $id, $data) = @_; |
575 | |
611 | |
576 | $self->{texture}[$id] ||= do { |
612 | $self->{texture}[$id] = my $tex = |
577 | my $tex = |
|
|
578 | new_from_image CFPlus::Texture |
613 | new_from_image CFPlus::Texture |
579 | $data, minify => 1, mipmap => 1; |
614 | $data, minify => 1, mipmap => 1; |
580 | |
615 | |
581 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
616 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
582 | $self->{map_widget}->update; |
617 | $self->{map_widget}->update; |
583 | |
|
|
584 | $tex |
|
|
585 | }; |
|
|
586 | } |
618 | } |
587 | |
619 | |
588 | sub sound_play { |
620 | sub sound_play { |
589 | my ($self, $x, $y, $soundnum, $type) = @_; |
621 | my ($self, $x, $y, $soundnum, $type) = @_; |
590 | |
622 | |
… | |
… | |
600 | $LAST_QUERY = $prompt; |
632 | $LAST_QUERY = $prompt; |
601 | |
633 | |
602 | $self->{query}-> ($self, $flags, $prompt); |
634 | $self->{query}-> ($self, $flags, $prompt); |
603 | } |
635 | } |
604 | |
636 | |
605 | sub drawinfo { |
637 | our %NAME_TO_COLOR = ( |
606 | my ($self, $color, $text) = @_; |
638 | black => 0, |
|
|
639 | white => 1, |
|
|
640 | darkblue => 2, |
|
|
641 | red => 3, |
|
|
642 | orange => 4, |
|
|
643 | lightblue => 5, |
|
|
644 | darkorange => 6, |
|
|
645 | green => 7, |
|
|
646 | darkgreen => 8, |
|
|
647 | grey => 9, |
|
|
648 | brown => 10, |
|
|
649 | yellow => 11, |
|
|
650 | tan => 12, |
|
|
651 | ); |
607 | |
652 | |
608 | my @color = ( |
653 | our @CF_COLOR = ( |
609 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
654 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
610 | [1.00, 1.00, 1.00], |
655 | [1.00, 1.00, 1.00], |
611 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
656 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
612 | [1.00, 0.00, 0.00], |
657 | [1.00, 0.00, 0.00], |
613 | [1.00, 0.54, 0.00], |
658 | [1.00, 0.54, 0.00], |
614 | [0.11, 0.56, 1.00], |
659 | [0.11, 0.56, 1.00], |
615 | [0.93, 0.46, 0.00], |
660 | [0.93, 0.46, 0.00], |
616 | [0.18, 0.54, 0.34], |
661 | [0.18, 0.54, 0.34], |
617 | [0.56, 0.73, 0.56], |
662 | [0.56, 0.73, 0.56], |
618 | [0.80, 0.80, 0.80], |
663 | [0.80, 0.80, 0.80], |
619 | [0.75, 0.61, 0.20], |
664 | [0.75, 0.61, 0.20], |
620 | [0.99, 0.77, 0.26], |
665 | [0.99, 0.77, 0.26], |
621 | [0.74, 0.65, 0.41], |
666 | [0.74, 0.65, 0.41], |
622 | ); |
667 | ); |
623 | |
668 | |
624 | my $fg = $color[$color % @color]; |
669 | sub msg { |
|
|
670 | my ($self, $color, $type, $text, @extra) = @_; |
625 | |
671 | |
|
|
672 | if (my $cb = $self->{cb_msg}{$type}) { |
|
|
673 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
|
|
674 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
|
|
675 | $type =~ s/-/_/g; |
|
|
676 | $self->{$type} = $text; |
|
|
677 | } else { |
626 | $self->logprint ("info: ", $text); |
678 | $self->logprint ("msg: ", $text); |
|
|
679 | return if $color < 0; # negative color == ignore if not understood |
627 | |
680 | |
|
|
681 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
|
|
682 | |
628 | # try to create single paragraphs of multiple lines sent by the server |
683 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
684 | # no longer neecssary with TRT servers |
629 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
685 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
630 | |
686 | |
631 | $text = CFPlus::asxml $text; |
|
|
632 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
|
|
633 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
|
|
634 | |
|
|
635 | ::message ({ fg => $fg, markup => $_ }) |
687 | ::message ({ fg => $fg, markup => $_ }) |
636 | for split /\n/, $text; |
688 | for split /\n/, $text; |
637 | |
689 | |
638 | $self->{statusbox}->add ($text, |
690 | $self->{statusbox}->add ($text, |
639 | group => $text, |
691 | group => $text, |
640 | fg => $fg, |
692 | fg => $fg, |
641 | timeout => $color >= 2 ? 180 : 10, |
693 | timeout => $color >= 2 ? 180 : 10, |
642 | tooltip_font => $::FONT_FIXED, |
694 | tooltip_font => $::FONT_FIXED, |
643 | ); |
695 | ); |
644 | } |
696 | } |
645 | |
|
|
646 | sub drawextinfo { |
|
|
647 | my ($self, $color, $type, $subtype, $message) = @_; |
|
|
648 | |
|
|
649 | $self->drawinfo ($color, $message); |
|
|
650 | } |
697 | } |
651 | |
698 | |
652 | sub spell_add { |
699 | sub spell_add { |
653 | my ($self, $spell) = @_; |
700 | my ($self, $spell) = @_; |
654 | |
701 | |
… | |
… | |
887 | $::SERVER_INFO->set_markup ( |
934 | $::SERVER_INFO->set_markup ( |
888 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
935 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
889 | . "protocol version <tt>$self->{version}</tt>\n" |
936 | . "protocol version <tt>$self->{version}</tt>\n" |
890 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
937 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
891 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
938 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
939 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
892 | . "editing support $yesno[!!$self->{editor_support}]\n" |
940 | . "editing support $yesno[!!$self->{editor_support}]\n" |
893 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
941 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
942 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
894 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
943 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
895 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
944 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
896 | . "map size $self->{mapw}×$self->{maph}\n" |
945 | . "map size $self->{mapw}×$self->{maph}\n" |
897 | ); |
946 | ); |
898 | |
947 | |