Skip to content

Commit

Permalink
More work on the Trade Ministry
Browse files Browse the repository at this point in the history
  • Loading branch information
icydee authored and Iain C Docherty committed Feb 15, 2016
1 parent b6a5aa3 commit 3232bc4
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 110 deletions.
39 changes: 13 additions & 26 deletions docs/Trade.pod
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The unique ID of the ship you want to add to the fleet.
=head3 quantity (optional)

Only available in the named argument call method. The number of ships to put on duty.
Defaults to 1 ship.
Defaults to all ships in the fleet.

=head3 RESPONSE

Expand Down Expand Up @@ -109,7 +109,7 @@ The unique ID of the ship you want to add to the fleet.
=head3 quantity (optional)

Only available in the named argument call method. The number of ships to put on duty.
Defaults to 1 ship.
Defaults to all ships in a fleet.

=head3 RESPONSE

Expand All @@ -119,16 +119,9 @@ Returns the same as C<view>

=head2 add_to_market

Adds a trade to the market for others to see. This now only takes named arguments.

The fixed argument method is no longer supported.

{


Accepts either fixed arguments or a hash of named parameters

( session_id, building_id, offer, ask, options )
( session_id, building_id, offer, ask, fleet_id )
( parameter_hash )

=head3 session_id (required)
Expand Down Expand Up @@ -284,7 +277,7 @@ Must be exactly C<fleet>.

=item fleet_id

The unique id of the fleet that you want to trade. See the C<get_fleets> method for a list of your fleets.
The unique id of the fleet that you want to trade. See the C<get_tradeable_fleets> method for a list of your fleets.

=item quantity

Expand All @@ -298,20 +291,14 @@ The number of ships in the fleet to offer in trade.

A number representing the amount of essentia you are asking for this trade. Must be a number between 0.1 and 99.9.

=head3 options (optional)

A hash reference of options to modify the trade.

=over

=item fleet_id
=head3 fleet_id (optional)

The ID of the fleet you want to use to transport this trade. See C<get_trade_fleets> for details.

If you don't specify a fleet_id then it will take the first available fleet for the trade.

The quantity of ships to send will be based on the number of ships in the fleet and the cargo capacity
of each ship in the fleet.
of each ship in the fleet. You do not need to specify this, it will be calculated for you.

=back

Expand All @@ -332,7 +319,7 @@ the supply chains.

Accepts either fixed arguments or a hash of named parameters

( session_id, building_id, target_id resource_type resource_hour )
( session_id, building_id, target resource_type resource_hour )
( parameter_hash )

=head3 session_id (required)
Expand Down Expand Up @@ -366,7 +353,7 @@ The amount of the resource you want to transfer each hour.
Returns the same as the call to B<view_supply_chains>


=head2 get_fleets
=head2 get_tradeable_fleets

Accepts either fixed arguments or a hash of named parameters

Expand Down Expand Up @@ -691,13 +678,13 @@ A Session ID.

The unique ID of the Trade Ministry.

=head3 target_body_id
=head3 target_body_id (optional)

The unique id of the body you'll be shipping to. Optional. If included it will calculate the estimated travel time of the fleets to this body.

=head3 RESPONSE

Returns a list of the fleets that could be used to do a trade.
Returns a list of the fleets that could be used to transport a trade.

{
"status" : { ... },
Expand Down Expand Up @@ -1269,7 +1256,7 @@ The unique id of the spy that you want to push. See the C<get_prisoners> method
The hash reference for fleets looks like:

{
"type" : "ship",
"type" : "fleet",
"fleet_id" : "id-goes-here",
"quantity" : 23,
}
Expand All @@ -1280,9 +1267,9 @@ The hash reference for fleets looks like:

Must be exactly C<fleet>.

=item ship_id
=item fleet_id

The unique id of the fleet that you want to push. See the C<get_fleets> method for a list of your fleets.
The unique id of the fleet that you want to push. See the C<get_tradeable_fleets> method for a list of your fleets.

=back

Expand Down
6 changes: 3 additions & 3 deletions lib/Lacuna/DB/Result/Building/Trade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ before 'can_downgrade' => sub {
};

sub add_to_market {
my ($self, $offer, $ask, $options, $internal_options) = @_;
my $ship = $self->next_available_trade_ship($options->{ship_id});
my ($self, $offer, $ask, $fleet_id, $internal_options) = @_;
my $ship = $self->next_available_trade_ship($fleet_id);
unless (defined $ship) {
confess [1011, "You do not have any ships available that can carry trade goods."];
}
Expand Down Expand Up @@ -408,7 +408,7 @@ sub trade_fleets {
sub next_available_trade_fleet {
my ($self, $fleet_id) = @_;
if ($fleet_id) {
return $self->trade_ships->find($fleet_id);
return $self->trade_fleets->find($fleet_id);
}
else {
return $self->trade_fleets->search(undef, {rows => 1})->single;
Expand Down
15 changes: 10 additions & 5 deletions lib/Lacuna/RPC/Building/Trade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ sub add_fleet_to_supply_duty {
my $empire = $self->get_empire_by_session($args->{session_id});
my $building = $self->get_building($empire, $args->{building_id});
my $fleet_id = $args->{fleet_id};
my $quantity = $args->{quantity} || 1;

if (not defined $building) {
>>>>>>> Started to modify Trade Ministry for fleets
Expand All @@ -175,6 +174,8 @@ sub add_fleet_to_supply_duty {
if (not first {$fleet->type eq $_} (SHIP_TRADE_TYPES)) {
confess [1009, 'You can only add transport ships to a supply chain.'];
}
my $quantity = $args->{quantity} || $fleet->quantity;

my $max_berth = $building->body->max_berth;

if ($fleet->berth_level > $max_berth) {
Expand Down Expand Up @@ -203,7 +204,6 @@ sub add_fleet_to_waste_duty {
my $empire = $self->get_empire_by_session($args->{session_id});
my $building = $self->get_building($empire, $args->{building_id});
my $fleet_id = $args->{fleet_id};
my $quantity = $args->{quantity} || 1;

if (not defined $building) {
confess [1002, "Building not found."];
Expand All @@ -224,6 +224,8 @@ sub add_fleet_to_waste_duty {
if ($fleet->type !~ m/^scow/) {
confess [1009, 'You can only add scows to a supply chain.'];
}
my $quantity = $args->{quantity} || $fleet->quantity;

my $max_berth = $building->body->max_berth;

if ($fleet->berth_level > $max_berth) {
Expand All @@ -246,7 +248,7 @@ sub add_to_market {
building_id => shift,
offer => shift,
ask => shift,
options => shift,
fleet_id => shift,
};
}

Expand All @@ -262,7 +264,7 @@ sub add_to_market {
my $guard = guard {
$cache->delete('trade_add_lock',$building->id);
};
my $trade = $building->add_to_market($args->{offer}, $args->{ask}, $args->{options});
my $trade = $building->add_to_market($args->{offer}, $args->{ask}, $args->{fleet_id});
return {
trade_id => $trade->id,
status => $self->format_status($empire, $building->body),
Expand Down Expand Up @@ -319,6 +321,8 @@ sub create_supply_chain {
}

# Target must be own empire or an allies
# TODO Allow supply chains to other empires?
#
if ($target->empire_id != $empire->id) {
if ($target->alliance_id != $empire->alliance_id) {
confess [1002, "You can only target one of your own or an allies colony or Space Station."];
Expand All @@ -341,7 +345,8 @@ sub create_supply_chain {
return $self->view_supply_chains($args->{session_id}, $building->id);
}


# Get fleets that are available to transport a trade
#
sub get_trade_fleets {
my $self = shift;
my $args = shift;
Expand Down
Loading

0 comments on commit 3232bc4

Please sign in to comment.