blob: ff6990eff6bcd76a4638bf62ffb7387774533c99 [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
MG Mud User88f12472016-06-24 23:31:02 +020010
11#include <properties.h>
12#define NEED_PROTOTYPES
13#include <living/combat.h>
14#include <thing/properties.h>
15#undef NEED_PROTOTYPES
16
17#define ME this_object()
18
19/*
20 * Some simple chat variables
21 */
22
23/*
24 * heart_beat is called so the monster may chat.
25 */
26void SetChats(int chance, mixed strs) {
27 if (!pointerp(strs))
28 return;
29 SetProp(P_CHAT_CHANCE,chance);
30 SetProp(P_CHATS,strs);
31}
32
33void SetAttackChats(int chance, mixed strs) {
34 if (!pointerp(strs))
35 return;
36 SetProp(P_ACHAT_CHANCE,chance);
37 SetProp(P_ACHATS,strs);
38}
39
Christian Georg Beckera32ae762017-04-03 01:06:34 +020040#define SR_CHAT_MSG 0
41#define SR_CHAT_TYP 1
42
43protected void process_chat(mixed strs) {
44 if(pointerp(strs) && sizeof(strs)) {
45 int msg_typ;
46 mixed entry = strs[random(sizeof(strs))];
47
48 if(pointerp(entry) && sizeof(entry)>=2 && intp(entry[SR_CHAT_TYP])) {
49 msg_typ = entry[SR_CHAT_TYP];
50 entry = entry[SR_CHAT_MSG];
51 }
52 if(closurep(entry))
53 entry = funcall(entry, &msg_typ);
Arathorn4fbd0b82018-02-05 15:33:55 +010054 entry = process_string(entry);
Christian Georg Beckera32ae762017-04-03 01:06:34 +020055
56 if(msg_typ)
57 msg_typ|=MSG_DONT_STORE|MSG_DONT_BUFFER;
Arathorn4fbd0b82018-02-05 15:33:55 +010058
59 // Nur nicht-leere Meldungen ausgeben, und nur dann, wenn der NPC noch
60 // existiert, denn im Falle von Attack-Chats koennte dieser z.B. durch
61 // reflektierten Schaden zerstoert worden sein.
62 if ( stringp(entry) && sizeof(entry) && objectp(this_object()) )
63 send_room(environment(),
64 entry,
65 msg_typ||(MT_LOOK|MT_LISTEN|MT_FEEL|MT_SMELL|
66 MSG_DONT_STORE|MSG_DONT_BUFFER|MSG_DONT_WRAP));
Christian Georg Beckera32ae762017-04-03 01:06:34 +020067 }
68}
69
MG Mud User88f12472016-06-24 23:31:02 +020070void DoAttackChat() {
71 string* c;
72 if (!ME || !environment(ME))
73 return;
74 if (QueryProp(P_DISABLE_ATTACK)>0)return ;
75 if (random(100) < QueryProp(P_ACHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020076 process_chat(QueryProp(P_ACHATS));
MG Mud User88f12472016-06-24 23:31:02 +020077}
78
79void DoChat() {
80 string *c;
81 if (!ME || !environment(ME))
82 return;
83 if (random(100) < QueryProp(P_CHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020084 process_chat(QueryProp(P_CHATS));
MG Mud User88f12472016-06-24 23:31:02 +020085}
86
87protected void heart_beat()
88{
89 if( InFight() ) DoAttackChat();
90 else DoChat();
91}