[Add] Gave AI customizable bribe messages.

This commit is contained in:
Allanis 2014-02-01 22:09:49 +00:00
parent 9cf2f1c9e9
commit 3540ba0724
7 changed files with 107 additions and 22 deletions

View File

@ -5,3 +5,8 @@ control_rate = 0.5 -- Lower control rate.
aggressive = true aggressive = true
land_planet = false land_planet = false
function create()
mem.bribe_no = "No response."
attack_choose()
end

View File

@ -7,6 +7,11 @@ aggressive = true
function create() function create()
ai.setcredits(rnd.int(1000, ai.shipprice()/200)) ai.setcredits(rnd.int(1000, ai.shipprice()/200))
attack_choose() attack_choose()
if rnd.int() > 0.4 then
mem.bribe_no = "\"I shall especially enjoy your death.\""
else
mem.bribe_no = "\"You shall not buy my honor!\""
end
end end
function taunt(target, offense) function taunt(target, offense)

View File

@ -10,6 +10,20 @@ function create()
if rnd.int(0,2)==0 then if rnd.int(0,2)==0 then
ai.broadcast("The Empire is watching") ai.broadcast("The Empire is watching")
end end
if rnd.int() > 0.7 then
mem.bribe = math.sqrt(ai.shipmass())*(500. * rnd.int() + 1750.)
mem.bribe_prompt = string.format("\"For some %d credits I could forget \
about seeing you.\"", mem.bribe)
mem.bribe_paid = "\"Now, scram, before I change my mind.\""
else
if rnd.int() > 0.5 then
mem.bribe_no = "\"You won't buy your way out of this one.\""
else
mem.bribe_no = "\"The Empire likes to make examples out of scum like you.\""
end
end
attack_choose() attack_choose()
end end

View File

@ -7,9 +7,24 @@ armour_run = 80
armour_return = 100 armour_return = 100
function create() function create()
ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
mem.bribe = math.sqrt(ai.shipmass()) * (300. * rnd.int() + 850.)
attack_choose() attack_choose()
ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
-- Deal with bribeability.
if rnd.int() < 0.05 then
mem.bribe_no = = "\"You won't be able to slide out of this one!\""
else
mem.bribe = math.sqrt(ai.shipmass()) * (300. * rnd.int() + 850.)
if rnd.int() > 0.5 then
mem.bribe_prompt = string.format("\"It'll cost you %d credits for me to ifnore your pile \
of rubbish.\"", mem.bribe)
mem.bribe_paid = "\"You're lucky I'm so kind.\""
else
mem.bribe_prompt = string.format("\"I'm in a good mood so I'll let you go for \
%d credits.\"", mem.bribe)
mem.bribe_paid = "\"Life doesn't get easier then this.\""
end
end
end end
function taunt(target, offense) function taunt(target, offense)

View File

