Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/sartak/TAEB
Browse files Browse the repository at this point in the history
Conflicts:
	lib/TAEB/Role/Initialize.pm
  • Loading branch information
doy committed Jul 11, 2009
2 parents 17e1e4a + 8db2d51 commit b5e3047
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 28 deletions.
4 changes: 3 additions & 1 deletion bin/mactaeb
Expand Up @@ -110,5 +110,7 @@ if ($options{interface} eq 'Telnet') {
}

my $config = Dump(\%options);
exec $^X, "$Bin/taeb", "--config=$config";
# TODO: Dump $config to a file
# TODO: Quote $^X and $Bin/taeb
system(qq{osascript -e 'tell application "Terminal" to do script "$^X $Bin/taeb"'});

3 changes: 3 additions & 0 deletions bin/taeb
Expand Up @@ -72,6 +72,9 @@ $SIG{TERM} = sub {
$SIG{USR1} = sub {
TAEB->debugger->console->repl(undef);
};
$SIG{USR2} = sub {
die "Dying on user request to give a stack trace";
};

$| = 1;

Expand Down
3 changes: 3 additions & 0 deletions doc/MonsterTracker.pm
Expand Up @@ -50,15 +50,18 @@ use TAEB::OO;
use overload %TAEB::Meta::Overload::default;

has level => (
is => 'ro',
isa => 'TAEB::World::Level',
weak_ref => 1,
);

has visible => (
is => 'ro',
isa => 'ArrayRef[TAEB::World::Monster]',
);

has pool => (
is => 'ro',
isa => 'ArrayRef[TAEB::World::Monster]',
);

Expand Down
2 changes: 1 addition & 1 deletion etc/examples/ais523.yml
Expand Up @@ -33,7 +33,7 @@ debug:
console:
readline: Gnu

unattended: 0
kiosk_mode: 0

other_config:
- ~/.taeb/secret_config.yml
20 changes: 13 additions & 7 deletions lib/TAEB.pm
Expand Up @@ -118,7 +118,8 @@ class_has log => (
max_level => 'warning',
callbacks => sub {
my %args = @_;
if (!TAEB->display->to_screen) {
if (!defined TAEB->display
|| !TAEB->display->to_screen) {
local $SIG{__WARN__};
warn $args{message};
}
Expand All @@ -129,7 +130,8 @@ class_has log => (
min_level => 'error',
callbacks => sub {
my %args = @_;
if (!TAEB->display->to_screen) {
if (!defined TAEB->display
|| !TAEB->display->to_screen) {
local $SIG{__WARN__};
confess $args{message};
}
Expand Down Expand Up @@ -254,7 +256,8 @@ class_has item_pool => (
isa => 'TAEB::World::ItemPool',
default => sub { TAEB::World::ItemPool->new },
handles => {
get_artifact => 'get_artifact',
get_artifact => 'get_artifact',
seen_artifact => 'get_artifact',
},
);

Expand All @@ -274,11 +277,14 @@ sub next_action {
my $action = $self->ai->next_action(@_)
or confess $self->ai . " did not return a next_action!";

if ($action->isa('TAEB::World::Path')) {
return TAEB::Action::Move->new(path => $action);
return $action if $action->isa('TAEB::Action');

# Not an action, but can become one.
if ($action->does('TAEB::Role::Actionable')) {
return $action->as_action;
}

return $action;
confess $self->ai . "'s next_action returned a non-action!";
}

sub iterate {
Expand Down Expand Up @@ -746,7 +752,7 @@ sub setup_handlers {
TAEB->log->perl($error, level => $level);
# Use the emergency versions of quit/save here, not the actions.
if (defined TAEB->config && defined TAEB->config->contents &&
TAEB->config->contents->{'unattended'}) {
TAEB->config->contents->{'kiosk_mode'}) {
TAEB->quit;
TAEB->destroy_saved_state;
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/TAEB/AI.pm
Expand Up @@ -64,12 +64,12 @@ sub respond_continue_lifting { "y" }

sub respond_wish {
# We all know how much TAEB loves Elbereth. Let's give it Elbereth's best buddy.
return "blessed fixed +3 Magicbane\n" unless TAEB->get_artifact("Magicbane");
return "blessed fixed +3 Magicbane\n" unless TAEB->seen_artifact("Magicbane");

# Half physical damage? Don't mind if I do! (Now with added grease for Eidolos!)
return "blessed fixed greased Master Key of Thievery\n"
if TAEB->align eq 'Cha'
&& !TAEB->get_artifact('Master Key of Thievery');
&& !TAEB->seen_artifact('Master Key of Thievery');

# We can always use more AC.
return "blessed fixed greased +3 dwarvish mithril-coat\n" unless TAEB->has_item(qr/mithril/);
Expand Down
9 changes: 6 additions & 3 deletions lib/TAEB/Action/Open.pm
Expand Up @@ -14,13 +14,16 @@ subscribe door => sub {
my $event = shift;

my $state = $event->state;
my $tile = $event->tile;
my $door = $event->tile;

# The tile may have been changed between the announcement's origin and now
return unless $door->isa('TAEB::World::Tile::Door');

if ($state eq 'locked') {
$tile->state('locked');
$door->state('locked');
}
elsif ($state eq 'resists') {
$tile->state('unlocked');
$door->state('unlocked');
}
};

Expand Down
2 changes: 2 additions & 0 deletions lib/TAEB/Announcement.pm
Expand Up @@ -19,6 +19,8 @@ sub name {
return lc $class;
}

sub immediate { 0 }

use Module::Pluggable (
require => 1,
sub_name => 'announcement_classes',
Expand Down
10 changes: 10 additions & 0 deletions lib/TAEB/Announcement/Exception.pm
@@ -0,0 +1,10 @@
package TAEB::Announcement::Exception;
use TAEB::OO;
extends 'TAEB::Announcement';

sub immediate { 1 }

__PACKAGE__->meta->make_immutable;

1;

8 changes: 8 additions & 0 deletions lib/TAEB/Announcement/Exception/MissingItem.pm
@@ -0,0 +1,8 @@
package TAEB::Announcement::Exception::MissingItem;
use TAEB::OO;
extends 'TAEB::Announcement::Exception';

__PACKAGE__->meta->make_immutable;

1;

1 change: 1 addition & 0 deletions lib/TAEB/Announcement/Query.pm
Expand Up @@ -2,6 +2,7 @@ package TAEB::Announcement::Query;
use TAEB::OO;
extends 'TAEB::Announcement';

sub immediate { 1 }

__PACKAGE__->meta->make_immutable;

Expand Down
2 changes: 1 addition & 1 deletion lib/TAEB/Config.pm
Expand Up @@ -342,7 +342,7 @@ TAEB::Config
# Set this to 1 if you want to run a buggy TAEB overnight; it causes TAEB
# to quit instead of saving on errors; if your TAEB is not particularly
# buggy, you might want to leave this this at 0 so the full state is kept.
#unattended: 0
#kiosk_mode: 0
#### External config ######
# Specify other config files to load here - for example, config files
Expand Down
2 changes: 1 addition & 1 deletion lib/TAEB/Display/Curses.pm
Expand Up @@ -459,7 +459,7 @@ sub change_draw_mode {

my $menu = TAEB::Display::Menu->new(
description => "Change draw mode",
items => [ map { $_->{description} } values %modes ],
items => [ sort map { $_->{description} } values %modes ],
select_type => 'single',
);

Expand Down
6 changes: 5 additions & 1 deletion lib/TAEB/Logger.pm
Expand Up @@ -93,6 +93,7 @@ has twitter => (
$args{message} =~ s/\n.*//s;
return sprintf "%s (T%s): %s",
TAEB->loaded_persistent_data
&& defined TAEB->senses # i.e. not yet cleaned up
? (TAEB->name, TAEB->turn)
: ('?', '-'),
$args{message};
Expand Down Expand Up @@ -211,7 +212,10 @@ sub _format {
my ($sec, $min, $hour, $mday, $mon, $year) = localtime;

return sprintf "<T%s> %04d-%02d-%02d %02d:%02d:%02d %s\n",
(TAEB->loaded_persistent_data ? TAEB->turn : '-'),
(TAEB->loaded_persistent_data
&& defined TAEB->senses # i.e. not yet cleaned up
? TAEB->turn
: '-'),
$year + 1900,
$mon + 1,
$mday,
Expand Down
6 changes: 5 additions & 1 deletion lib/TAEB/Meta/Trait/Persistent.pm
Expand Up @@ -15,7 +15,11 @@ before _process_options => sub {

# do we have the value from persistency?
my $value = delete TAEB->persistent_data->{$name};
return $value if defined $value;
if (defined($value)) {
# For some reason Storable doesn't load TAEB::AI::Demo
Class::MOP::load_class(blessed($value)) if blessed($value);
return $value;
}

# otherwise, use the old default
ref($old_default) eq 'CODE' ? $old_default->($self, @_) : $old_default;
Expand Down
7 changes: 6 additions & 1 deletion lib/TAEB/Publisher.pm
Expand Up @@ -86,7 +86,12 @@ sub announce {
sub send_message {
my $self = shift;

return $self->_enqueue_message(@_) if $self->is_paused;
if ($self->is_paused) {
# Some announcements (like queries) cannot be delayed
unless (@_ == 1 && blessed($_[0]) && $_[0]->isa('TAEB::Announcement') && $_[0]->is_immediate) {
return $self->_enqueue_message(@_);
}
}

my $name = shift;
my @args = @_;
Expand Down
7 changes: 7 additions & 0 deletions lib/TAEB/Role/Actionable.pm
@@ -0,0 +1,7 @@
package TAEB::Role::Actionable;
use Moose::Role;

requires 'as_action';

1;

2 changes: 1 addition & 1 deletion lib/TAEB/Role/Initialize.pm
Expand Up @@ -39,7 +39,7 @@ after initialize => sub {
next unless $class->meta->does_role(__PACKAGE__);

my $value = $attr->get_read_method_ref->($self);
next unless blessed($value);
next unless blessed $value;
$value->initialize;
}
};
Expand Down
12 changes: 12 additions & 0 deletions lib/TAEB/Senses.pm
Expand Up @@ -682,6 +682,18 @@ sub speed {
return ($min, $max);
}

# The maximum weight we can carry with out current stats and still be
# unburdened. The maximum weight we can carry without being stressed
# is about 1.5 times this; wizmode testing shows that a character with
# no inventory, and max str and con, can carry $100049 without being
# burdened, and $149949 without being stressed.
sub unburdened_limit {
my $self = shift;
my $limit = 25*($self->con+$self->numeric_strength)+50;
return 1000 if $limit > 1000;
return 1000;
}

# XXX this belongs elsewhere, but where?

sub spell_protection_return {
Expand Down
54 changes: 49 additions & 5 deletions lib/TAEB/Spoilers/Sokoban.pm
Expand Up @@ -367,6 +367,38 @@ sub recognise_sokoban_variant {
return $variant;
}

sub remaining_pits {
my $self = shift;
my $level = shift || TAEB->current_level;
my $remaining_pits = 0;
$level->each_tile(sub {
my $t = shift;
$remaining_pits++ if $t->type eq 'trap';
});
return $remaining_pits;
}

sub first_unsolved_sokoban_level {
my $self = shift;
return TAEB->dungeon->shallowest_level(sub {
my $level = shift;
return $level->known_branch
&& $level->branch eq 'sokoban'
&& $self->remaining_pits($level) > 0;
});
}

sub first_solvable_sokoban_level {
my $self = shift;
my $pathable = shift;
return TAEB->dungeon->shallowest_level(sub {
my $level = shift;
return $level->known_branch
&& $level->branch eq 'sokoban'
&& defined $self->next_sokoban_step($level,$pathable);
});
}

sub next_sokoban_step {
my $self = shift;
my $level = shift;
Expand Down Expand Up @@ -395,11 +427,7 @@ sub next_sokoban_step {
my $solution = $self->level_maps->{$variant}->{'solution'};

# Find out how many pits have been filled already.
my $remaining_pits = 0;
$level->each_tile(sub {
my $t = shift;
$remaining_pits++ if $t->type eq 'trap';
});
my $remaining_pits = $self->remaining_pits($level);

return if $remaining_pits == 0; # already solved

Expand Down Expand Up @@ -563,6 +591,22 @@ level. If called in list context, also gives the x and y offset of the
map from the spoiler. If no level is given, defaults to TAEB's current
level.
=head2 first_unsolved_sokoban_level -> Level
Returns the lowest level in Sokoban that is not yet completely solved
but that TAEB has encountered in the past.
=head2 first_solvable_sokoban_level -> Level
Returns the lowest level in Sokoban that can be solved from here
(i.e. is not yet completely solved and has not been fatally messed up)
but that TAEB has encountered in the past.
=head2 remaining_pits [Level] -> Int
Returns the number of pits/holes remaining on level Level (defaulting
to the current level). When this is 0, the level is solved.
=head2 next_sokoban_step Level [Pathable] -> Maybe Tile
Return the tile that we need to head to next to solve the Sokoban
Expand Down
8 changes: 8 additions & 0 deletions lib/TAEB/World/Path.pm
Expand Up @@ -4,6 +4,8 @@ use Heap::Simple;
use TAEB::Util qw/delta2vi deltas sum max refaddr/;
use Time::HiRes 'time';

with 'TAEB::Role::Actionable';

has from => (
is => 'ro',
isa => 'TAEB::World::Tile',
Expand Down Expand Up @@ -355,6 +357,12 @@ sub contains_tile {
return $self->tiles->{refaddr $tile};
}

use TAEB::Action::Move;
sub as_action {
my $self = shift;
return TAEB::Action::Move->new(path => $self);
}

__PACKAGE__->meta->make_immutable(inline_constructor => 0);

1;
Expand Down
3 changes: 2 additions & 1 deletion lib/TAEB/World/Spells.pm
@@ -1,13 +1,14 @@
package TAEB::World::Spells;
use TAEB::OO;
use TAEB::Util 'first';
use TAEB::World::Spell;

use overload %TAEB::Meta::Overload::default;

my @slots = ('a' .. 'z', 'A' .. 'Z');

has _spells => (
metaclass => 'Collection::Hash',
traits => ['MooseX::AttributeHelpers::Trait::Collection::Hash'],
isa => 'HashRef[TAEB::World::Spell]',
default => sub { {} },
provides => {
Expand Down

0 comments on commit b5e3047

Please sign in to comment.