MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // npc/chat.c -- Labernde NPCs |
| 4 | // |
| 5 | // $Id: chat.c 6801 2008-03-21 23:34:46Z Zesstra $ |
| 6 | #pragma strong_types |
| 7 | #pragma save_types |
| 8 | #pragma range_check |
| 9 | #pragma no_clone |
| 10 | #pragma pedantic |
| 11 | |
| 12 | #include <properties.h> |
| 13 | #define NEED_PROTOTYPES |
| 14 | #include <living/combat.h> |
| 15 | #include <thing/properties.h> |
| 16 | #undef NEED_PROTOTYPES |
| 17 | |
| 18 | #define ME this_object() |
| 19 | |
| 20 | /* |
| 21 | * Some simple chat variables |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * heart_beat is called so the monster may chat. |
| 26 | */ |
| 27 | void SetChats(int chance, mixed strs) { |
| 28 | if (!pointerp(strs)) |
| 29 | return; |
| 30 | SetProp(P_CHAT_CHANCE,chance); |
| 31 | SetProp(P_CHATS,strs); |
| 32 | } |
| 33 | |
| 34 | void SetAttackChats(int chance, mixed strs) { |
| 35 | if (!pointerp(strs)) |
| 36 | return; |
| 37 | SetProp(P_ACHAT_CHANCE,chance); |
| 38 | SetProp(P_ACHATS,strs); |
| 39 | } |
| 40 | |
Christian Georg Becker | a32ae76 | 2017-04-03 01:06:34 +0200 | [diff] [blame] | 41 | #define SR_CHAT_MSG 0 |
| 42 | #define SR_CHAT_TYP 1 |
| 43 | |
| 44 | protected void process_chat(mixed strs) { |
| 45 | if(pointerp(strs) && sizeof(strs)) { |
| 46 | int msg_typ; |
| 47 | mixed entry = strs[random(sizeof(strs))]; |
| 48 | |
| 49 | if(pointerp(entry) && sizeof(entry)>=2 && intp(entry[SR_CHAT_TYP])) { |
| 50 | msg_typ = entry[SR_CHAT_TYP]; |
| 51 | entry = entry[SR_CHAT_MSG]; |
| 52 | } |
| 53 | if(closurep(entry)) |
| 54 | entry = funcall(entry, &msg_typ); |
Arathorn | 4fbd0b8 | 2018-02-05 15:33:55 +0100 | [diff] [blame] | 55 | entry = process_string(entry); |
Christian Georg Becker | a32ae76 | 2017-04-03 01:06:34 +0200 | [diff] [blame] | 56 | |
| 57 | if(msg_typ) |
| 58 | msg_typ|=MSG_DONT_STORE|MSG_DONT_BUFFER; |
Arathorn | 4fbd0b8 | 2018-02-05 15:33:55 +0100 | [diff] [blame] | 59 | |
| 60 | // Nur nicht-leere Meldungen ausgeben, und nur dann, wenn der NPC noch |
| 61 | // existiert, denn im Falle von Attack-Chats koennte dieser z.B. durch |
| 62 | // reflektierten Schaden zerstoert worden sein. |
| 63 | if ( stringp(entry) && sizeof(entry) && objectp(this_object()) ) |
| 64 | send_room(environment(), |
| 65 | entry, |
| 66 | msg_typ||(MT_LOOK|MT_LISTEN|MT_FEEL|MT_SMELL| |
| 67 | MSG_DONT_STORE|MSG_DONT_BUFFER|MSG_DONT_WRAP)); |
Christian Georg Becker | a32ae76 | 2017-04-03 01:06:34 +0200 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 71 | void DoAttackChat() { |
| 72 | string* c; |
| 73 | if (!ME || !environment(ME)) |
| 74 | return; |
| 75 | if (QueryProp(P_DISABLE_ATTACK)>0)return ; |
| 76 | if (random(100) < QueryProp(P_ACHAT_CHANCE)) |
Christian Georg Becker | a32ae76 | 2017-04-03 01:06:34 +0200 | [diff] [blame] | 77 | process_chat(QueryProp(P_ACHATS)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void DoChat() { |
| 81 | string *c; |
| 82 | if (!ME || !environment(ME)) |
| 83 | return; |
| 84 | if (random(100) < QueryProp(P_CHAT_CHANCE)) |
Christian Georg Becker | a32ae76 | 2017-04-03 01:06:34 +0200 | [diff] [blame] | 85 | process_chat(QueryProp(P_CHATS)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | protected void heart_beat() |
| 89 | { |
| 90 | if( InFight() ) DoAttackChat(); |
| 91 | else DoChat(); |
| 92 | } |