… | |
… | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Time::HiRes 'time'; |
6 | use Time::HiRes 'time'; |
7 | use Event; |
7 | use Event; |
8 | |
|
|
9 | use SDL; |
|
|
10 | use SDL::App; |
|
|
11 | use SDL::Event; |
|
|
12 | use SDL::Surface; |
|
|
13 | |
|
|
14 | use SDL::Mixer; |
|
|
15 | use SDL::Sound; |
|
|
16 | use SDL::Music; |
|
|
17 | |
|
|
18 | use SDL::OpenGL; |
|
|
19 | |
8 | |
20 | use Crossfire; |
9 | use Crossfire; |
21 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
22 | |
11 | |
23 | use Compress::LZF; |
12 | use Compress::LZF; |
… | |
… | |
58 | our $METASERVER; |
47 | our $METASERVER; |
59 | |
48 | |
60 | our $GAUGES; |
49 | our $GAUGES; |
61 | |
50 | |
62 | our $SDL_ACTIVE; |
51 | our $SDL_ACTIVE; |
63 | our $SDL_EV; |
|
|
64 | our %SDL_CB; |
52 | our %SDL_CB; |
65 | |
53 | |
66 | our $SDL_MIXER; |
54 | our $SDL_MIXER; |
67 | our @SOUNDS; # event => file mapping |
55 | our @SOUNDS; # event => file mapping |
68 | our %AUDIO_CHUNKS; # audio files |
56 | our %AUDIO_CHUNKS; # audio files |
… | |
… | |
110 | undef $CONN; |
98 | undef $CONN; |
111 | } |
99 | } |
112 | |
100 | |
113 | sub client_setup { |
101 | sub client_setup { |
114 | my $dialog = new CFClient::UI::FancyFrame |
102 | my $dialog = new CFClient::UI::FancyFrame |
|
|
103 | title => "Client Setup", |
115 | child => (my $vbox = new CFClient::UI::VBox); |
104 | child => (my $vbox = new CFClient::UI::VBox); |
116 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup"); |
|
|
117 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
105 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
118 | |
106 | |
119 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
107 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
120 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
108 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
121 | |
109 | |
122 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
110 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
123 | $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); |
111 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
124 | |
112 | |
125 | $mode_slider->connect (changed => sub { |
113 | $mode_slider->connect (changed => sub { |
126 | my ($self, $value) = @_; |
114 | my ($self, $value) = @_; |
127 | |
115 | |
128 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
116 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
… | |
… | |
188 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
176 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
189 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
177 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
190 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
178 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
191 | $CFG->{bgm_enable} = $_[1]; |
179 | $CFG->{bgm_enable} = $_[1]; |
192 | }); |
180 | }); |
193 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { |
181 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
194 | $CFG->{bgm_volume} = $_[1]; |
182 | $CFG->{bgm_volume} = $_[1]; |
195 | $SDL_MIXER->music_volume ($_[1]); |
183 | CFClient::MixMusic::volume $_[1] * 128; |
196 | }); |
184 | }); |
197 | |
185 | |
198 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
186 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
199 | audio_shutdown (); |
187 | audio_shutdown (); |
200 | audio_init (); |
188 | audio_init (); |
… | |
… | |
203 | $dialog |
191 | $dialog |
204 | } |
192 | } |
205 | |
193 | |
206 | sub metaserver_dialog { |
194 | sub metaserver_dialog { |
207 | my $dialog = new CFClient::UI::FancyFrame |
195 | my $dialog = new CFClient::UI::FancyFrame |
|
|
196 | title => "Metaserver", |
208 | child => (my $vbox = new CFClient::UI::VBox); |
197 | child => (my $vbox = new CFClient::UI::VBox); |
209 | |
198 | |
210 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
199 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
211 | |
200 | |
212 | $dialog |
201 | $dialog |
… | |
… | |
278 | }); |
267 | }); |
279 | } |
268 | } |
280 | |
269 | |
281 | sub server_setup { |
270 | sub server_setup { |
282 | my $dialog = new CFClient::UI::FancyFrame |
271 | my $dialog = new CFClient::UI::FancyFrame |
|
|
272 | title => "Server Setup", |
283 | child => (my $vbox = new CFClient::UI::VBox); |
273 | child => (my $vbox = new CFClient::UI::VBox); |
284 | |
274 | |
285 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup"); |
|
|
286 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
275 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
287 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
276 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
288 | |
277 | |
289 | { |
278 | { |
290 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
279 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
… | |
… | |
337 | $dialog |
326 | $dialog |
338 | } |
327 | } |
339 | |
328 | |
340 | sub message_window { |
329 | sub message_window { |
341 | my $window = new CFClient::UI::FancyFrame |
330 | my $window = new CFClient::UI::FancyFrame |
|
|
331 | title => "Messages", |
342 | border_bg => [1, 1, 1, 0.5], |
332 | border_bg => [1, 1, 1, 0.5], |
343 | bg => [0.3, 0.3, 0.3, 0.8], |
333 | bg => [0.3, 0.3, 0.3, 0.8], |
344 | user_w => int $::WIDTH / 3, |
334 | user_w => int $::WIDTH / 3, |
345 | user_h => int $::HEIGHT / 5, |
335 | user_h => int $::HEIGHT / 5, |
346 | child => (my $vbox = new CFClient::UI::VBox); |
336 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
388 | |
378 | |
389 | $window |
379 | $window |
390 | } |
380 | } |
391 | |
381 | |
392 | sub sdl_init { |
382 | sub sdl_init { |
393 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
383 | CFClient::SDL_Init |
394 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
395 | and die "SDL::Init failed!\n"; |
384 | and die "SDL::Init failed!\n"; |
396 | } |
385 | } |
397 | |
386 | |
398 | sub video_init { |
387 | sub video_init { |
399 | sdl_init; |
388 | sdl_init; |
400 | |
389 | |
401 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
390 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
402 | $FULLSCREEN = $CFG->{fullscreen}; |
391 | $FULLSCREEN = $CFG->{fullscreen}; |
403 | $FAST = $CFG->{fast}; |
392 | $FAST = $CFG->{fast}; |
404 | |
393 | |
405 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
394 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
406 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
407 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
408 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
|
|
409 | |
|
|
410 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
411 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
412 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
413 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
414 | |
|
|
415 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
416 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
417 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
418 | |
|
|
419 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
420 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
421 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
422 | or die "SDL::SetVideoMode failed!\n"; |
395 | or die "SDL_SetVideoMode failed!\n"; |
423 | |
|
|
424 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
425 | |
|
|
426 | $SDL_EV = new SDL::Event; |
|
|
427 | $SDL_EV->set_unicode (1); |
|
|
428 | |
396 | |
429 | $SDL_ACTIVE = 1; |
397 | $SDL_ACTIVE = 1; |
430 | |
398 | |
431 | $LAST_REFRESH = time - 0.01; |
399 | $LAST_REFRESH = time - 0.01; |
432 | |
400 | |
… | |
… | |
477 | status "Configuration Saved"; |
445 | status "Configuration Saved"; |
478 | }); |
446 | }); |
479 | |
447 | |
480 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
448 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
481 | |
449 | |
482 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
450 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats"); |
483 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
451 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
484 | |
452 | |
485 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
453 | $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp')); |
486 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
454 | $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana')); |
487 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
455 | $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace')); |
488 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
456 | $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food')); |
489 | |
457 | |
490 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
458 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
491 | $CFClient::UI::ROOT->add ($tgw); |
459 | $CFClient::UI::ROOT->add ($tgw); |
492 | } |
460 | } |
493 | |
461 | |
494 | sub video_shutdown { |
462 | sub video_shutdown { |
495 | $CFClient::UI::ROOT->{children} = []; |
463 | $CFClient::UI::ROOT->{children} = []; |
496 | undef $SDL_ACTIVE; |
464 | undef $SDL_ACTIVE; |
497 | undef $SDL_EV; |
|
|
498 | } |
465 | } |
499 | |
466 | |
500 | my $bgmusic;#TODO#hack#d# |
467 | my $bgmusic;#TODO#hack#d# |
501 | |
468 | |
502 | sub audio_init { |
469 | sub audio_init { |
503 | if ($CFG->{audio_enable}) { |
470 | if ($CFG->{audio_enable}) { |
504 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
471 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
505 | |
472 | |
506 | $SDL_MIXER = new SDL::Mixer |
473 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
507 | -rate => 22050, |
474 | CFClient::Mix_AllocateChannels 8; |
508 | -channels => 1, # mono |
475 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
509 | -size => 512; |
|
|
510 | |
|
|
511 | $SDL_MIXER->allocate_channels (8); |
|
|
512 | |
476 | |
513 | # TODO: hack, do play loop and mood music |
477 | # TODO: hack, do play loop and mood music |
514 | if ($CFG->{bgm_enable}) { |
478 | if ($CFG->{bgm_enable}) { |
515 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
479 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg"; |
516 | $SDL_MIXER->play_music ($bgmusic, -1); |
480 | $bgmusic->play; |
517 | $SDL_MIXER->music_volume ($CFG->{bgm_volume}); |
|
|
518 | } |
481 | } |
519 | |
482 | |
520 | while (<$fh>) { |
483 | while (<$fh>) { |
521 | next if /^\s*#/; |
484 | next if /^\s*#/; |
522 | next if /^\s*$/; |
485 | next if /^\s*$/; |
… | |
… | |
524 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
487 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
525 | |
488 | |
526 | push @SOUNDS, "$volume,$file"; |
489 | push @SOUNDS, "$volume,$file"; |
527 | |
490 | |
528 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
491 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
529 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
492 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
530 | $chunk->volume ($volume * 128 / 100); |
493 | $chunk->volume ($volume * 128 / 100); |
531 | $chunk |
494 | $chunk |
532 | }; |
495 | }; |
533 | } |
496 | } |
534 | } else { |
497 | } else { |
… | |
… | |
536 | } |
499 | } |
537 | } |
500 | } |
538 | } |
501 | } |
539 | |
502 | |
540 | sub audio_shutdown { |
503 | sub audio_shutdown { |
|
|
504 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
541 | undef $SDL_MIXER; |
505 | undef $SDL_MIXER; |
542 | @SOUNDS = (); |
506 | @SOUNDS = (); |
543 | %AUDIO_CHUNKS = (); |
507 | %AUDIO_CHUNKS = (); |
544 | } |
508 | } |
545 | |
509 | |
… | |
… | |
558 | $want_refresh = 0; |
522 | $want_refresh = 0; |
559 | $can_refresh = 0; |
523 | $can_refresh = 0; |
560 | |
524 | |
561 | $CFClient::UI::ROOT->draw; |
525 | $CFClient::UI::ROOT->draw; |
562 | |
526 | |
563 | SDL::GLSwapBuffers; |
527 | CFClient::SDL_GL_SwapBuffers; |
564 | |
528 | |
565 | $LAST_REFRESH = $NOW; |
529 | $LAST_REFRESH = $NOW; |
566 | } |
530 | } |
567 | |
531 | |
568 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
532 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
569 | $NOW = time; |
533 | $NOW = time; |
570 | |
534 | |
571 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
535 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
572 | while $SDL_EV->poll; |
536 | for CFClient::SDL_PollEvent; |
573 | |
537 | |
574 | if (%animate_object) { |
538 | if (%animate_object) { |
575 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
539 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
576 | $want_refresh++; |
540 | $want_refresh++; |
577 | } |
541 | } |
… | |
… | |
607 | my $hp = $stats->{1}; |
571 | my $hp = $stats->{1}; |
608 | my $hp_m = $stats->{2}; |
572 | my $hp_m = $stats->{2}; |
609 | my $sp = $stats->{3}; |
573 | my $sp = $stats->{3}; |
610 | my $sp_m = $stats->{4}; |
574 | my $sp_m = $stats->{4}; |
611 | my $fo = $stats->{18}; |
575 | my $fo = $stats->{18}; |
612 | my $fo_m = 1000; |
576 | my $fo_m = 999; |
613 | my $gr = $stats->{23}; |
577 | my $gr = $stats->{23}; |
614 | my $gr_m = $stats->{24}; |
578 | my $gr_m = $stats->{24}; |
615 | |
579 | |
616 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
580 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
617 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
581 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
618 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
582 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
619 | $GAUGES->{food}->set_value ($fo, $fo_m); |
583 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
620 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
584 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
621 | } |
585 | } |
622 | |
586 | |
623 | sub conn::user_send { |
587 | sub conn::user_send { |
624 | my ($self, $command) = @_; |
588 | my ($self, $command) = @_; |
… | |
… | |
659 | |
623 | |
660 | sub conn::map_clear { |
624 | sub conn::map_clear { |
661 | my ($self) = @_; |
625 | my ($self) = @_; |
662 | |
626 | |
663 | $self->flush_map; |
627 | $self->flush_map; |
664 | delete $self->{neigh}; |
628 | delete $self->{neigh_map}; |
665 | |
629 | |
666 | $MAP->clear; |
630 | $MAP->clear; |
667 | } |
631 | } |
668 | |
632 | |
669 | |
633 | |
… | |
… | |
681 | } |
645 | } |
682 | } |
646 | } |
683 | } |
647 | } |
684 | |
648 | |
685 | sub conn::flood_fill { |
649 | sub conn::flood_fill { |
686 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
650 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
687 | |
651 | |
688 | # the server does not allow map paths > 6 |
652 | # the server does not allow map paths > 6 |
689 | return if 6 <= length $path; |
653 | return if 6 <= length $path; |
690 | |
654 | |
691 | for my $tile (1..4) { |
655 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
692 | next if $self->{neigh}{$hash}[$tile]; |
656 | |
|
|
657 | for ( |
|
|
658 | [1, 0, -1], |
|
|
659 | [2, 1, 0], |
|
|
660 | [3, 0, 1], |
|
|
661 | [4, -1, 0], |
|
|
662 | ) { |
|
|
663 | my ($tile, $dx, $dy) = @$_; |
|
|
664 | |
|
|
665 | my $gx = $gx + $dx; |
|
|
666 | my $gy = $gy + $dy; |
|
|
667 | |
693 | next unless $flags & (1 << ($tile - 1)); |
668 | next unless $flags & (1 << ($tile - 1)); |
|
|
669 | next if $self->{neigh_grid}{$gx, $gy}++; |
694 | |
670 | |
695 | my $neigh = $self->{neigh}{$hash} ||= []; |
671 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
696 | |
672 | if (my $info = $neigh->[$tile]) { |
697 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
698 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
673 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
699 | |
674 | |
700 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
701 | return if $mode ne "spatial"; |
|
|
702 | |
|
|
703 | $x += $MAP->ox; |
|
|
704 | $y += $MAP->oy; |
|
|
705 | |
|
|
706 | $self->load_map ($hash, $x, $y) |
|
|
707 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
708 | |
|
|
709 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
710 | |
|
|
711 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
675 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
712 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
676 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
677 | |
|
|
678 | } else { |
|
|
679 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
680 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
681 | |
|
|
682 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
683 | return if $mode ne "spatial"; |
|
|
684 | |
|
|
685 | $x += $MAP->ox; |
|
|
686 | $y += $MAP->oy; |
|
|
687 | |
|
|
688 | $self->load_map ($hash, $x, $y) |
|
|
689 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
690 | |
|
|
691 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
692 | |
|
|
693 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
694 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
695 | }); |
713 | }); |
696 | } |
714 | } |
697 | } |
715 | } |
698 | } |
716 | |
699 | |
717 | sub conn::map_change { |
700 | sub conn::map_change { |
718 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
701 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
721 | |
704 | |
722 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
705 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
723 | |
706 | |
724 | my $mapmapw = 250; |
707 | my $mapmapw = 250; |
725 | my $mapmaph = 250; |
708 | my $mapmaph = 250; |
|
|
709 | |
|
|
710 | $self->{neigh_rect} = [ |
|
|
711 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
712 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5, |
|
|
713 | ]; |
726 | |
714 | |
|
|
715 | delete $self->{neigh_grid}; |
727 | $self->flood_fill ("", $hash, $flags, |
716 | $self->flood_fill (0, 0, "", $hash, $flags); |
728 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
729 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
730 | |
717 | |
731 | $x += $ox; |
718 | $x += $ox; |
732 | $y += $oy; |
719 | $y += $oy; |
733 | |
720 | |
734 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
721 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
… | |
… | |
800 | or return; |
787 | or return; |
801 | |
788 | |
802 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
789 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
803 | or return; |
790 | or return; |
804 | |
791 | |
805 | $SDL_MIXER->play_channel (-1, $chunk, 0, -1); |
792 | $chunk->play; |
806 | warn "sound $x,$y,$soundnum,$type\n";#d# |
793 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
807 | } |
794 | } |
808 | |
795 | |
809 | sub conn::query { |
796 | sub conn::query { |
810 | my ($self, $flags, $prompt) = @_; |
797 | my ($self, $flags, $prompt) = @_; |
811 | |
798 | |
812 | #TODO |
799 | #TODO, display dialog with relevant information |
813 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
800 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
814 | } |
801 | } |
815 | |
802 | |
816 | sub conn::drawinfo { |
803 | sub conn::drawinfo { |
817 | my ($self, $color, $text) = @_; |
804 | my ($self, $color, $text) = @_; |
… | |
… | |
833 | ); |
820 | ); |
834 | |
821 | |
835 | $LOGVIEW->add_paragraph ($color[$color], $text); |
822 | $LOGVIEW->add_paragraph ($color[$color], $text); |
836 | } |
823 | } |
837 | |
824 | |
|
|
825 | sub conn::spell_add { |
|
|
826 | my ($self, $spell) = @_; |
|
|
827 | |
|
|
828 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub { |
|
|
829 | }); |
|
|
830 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub { |
|
|
831 | }); |
|
|
832 | } |
|
|
833 | |
|
|
834 | sub conn::spell_delete { |
|
|
835 | my ($self, $spell) = @_; |
|
|
836 | } |
|
|
837 | |
|
|
838 | sub conn::addme_success { |
|
|
839 | my ($self) = @_; |
|
|
840 | |
|
|
841 | for my $skill (values %{$self->{skill_info}}) { |
|
|
842 | $MAPWIDGET->add_command ("ready_skill $skill", "", sub { |
|
|
843 | }); |
|
|
844 | $MAPWIDGET->add_command ("use_skill $skill", "", sub { |
|
|
845 | }); |
|
|
846 | } |
|
|
847 | } |
|
|
848 | |
838 | %SDL_CB = ( |
849 | %SDL_CB = ( |
839 | SDL_QUIT() => sub { |
850 | CFClient::SDL_QUIT => sub { |
840 | Event::unloop -1; |
851 | Event::unloop -1; |
841 | }, |
852 | }, |
842 | SDL_VIDEORESIZE() => sub { |
853 | CFClient::SDL_VIDEORESIZE => sub { |
843 | }, |
854 | }, |
844 | SDL_VIDEOEXPOSE() => sub { |
855 | CFClient::SDL_VIDEOEXPOSE => sub { |
845 | refresh; |
856 | refresh; |
846 | }, |
857 | }, |
847 | SDL_KEYDOWN() => sub { |
858 | CFClient::SDL_KEYDOWN => sub { |
848 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
859 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
849 | # alt-enter |
860 | # alt-enter |
850 | video_shutdown; |
861 | video_shutdown; |
851 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
862 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
852 | video_init; |
863 | video_init; |
853 | } else { |
864 | } else { |
854 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
865 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
855 | } |
866 | } |
856 | }, |
867 | }, |
857 | SDL_KEYUP() => sub { |
868 | CFClient::SDL_KEYUP => sub { |
858 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
869 | CFClient::UI::feed_sdl_key_up_event ($_[0]); |
859 | }, |
870 | }, |
860 | SDL_MOUSEMOTION() => sub { |
871 | CFClient::SDL_MOUSEMOTION => sub { |
861 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
872 | CFClient::UI::feed_sdl_motion_event ($_[0]); |
862 | }, |
873 | }, |
863 | SDL_MOUSEBUTTONDOWN() => sub { |
874 | CFClient::SDL_MOUSEBUTTONDOWN => sub { |
864 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
875 | CFClient::UI::feed_sdl_button_down_event ($_[0]); |
865 | }, |
876 | }, |
866 | SDL_MOUSEBUTTONUP() => sub { |
877 | CFClient::SDL_MOUSEBUTTONUP => sub { |
867 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
878 | CFClient::UI::feed_sdl_button_up_event ($_[0]); |
868 | }, |
879 | }, |
869 | SDL_ACTIVEEVENT() => sub { |
880 | CFClient::SDL_ACTIVEEVENT => sub { |
870 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
881 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
871 | }, |
882 | }, |
872 | ); |
883 | ); |
873 | |
884 | |
874 | ############################################################################# |
885 | ############################################################################# |
… | |
… | |
894 | mapsize => 100, |
905 | mapsize => 100, |
895 | host => "crossfire.schmorp.de", |
906 | host => "crossfire.schmorp.de", |
896 | say_command => 'say', |
907 | say_command => 'say', |
897 | audio_enable => 1, |
908 | audio_enable => 1, |
898 | bgm_enable => 1, |
909 | bgm_enable => 1, |
899 | bgm_volume => 64, |
910 | bgm_volume => 0.25, |
900 | ); |
911 | ); |
901 | |
912 | |
902 | while (my ($k, $v) = each %DEF_CFG) { |
913 | while (my ($k, $v) = each %DEF_CFG) { |
903 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
914 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
904 | } |
915 | } |
905 | |
916 | |
906 | sdl_init; |
917 | sdl_init; |
907 | |
918 | |
908 | @SDL_MODES = reverse |
919 | @SDL_MODES = reverse |
909 | grep $_->[0] >= 640 && $_->[1] >= 480, |
920 | grep $_->[0] >= 640 && $_->[1] >= 480, |
910 | map [SDL::RectW ($_), SDL::RectH ($_)], |
921 | CFClient::SDL_ListModes; |
911 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
912 | |
922 | |
913 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
923 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
914 | |
924 | |
915 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
925 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
916 | |
926 | |
… | |
… | |
924 | video_init; |
934 | video_init; |
925 | audio_init; |
935 | audio_init; |
926 | |
936 | |
927 | Event::loop; |
937 | Event::loop; |
928 | |
938 | |
929 | END { SDL::Quit } |
939 | END { CFClient::SDL_Quit } |
930 | |
940 | |
931 | |
941 | |