@ -4,7 +4,7 @@ function sos()
msg = { msg = {
"Mayday! We are under attack!", "Mayday! We are under attack!",
"Requesting assistance. We are under attack!", "Requesting assistance. We are under attack!",
"Merchant vessle here under attack! HELP!" "Merchant vessel here under attack! HELP!"
} }
ai.broadcast(msg[rnd.int(1, #msg)]) ai.broadcast(msg[rnd.int(1, #msg)])
end end
@ -12,6 +12,8 @@ end
function create() function create()
ai.setcredits(rnd.int(100, ai.shipprice()/50)) ai.setcredits(rnd.int(100, ai.shipprice()/50))
mem.bribe_no = "\"The space Traders do not negotiate with criminals.\""
-- Some stuff has more than others. -- Some stuff has more than others.
num = rnd.int(12) num = rnd.int(12)
if num < 5 then if num < 5 then

View File

@ -443,6 +443,7 @@ static int ai_loadProfile(char* filename) {
/* Open basic Lua stuff. */ /* Open basic Lua stuff. */
llua_loadBasic(L); llua_loadBasic(L);
llua_load(L, luaopen_string); /* Open string. */
/* Constants. */ /* Constants. */
lua_regnumber(L, "player", PLAYER_ID); /* Player id. */ lua_regnumber(L, "player", PLAYER_ID); /* Player id. */

View File

@ -20,8 +20,9 @@
static Pilot* comm_pilot = NULL; /**< Pilot currently talking to. */ static Pilot* comm_pilot = NULL; /**< Pilot currently talking to. */
/* Static. */ /* Static. */
static void comm_bribe(unsigned int wid, char* str); static void comm_bribe(unsigned int wid, char* unused);
static unsigned int comm_getBribeAmount(void); static unsigned int comm_getBribeAmount(void);
static char* comm_getBribeString(char* str);
/* Extern. */ /* Extern. */
void ai_setPilot(Pilot* p); void ai_setPilot(Pilot* p);
@ -115,21 +116,35 @@ int comm_open(unsigned int pilot) {
* @param wid ID of window calling the function. * @param wid ID of window calling the function.
* @param str Unused. * @param str Unused.
*/ */
static void comm_bribe(unsigned int wid, char* str) { static void comm_bribe(unsigned int wid, char* unused) {
(void)str; (void)unused;
int answer; int answer;
int price; int price;
char* str;
/* Set up for the comm_get* functions. */
ai_setPilot(comm_pilot);
price = comm_getBribeAmount(); price = comm_getBribeAmount();
/* Unbribeable. */ /* Unbribeable. */
if(price == 0) { if(price == 0) {
dialogue_msg("Bribe Pilot", "\"Money won't save your hide now!\""); str = comm_getBribeString("bribe_no");
if(str == NULL)
dialogue_msg("Bribe Pilot", "\"Money won't save your hide now!\"");
else
dialogue_msg("Bribe Pilot", "%s", str);
return; return;
} }
answer = dialogue_YesNo("Bribe Pilot", "\"I'm gonna need at least %d credits \ /* Bribe message. */
to not leave you as a hunk of floating debris.\"\n\npay %d Credits?", price, price); str = comm_getBribeString("bribe_prompt");
if(str == NULL) {
answer = dialogue_YesNo("Bribe Pilot", "\"I'm gonna need at least %d credits to not leave \
you as a hunk of floating debris.\"\n\nPay %d credits?", price, price);
}
else
answer = dialogue_YesNo("Bribe Pilot", "%s\n\npay %d credits?", str, price);
/* Said no. */ /* Said no. */
if(answer == 0) { if(answer == 0) {
@ -142,7 +157,11 @@ static void comm_bribe(unsigned int wid, char* str) {
dialogue_msg("Bribe Pilot", "You don't have enough credits for the bribary."); dialogue_msg("Bribe Pilot", "You don't have enough credits for the bribary.");
} else { } else {
player->credits -= price; player->credits -= price;
dialogue_msg("Bribe Pilot", "\"Pleasure to do business with you.\""); str = comm_getBribeString("bribe_paid");
if(str == NULL)
dialogue_msg("Bribe Pilot", "\"Pleasure to do business with you.\"");
else
dialogue_msg("Bribe Pilot", "%s", str);
pilot_setFlag(comm_pilot, PILOT_BRIBED); pilot_setFlag(comm_pilot, PILOT_BRIBED);
/* Reopen window. */ /* Reopen window. */
window_destroy(wid); window_destroy(wid);
@ -158,27 +177,51 @@ static void comm_bribe(unsigned int wid, char* str) {
*/ */
static unsigned int comm_getBribeAmount(void) { static unsigned int comm_getBribeAmount(void) {
lua_State* L; lua_State* L;
double bribe; unsigned int bribe;
/* Set up the state. */ /* Set up the state. */
ai_setPilot(comm_pilot);
L = comm_pilot->ai->L; L = comm_pilot->ai->L;
lua_getglobal(L, "mem");
/* Get the bribe amount. */ /* Get the bribe amount. */
lua_getglobal(L, "mem");
lua_getfield(L, -1, "bribe"); lua_getfield(L, -1, "bribe");
/* If not number consider unbribeable. */ /* If not number consider unbribeable. */
if(!lua_isnumber(L, -1)) { if(!lua_isnumber(L, -1))
lua_pop(L, 2); bribe = 0;
return 0; else
} bribe = (unsigned int)lua_tonumber(L, -1);
/* Get amount. */
bribe = (unsigned int) lua_tonumber(L, -1);
/* Clean up. */
lua_pop(L, 2); lua_pop(L, 2);
return bribe; return bribe;
} }
/**
* @brief Get a string from the pilots memory.
*
* Valid targets are:
* -- bribe_no : Unbribe message.
* -- bribe_prompt : Bribe prompt.
* -- bribe_paid: paid message.
*
* @param str String to get.
* @return String matching str.
*/
static char* comm_getBribeString(char* str) {
lua_State* L;
char* ret;
/* Get memory table. */
L = comm_pilot->ai->L;
lua_getglobal(L, "mem");
/* Get str message. */
lua_getfield(L, -1, str);
if(!lua_isstring(L, -1))
ret = NULL;
else
ret = (char*) lua_tostring(L, -1);
lua_pop(L, 2);
return ret;
}