[Add] Merchants now have cargo that you can steal upon boarding.

This commit is contained in:
Allanis 2013-03-17 14:22:10 +00:00
parent 5d2f604703
commit b9fce0adbf
2 changed files with 78 additions and 26 deletions

View File

@ -42,6 +42,14 @@ end
function create() function create()
ai.setcredits(ai.rnd(200, ai.shipprice()/100)) ai.setcredits(ai.rnd(200, ai.shipprice()/100))
num = ai.rnd(0,1)
if num == 0 then
cargo = "Food"
elseif num == 1 then
cargo = "Ore"
end
ai.setCargo(cargo, ai.rnd(0, ai.cargofree()))
end end
-- Runs away. -- Runs away.

View File

@ -16,14 +16,13 @@ static unsigned int board_wid = 0;
static void board_exit(char* str); static void board_exit(char* str);
static void board_stealCreds(char* str); static void board_stealCreds(char* str);
static void board_fail(void); static void board_stealCargo(char* str);
static int board_fail(void);
static void board_update(void); static void board_update(void);
// Attempt to board the players target. // Attempt to board the players target.
void player_board(void) { void player_board(void) {
Pilot* p; Pilot* p;
char str[128];
char cred[10];
if(player_target == PLAYER_ID) { if(player_target == PLAYER_ID) {
player_message("You need a target to board first!"); player_message("You need a target to board first!");
@ -63,19 +62,20 @@ void player_board(void) {
0, "txtCargo", &gl_smallFont, &cDConsole, 0, "txtCargo", &gl_smallFont, &cDConsole,
"SCreds:\n" "SCreds:\n"
"Cargo:\n"); "Cargo:\n");
credits2str(cred, p->credits, 2);
snprintf(str, 128,
"%s\n"
"%s\n",
cred, "none");
window_addText(board_wid, 80, -30, 120, 60, 0, "txtData", window_addText(board_wid, 80, -30, 120, 60, 0, "txtData",
&gl_smallFont, &cBlack, str); &gl_smallFont, &cBlack, NULL);
window_addButton(board_wid, 20, 20, 50, 30, "btnStealScred", "SCred", window_addButton(board_wid, 20, 20, 50, 30, "btnStealCredits",
board_stealCreds); "Credits", board_stealCreds);
window_addButton(board_wid, -20, 20, 50, 30, "btnBoardingClose", "Leave",
board_exit); window_addButton(board_wid, 90, 20, 50, 30, "btnStealCargo",
"Cargo", board_stealCargo);
window_addButton(board_wid, -20, 20, 50, 30, "btnBoardingClose",
"Leave", board_exit);
board_update();
} }
static void board_exit(char* str) { static void board_exit(char* str) {
@ -95,11 +95,7 @@ static void board_stealCreds(char* str) {
return; return;
} }
// Calculate success. if(board_fail()) return;
if(RNG(0,100) < (int)(50.*(double)p->ship->crew/(double)player->ship->crew)) {
board_fail();
return;
}
player_credits += p->credits; player_credits += p->credits;
p->credits = 0; p->credits = 0;
@ -107,13 +103,51 @@ static void board_stealCreds(char* str) {
player_message("You manage to steal the ship's Scred."); player_message("You manage to steal the ship's Scred.");
} }
// Failed to board. static void board_stealCargo(char* str) {
static void board_fail(void) { (void)str;
int q;
Pilot* p; Pilot* p;
p = pilot_get(player_target);
if(p->ncommodities==0) {
// No cargo.
player_message("The ship has no cargo.");
return;
}
else if(player->cargo_free <= 0) {
player_message("You have no room for cargo.");
return;
}
if(board_fail()) return;
// Steal as much as possible until full - TODO: Allow the player to choose.
q = 1;
while((p->ncommodities > 0) && (q != 0)) {
q = pilot_addCargo(player, p->commodities[0].commodity,
p->commodities[0].quantity);
pilot_rmCargo(p, p->commodities[0].commodity, q);
}
board_update();
player_message("You manage to steal the ship's cargo.");
}
// Failed to board.
static int board_fail(void) {
Pilot* p;
p = pilot_get(player_target);
// Fail chance.
return 0;
if(RNG(0, 100) > (int)(50. * (double)p->ship->crew/(double)player->ship->crew))
return;
if(RNG(0, 2)==0) { if(RNG(0, 2)==0) {
// 33% of instant death. // 33% of instant death.
p = pilot_get(player_target);
p->armour = -1; p->armour = -1;
player_message("You have tripped the ship's self destruct mechanism!"); player_message("You have tripped the ship's self destruct mechanism!");
} else } else
@ -121,11 +155,13 @@ static void board_fail(void) {
player_message("The ship's security system locks you out!"); player_message("The ship's security system locks you out!");
board_exit(NULL); board_exit(NULL);
return 1;
} }
// Update the cargo and credit fields. // Update the cargo and credit fields.
static void board_update(void) { static void board_update(void) {
char str[128]; int i;
char str[128], buf[32];
char cred[10]; char cred[10];
Pilot* p; Pilot* p;
@ -133,10 +169,18 @@ static void board_update(void) {
credits2str(cred, p->credits, 2); credits2str(cred, p->credits, 2);
snprintf(str, 128, snprintf(str, 11,
"%s\n" "%s\n", cred);
"%s\n", if(p->ncommodities == 0)
cred, "none"); snprintf(buf, 128, "none");
else {
for(i = 0; i < p->ncommodities; i++) {
snprintf(buf, 32,
"%d %s\n",
p->commodities[i].quantity, p->commodities[i].commodity->name);
strncat(str, buf, 32);
}
}
window_modifyText(board_wid, "txtData", str); window_modifyText(board_wid, "txtData", str);
} }