blob: 9eb91848ed13ec028286b9f6d2c9c85cbb6778c1 [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 */
Zesstra082f4eb2022-12-23 19:55:39 +010026void SetChats(int chance,
27 <string|closure|<string|closure|int>* >* strs = QueryProp(P_CHATS))
28{
29 SetProp(P_CHAT_CHANCE, chance);
30 SetProp(P_CHATS, strs);
MG Mud User88f12472016-06-24 23:31:02 +020031}
32
Zesstra082f4eb2022-12-23 19:55:39 +010033void SetAttackChats(int chance,
34 <string|closure|<string|closure|int>* >* strs = QueryProp(P_ACHATS))
35{
36 SetProp(P_ACHAT_CHANCE, chance);
37 SetProp(P_ACHATS, strs);
MG Mud User88f12472016-06-24 23:31:02 +020038}
39
Christian Georg Beckera32ae762017-04-03 01:06:34 +020040#define SR_CHAT_MSG 0
41#define SR_CHAT_TYP 1
42
Zesstra082f4eb2022-12-23 19:55:39 +010043protected void process_chat(<string|closure|<string|closure|int>* >* strs)
44{
45 if (!sizeof(strs))
Arathorn7c458422022-12-13 23:39:54 +010046 return;
Christian Georg Beckera32ae762017-04-03 01:06:34 +020047
Arathorn7c458422022-12-13 23:39:54 +010048 int msg_typ;
Zesstra082f4eb2022-12-23 19:55:39 +010049 <string|closure|<string|closure|int>*> entry = strs[random(sizeof(strs))];
Christian Georg Beckera32ae762017-04-03 01:06:34 +020050
Arathorn7c458422022-12-13 23:39:54 +010051 if(pointerp(entry) && sizeof(entry)>=2 && intp(entry[SR_CHAT_TYP])) {
52 msg_typ = entry[SR_CHAT_TYP];
53 entry = entry[SR_CHAT_MSG];
Christian Georg Beckera32ae762017-04-03 01:06:34 +020054 }
Arathorn7c458422022-12-13 23:39:54 +010055
56 if(closurep(entry))
57 entry = funcall(entry, &msg_typ);
58
59 // Falls wir in der Chat-Closure zerstoert wurden, nichts weiter tun.
60 if (!objectp(ME))
61 return;
62
63 if (msg_typ)
64 msg_typ |= MSG_DONT_STORE|MSG_DONT_BUFFER;
65
66 entry = process_string(entry);
67
68 // Falls wir durch process_string() zerstoert wurden oder keine Meldung
69 // (mehr) existiert, nichts weiter tun.
70 if (!objectp(ME) || !stringp(entry) || !sizeof(entry))
71 return;
72
73 send_room(environment(),
74 entry,
75 msg_typ||(MT_LOOK|MT_LISTEN|MT_FEEL|MT_SMELL|
76 MSG_DONT_STORE|MSG_DONT_BUFFER|MSG_DONT_WRAP));
Christian Georg Beckera32ae762017-04-03 01:06:34 +020077}
78
MG Mud User88f12472016-06-24 23:31:02 +020079void DoAttackChat() {
MG Mud User88f12472016-06-24 23:31:02 +020080 if (!ME || !environment(ME))
81 return;
82 if (QueryProp(P_DISABLE_ATTACK)>0)return ;
83 if (random(100) < QueryProp(P_ACHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020084 process_chat(QueryProp(P_ACHATS));
MG Mud User88f12472016-06-24 23:31:02 +020085}
86
87void DoChat() {
MG Mud User88f12472016-06-24 23:31:02 +020088 if (!ME || !environment(ME))
89 return;
90 if (random(100) < QueryProp(P_CHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020091 process_chat(QueryProp(P_CHATS));
MG Mud User88f12472016-06-24 23:31:02 +020092}
93
94protected void heart_beat()
95{
96 if( InFight() ) DoAttackChat();
97 else DoChat();
98}