[Add] Gave AI customizable bribe messages.

This commit is contained in:
Allanis 2014-01-27 15:02:00 +00:00
parent 9cf2f1c9e9
commit fb8c13495d
7 changed files with 107 additions and 22 deletions

View File

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

View File

@ -7,6 +7,11 @@ aggressive = true
function create()
ai.setcredits(rnd.int(1000, ai.shipprice()/200))
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
function taunt(target, offense)

View File

@ -10,6 +10,20 @@ function create()
if rnd.int(0,2)==0 then
ai.broadcast("The Empire is watching")
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()
end

View File

@ -7,9 +7,24 @@ armour_run = 80
armour_return = 100
function create()
ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
mem.bribe = math.sqrt(ai.shipmass()) * (300. * rnd.int() + 850.)
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
function taunt(target, offense)

View File

@ -4,7 +4,7 @@ function sos()
msg = {
"Mayday! 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)])
end
@ -12,6 +12,8 @@ end
function create()
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.
num = rnd.int(12)
if num < 5 then

View File

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

View File

@ -20,8 +20,9 @@
static Pilot* comm_pilot = NULL; /**< Pilot currently talking to. */
/* 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 char* comm_getBribeString(char* str);
/* Extern. */
void ai_setPilot(Pilot* p);
@ -115,21 +116,35 @@ int comm_open(unsigned int pilot) {
* @param wid ID of window calling the function.
* @param str Unused.
*/
static void comm_bribe(unsigned int wid, char* str) {
(void)str;
static void comm_bribe(unsigned int wid, char* unused) {
(void)unused;
int answer;
int price;
char* str;
/* Set up for the comm_get* functions. */
ai_setPilot(comm_pilot);
price = comm_getBribeAmount();
/* Unbribeable. */
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;
}
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);
/* Bribe message. */
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. */
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.");
} else {
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);
/* Reopen window. */
window_destroy(wid);
@ -158,27 +177,51 @@ static void comm_bribe(unsigned int wid, char* str) {
*/
static unsigned int comm_getBribeAmount(void) {
lua_State* L;
double bribe;
unsigned int bribe;
/* Set up the state. */
ai_setPilot(comm_pilot);
L = comm_pilot->ai->L;
lua_getglobal(L, "mem");
/* Get the bribe amount. */
lua_getglobal(L, "mem");
lua_getfield(L, -1, "bribe");
/* If not number consider unbribeable. */
if(!lua_isnumber(L, -1)) {
lua_pop(L, 2);
return 0;
}
/* Get amount. */
bribe = (unsigned int) lua_tonumber(L, -1);
/* Clean up. */
if(!lua_isnumber(L, -1))
bribe = 0;
else
bribe = (unsigned int)lua_tonumber(L, -1);
lua_pop(L, 2);
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;
}