blob: 4c70823ad4fcfdbcb5b3f60fab8ccd8a0dedb973 [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) {
Arathorn7c458422022-12-13 23:39:54 +010044 if (!pointerp(strs) || !sizeof(strs))
45 return;
Christian Georg Beckera32ae762017-04-03 01:06:34 +020046
Arathorn7c458422022-12-13 23:39:54 +010047 int msg_typ;
48 mixed entry = strs[random(sizeof(strs))];
Christian Georg Beckera32ae762017-04-03 01:06:34 +020049
Arathorn7c458422022-12-13 23:39:54 +010050 if(pointerp(entry) && sizeof(entry)>=2 && intp(entry[SR_CHAT_TYP])) {
51 msg_typ = entry[SR_CHAT_TYP];
52 entry = entry[SR_CHAT_MSG];
Christian Georg Beckera32ae762017-04-03 01:06:34 +020053 }
Arathorn7c458422022-12-13 23:39:54 +010054
55 if(closurep(entry))
56 entry = funcall(entry, &msg_typ);
57
58 // Falls wir in der Chat-Closure zerstoert wurden, nichts weiter tun.
59 if (!objectp(ME))
60 return;
61
62 if (msg_typ)
63 msg_typ |= MSG_DONT_STORE|MSG_DONT_BUFFER;
64
65 entry = process_string(entry);
66
67 // Falls wir durch process_string() zerstoert wurden oder keine Meldung
68 // (mehr) existiert, nichts weiter tun.
69 if (!objectp(ME) || !stringp(entry) || !sizeof(entry))
70 return;
71
72 send_room(environment(),
73 entry,
74 msg_typ||(MT_LOOK|MT_LISTEN|MT_FEEL|MT_SMELL|
75 MSG_DONT_STORE|MSG_DONT_BUFFER|MSG_DONT_WRAP));
Christian Georg Beckera32ae762017-04-03 01:06:34 +020076}
77
MG Mud User88f12472016-06-24 23:31:02 +020078void DoAttackChat() {
MG Mud User88f12472016-06-24 23:31:02 +020079 if (!ME || !environment(ME))
80 return;
81 if (QueryProp(P_DISABLE_ATTACK)>0)return ;
82 if (random(100) < QueryProp(P_ACHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020083 process_chat(QueryProp(P_ACHATS));
MG Mud User88f12472016-06-24 23:31:02 +020084}
85
86void DoChat() {
MG Mud User88f12472016-06-24 23:31:02 +020087 if (!ME || !environment(ME))
88 return;
89 if (random(100) < QueryProp(P_CHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020090 process_chat(QueryProp(P_CHATS));
MG Mud User88f12472016-06-24 23:31:02 +020091}
92
93protected void heart_beat()
94{
95 if( InFight() ) DoAttackChat();
96 else DoChat();
97}