1 #include "twcgamecontroller.h"
2 #include "twcplayerclient.h"
5 void TWCShipIf::transporter_menu_input()
7 char *line
= plyrcli
.getline(0);
17 TWCShip
*target
= plyrcli
.acquire_target("Transport to which ship?",
18 "That ship is docked.");
22 TWCTransportSelfResults res
= target
->transport_self(plyrcli
);
24 if (res
== TSAlreadyCaptained
)
25 plyrcli
.print("That ship already has a captain.\n");
26 else if (res
!= TSAccessDenied
)
28 ship
.set_captain(NULL
);
29 plyrcli
.print("You beam aboard the %s.\n", target
->name());
30 if (res
== TSClaimedOwnership
)
31 plyrcli
.print("You claim ownership of the %s.\n",
33 plyrcli
.set_location(target
);
41 bool beam_to_ship
= true;
42 plyrcli
.print("Transport cargo to or from this ship? (t/f) ");
43 line
= plyrcli
.continue_getline();
47 if (line
[0] == 'f' || line
[0] == 'f')
50 TWCShip
*target
= plyrcli
.acquire_target(
51 WvString("Transport cargo %s which ship?",
52 beam_to_ship
? "from" : "to"),
53 "That ship is docked.");
57 TWCShip
*from_ship
, *to_ship
;
69 plyrcli
.display_inventory(from_ship
, true);
70 plyrcli
.print("Beam which commodity aboard? ");
72 int comm_type
= plyrcli
.get_int(abort
);
73 if (abort
|| !comm_type
)
75 ship
.game
->log("commodity type to beam is %s\n", comm_type
);
76 int max
= from_ship
->onboard("commodities", comm_type
);
77 if (max
> to_ship
->free_holds())
78 max
= to_ship
->free_holds();
79 plyrcli
.print("Beam how many aboard (max %s)? ", max
);
80 int num
= plyrcli
.get_int(abort
);
84 plyrcli
.print("You can't transport that many.\n");
85 else if (target
->sector() != ship
.sector())
86 plyrcli
.print("The ship has left the sector!\n");
87 else if (!to_ship
->beam_cargo_aboard(from_ship
, comm_type
, num
))
88 plyrcli
.print("Cargo transportation failed.\n");
90 plyrcli
.print("Cargo transferred.\n");
107 transport_comm_result
TWCPlayerClient::transport_commodities(int from
,
112 int target
, actor
= loccfg().key().printable().num();
113 TWCEventType event_type
;
117 event_type
= CargoBeamedTo
;
122 event_type
= CargoBeamedFrom
;
125 log("transport_commodities() from [%s] to [%s] actor [%s] target [%s]\n",
126 from
, to
, actor
, target
);
127 log("number of [%s] on from [%s] is [%s] (want [%s])\n", comm_type
, from
,
128 cfg
["ships"][from
]["holds"][comm_type
].getint(), number
);
129 if (check_shields(target
) != CSAccessGranted
)
130 return TCAccessDenied
;
132 log("shields are down on target\n");
133 if (cfg
["ships"][from
]["holds"][comm_type
].getint() < number
)
136 log("doing actual transport\n");
137 int holds
= cfg
["ships"][to
]["total holds"].getint();
138 UniConf::Iter
i(cfg
["ships"][to
]["holds"]);
139 for (i
.rewind(); i
.next(); )
140 holds
-= i().getint();
144 decr_uniconf(cfg
["ships"][from
]["holds"][comm_type
], number
);
145 incr_uniconf(cfg
["ships"][to
]["holds"][comm_type
], number
);
147 WvString
beam_result("%s holds of %s.\n", number
,
148 cfg
["commodities"][comm_type
]["name"].get());
149 msg("%s beamed to %s from %s.\n", beam_result
,
150 cfg
["ships"][to
]["name"].get(),
151 cfg
["ships"][from
]["name"].get());
153 game
->announce(event_type
, actor
, target
,
154 WvString("%s beams cargo %s %s.\n",
155 loccfg()["name"].get(),
156 comm_type
== CargoBeamedTo
? "from" : "to",
157 cfg
["ships"][target
]["name"].get()),
158 loccfg()["location"].getint());
165 TWCTransportSelfResults
TWCShip::transport_self(TWCPlayerClient
&plyrcli
)
168 return TSAlreadyCaptained
;
170 if (check_shields(plyrcli
) == CSAccessGranted
)
172 check_claim_ownership(&plyrcli
.player
);
173 // player client must set location itself
176 return TSAccessDenied
;
180 TWCCheckShieldsResults
TWCShip::check_shields(TWCPlayerClient
&plyrcli
)
182 if (!are_shields_up() || owner() == &plyrcli
.player
)
183 return CSAccessGranted
;
186 return CSAccessForbidden
;
188 if (password() == plyrcli
.try_passwd())
189 return CSAccessGranted
;
191 return CSAccessDenied
;
195 TWCCheckShieldsResults
TWCShipIf::check_shields(TWCShip
*target
)
197 TWCCheckShieldsResults res
= target
->check_shields(plyrcli
);
198 if (res
== CSAccessForbidden
)
199 plyrcli
.print("You don't own this ship, its shields are up, and the "
200 "owner has forbidden transports.\n");
201 else if (res
!= CSAccessGranted
)
202 plyrcli
.print("Access denied.\n");