Permalink
Browse files

Trimming ex-code and hopefully speeding up ticking spies.

  • Loading branch information...
lemming552 committed Jan 3, 2014
1 parent fb5676c commit b492adc056d2bb28d72e6341aacc5433913897e6
@@ -88,114 +88,5 @@ has training_multiplier => (
}
);
-sub training_costs {
- my $self = shift;
- my $spy_id = shift;
- my $multiplier = $self->training_multiplier;
- my $costs = {
- water => 1100 * $multiplier,
- waste => 40 * $multiplier,
- energy => 100 * $multiplier,
- food => 1000 * $multiplier,
- ore => 10 * $multiplier,
- time => [],
- };
- if ($spy_id) {
- my $spy = $self->get_spy($spy_id);
- my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100)+1;
- my $train_time = sprintf('%.0f', 3600 * $xp_level *
- ((100 - (5 * $self->body->empire->management_affinity)) / 100));
- if ($self->body->happiness < 0) {
- my $unhappy_workers = abs($self->body->happiness)/100_000;
- $train_time = int($train_time * $unhappy_workers);
- }
- $train_time = 5184000 if ($train_time > 5184000); # Max time per spy is 60 days
- $train_time = 21600 if ($train_time < 21600); # Min time is 6 hour
- $costs->{time} = $train_time;
- }
- else {
- my $spies = $self->get_spies->search({ task => { in => ['Counter Espionage','Idle'] } });
- while (my $spy = $spies->next) {
- my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100)+1;
- my $train_time = sprintf('%.0f', 3600 * $xp_level *
- ((100 - (5 * $self->body->empire->management_affinity)) / 100));
- if ($self->body->happiness < 0) {
- my $unhappy_workers = abs($self->body->happiness)/100_000;
- $train_time = int($train_time * $unhappy_workers);
- }
- $train_time = 5184000 if ($train_time > 5184000); # Max time per spy is 60 days
- $train_time = 21600 if ($train_time < 21600); # Min time is 6 hour
- push @{$costs->{time}}, {
- spy_id => $spy->id,
- name => $spy->name,
- time => $train_time,
- level => $spy->level,
- offense_rating => $spy->offense,
- defense_rating => $spy->offense,
- intel => $spy->intel_xp,
- mayhem => $spy->mayhem_xp,
- politics => $spy->politics_xp,
- theft => $spy->theft_xp,
- task => $spy->task, # Should only be Idle or Counter Espionage
- based_from => {
- body_id => $spy->from_body_id,
- name => $spy->from_body->name,
- x => $spy->from_body->x,
- y => $spy->from_body->y,
- },
- };
- }
- }
- return $costs;
-}
-
-sub can_train_spy {
- my ($self, $costs) = @_;
- my $body = $self->body;
- foreach my $resource (qw(water ore food energy)) {
- unless ($body->type_stored($resource) >= $costs->{$resource}) {
- confess [1011, 'Not enough '.$resource.' to train a spy.'];
- }
- }
- return 1;
-}
-
-sub spend_resources_to_train_spy {
- my ($self, $costs) = @_;
- my $body = $self->body;
- foreach my $resource (qw(water ore food energy)) {
- my $spend = 'spend_'.$resource;
- $body->$spend($costs->{$resource});
- }
- $body->add_waste($costs->{waste});
-}
-
-sub train_spy {
- my ($self, $spy_id, $time_to_train) = @_;
- my $empire = $self->body->empire;
- my $spy = $self->get_spy($spy_id);
- unless ($spy->intel_xp < 2600) {
- confess [1013, $spy->name." has already learned all there is to know about Intelligence."];
- }
- unless (defined $time_to_train) {
- $time_to_train = $self->training_costs($spy_id)->{time};
- }
- $spy->is_available;
- unless ($spy->task ~~ ['Counter Espionage','Idle']) {
- confess [1011, 'Spy must be idle to train.'];
- }
- my $available_on = DateTime->now;
- $available_on->add(seconds => $time_to_train );
- my $total = $spy->intel_xp + $self->level;
- $total = 2600 if $total > 2600;
- $spy->intel_xp($total);
- $spy->update_level;
- $spy->task('Training');
- $spy->available_on($available_on);
- $spy->update;
- return $self;
-}
-
-
no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
@@ -91,112 +91,5 @@ has training_multiplier => (
}
);
-sub training_costs {
- my $self = shift;
- my $spy_id = shift;
- my $multiplier = $self->training_multiplier;
- my $costs = {
- water => 1100 * $multiplier,
- waste => 40 * $multiplier,
- energy => 100 * $multiplier,
- food => 1000 * $multiplier,
- ore => 10 * $multiplier,
- time => [],
- };
- if ($spy_id) {
- my $spy = $self->get_spy($spy_id);
- my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1;
- my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100));
- if ($self->body->happiness < 0) {
- my $unhappy_workers = abs($self->body->happiness)/100_000;
- $train_time = int($train_time * $unhappy_workers);
- }
- $train_time = 5184000 if ($train_time > 5184000); # Max time per spy is 60 days
- $train_time = 21600 if ($train_time < 21600); # Min time is 6 hour
- $costs->{time} = $train_time;
- }
- else {
- my $spies = $self->get_spies->search({ task => { in => ['Counter Espionage','Idle'] } });
- while (my $spy = $spies->next) {
- my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1;
- my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100));
- if ($self->body->happiness < 0) {
- my $unhappy_workers = abs($self->body->happiness)/100_000;
- $train_time = int($train_time * $unhappy_workers);
- }
- $train_time = 5184000 if ($train_time > 5184000); # Max time per spy is 60 days
- $train_time = 21600 if ($train_time < 21600); # Min time is 6 hour
- push @{$costs->{time}}, {
- spy_id => $spy->id,
- name => $spy->name,
- time => $train_time,
- level => $spy->level,
- offense_rating => $spy->offense,
- defense_rating => $spy->offense,
- intel => $spy->intel_xp,
- mayhem => $spy->mayhem_xp,
- politics => $spy->politics_xp,
- theft => $spy->theft_xp,
- task => $spy->task, # Should only be Idle or Counter Espionage
- based_from => {
- body_id => $spy->from_body_id,
- name => $spy->from_body->name,
- x => $spy->from_body->x,
- y => $spy->from_body->y,
- },
- };
- }
- }
- return $costs;
-}
-
-sub can_train_spy {
- my ($self, $costs) = @_;
- my $body = $self->body;
- foreach my $resource (qw(water ore food energy)) {
- unless ($body->type_stored($resource) >= $costs->{$resource}) {
- confess [1011, 'Not enough '.$resource.' to train a spy.'];
- }
- }
- return 1;
-}
-
-sub spend_resources_to_train_spy {
- my ($self, $costs) = @_;
- my $body = $self->body;
- foreach my $resource (qw(water ore food energy)) {
- my $spend = 'spend_'.$resource;
- $body->$spend($costs->{$resource});
- }
- $body->add_waste($costs->{waste});
-}
-
-sub train_spy {
- my ($self, $spy_id, $time_to_train) = @_;
- my $empire = $self->body->empire;
- my $spy = $self->get_spy($spy_id);
- unless ($spy->mayhem_xp < 2600) {
- confess [1013, $spy->name." has already learned all there is to know about Mayhem."];
- }
- unless (defined $time_to_train) {
- $time_to_train = $self->training_costs($spy_id)->{time};
- }
- $spy->is_available;
- unless ($spy->task ~~ ['Counter Espionage','Idle']) {
- confess [1011, 'Spy must be idle to train.'];
- }
- my $available_on = DateTime->now;
- $available_on->add(seconds => $time_to_train );
- my $total = $spy->mayhem_xp + $self->level;
- $total = 2600 if $total > 2600;
- $spy->mayhem_xp($total);
- $spy->update_level;
- $spy->task('Training');
- $spy->available_on($available_on);
- $spy->update;
- return $self;
-}
-
-
no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
@@ -88,112 +88,5 @@ has training_multiplier => (
}
);
-sub training_costs {
- my $self = shift;
- my $spy_id = shift;
- my $multiplier = $self->training_multiplier;
- my $costs = {
- water => 1100 * $multiplier,
- waste => 40 * $multiplier,
- energy => 100 * $multiplier,
- food => 1000 * $multiplier,
- ore => 10 * $multiplier,
- time => [],
- };
- if ($spy_id) {
- my $spy = $self->get_spy($spy_id);
- my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1;
- my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100));
- if ($self->body->happiness < 0) {
- my $unhappy_workers = abs($self->body->happiness)/100_000;
- $train_time = int($train_time * $unhappy_workers);
- }
- $train_time = 5184000 if ($train_time > 5184000); # Max time per spy is 60 days
- $train_time = 21600 if ($train_time < 21600); # Min time is 6 hour
- $costs->{time} = $train_time;
- }
- else {
- my $spies = $self->get_spies->search({ task => { in => ['Counter Espionage','Idle'] } });
- while (my $spy = $spies->next) {
- my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1;
- my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100));
- if ($self->body->happiness < 0) {
- my $unhappy_workers = abs($self->body->happiness)/100_000;
- $train_time = int($train_time * $unhappy_workers);
- }
- $train_time = 5184000 if ($train_time > 5184000); # Max time per spy is 60 days
- $train_time = 21600 if ($train_time < 21600); # Min time is 6 hour
- push @{$costs->{time}}, {
- spy_id => $spy->id,
- name => $spy->name,
- time => $train_time,
- level => $spy->level,
- offense_rating => $spy->offense,
- defense_rating => $spy->offense,
- intel => $spy->intel_xp,
- mayhem => $spy->mayhem_xp,
- politics => $spy->politics_xp,
- theft => $spy->theft_xp,
- task => $spy->task, # Should only be Idle or Counter Espionage
- based_from => {
- body_id => $spy->from_body_id,
- name => $spy->from_body->name,
- x => $spy->from_body->x,
- y => $spy->from_body->y,
- },
- };
- }
- }
- return $costs;
-}
-
-sub can_train_spy {
- my ($self, $costs) = @_;
- my $body = $self->body;
- foreach my $resource (qw(water ore food energy)) {
- unless ($body->type_stored($resource) >= $costs->{$resource}) {
- confess [1011, 'Not enough '.$resource.' to train a spy.'];
- }
- }
- return 1;
-}
-
-sub spend_resources_to_train_spy {
- my ($self, $costs) = @_;
- my $body = $self->body;
- foreach my $resource (qw(water ore food energy)) {
- my $spend = 'spend_'.$resource;
- $body->$spend($costs->{$resource});
- }
- $body->add_waste($costs->{waste});
-}
-
-sub train_spy {
- my ($self, $spy_id, $time_to_train) = @_;
- my $empire = $self->body->empire;
- my $spy = $self->get_spy($spy_id);
- unless ($spy->politics_xp < 2600) {
- confess [1013, $spy->name." has already learned all there is to know about Politics."];
- }
- unless (defined $time_to_train) {
- $time_to_train = $self->training_costs($spy_id)->{time};
- }
- $spy->is_available;
- unless ($spy->task ~~ ['Counter Espionage','Idle']) {
- confess [1011, 'Spy must be idle to train.'];
- }
- my $available_on = DateTime->now;
- $available_on->add(seconds => $time_to_train );
- my $total = $spy->politics_xp + $self->level;
- $total = 2600 if $total > 2600;
- $spy->politics_xp($total);
- $spy->update_level;
- $spy->task('Training');
- $spy->available_on($available_on);
- $spy->update;
- return $self;
-}
-
-
no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
Oops, something went wrong.

0 comments on commit b492adc

Please sign in to comment.