blob: 03a232a7a3e4d7b254d855bc29fbc308d2d82b2b [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// 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 */
27void SetChats(int chance, mixed strs) {
28 if (!pointerp(strs))
29 return;
30 SetProp(P_CHAT_CHANCE,chance);
31 SetProp(P_CHATS,strs);
32}
33
34void 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 Beckera32ae762017-04-03 01:06:34 +020041#define SR_CHAT_MSG 0
42#define SR_CHAT_TYP 1
43
44protected 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);
55
56 if(msg_typ)
57 msg_typ|=MSG_DONT_STORE|MSG_DONT_BUFFER;
58 send_room(environment(),
59 process_string(entry),
60 msg_typ||(MT_LOOK|MT_LISTEN|MT_FEEL|MT_SMELL|
61 MSG_DONT_STORE|MSG_DONT_BUFFER|MSG_DONT_WRAP));
62 }
63}
64
MG Mud User88f12472016-06-24 23:31:02 +020065void DoAttackChat() {
66 string* c;
67 if (!ME || !environment(ME))
68 return;
69 if (QueryProp(P_DISABLE_ATTACK)>0)return ;
70 if (random(100) < QueryProp(P_ACHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020071 process_chat(QueryProp(P_ACHATS));
MG Mud User88f12472016-06-24 23:31:02 +020072}
73
74void DoChat() {
75 string *c;
76 if (!ME || !environment(ME))
77 return;
78 if (random(100) < QueryProp(P_CHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020079 process_chat(QueryProp(P_CHATS));
MG Mud User88f12472016-06-24 23:31:02 +020080}
81
82protected void heart_beat()
83{
84 if( InFight() ) DoAttackChat();
85 else DoChat();
86}