blob: 59f70067c032d88d5506319f66f11d6c424b7d33 [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);
Arathorn4fbd0b82018-02-05 15:33:55 +010055 entry = process_string(entry);
Christian Georg Beckera32ae762017-04-03 01:06:34 +020056
57 if(msg_typ)
58 msg_typ|=MSG_DONT_STORE|MSG_DONT_BUFFER;
Arathorn4fbd0b82018-02-05 15:33:55 +010059
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 Beckera32ae762017-04-03 01:06:34 +020068 }
69}
70
MG Mud User88f12472016-06-24 23:31:02 +020071void 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 Beckera32ae762017-04-03 01:06:34 +020077 process_chat(QueryProp(P_ACHATS));
MG Mud User88f12472016-06-24 23:31:02 +020078}
79
80void DoChat() {
81 string *c;
82 if (!ME || !environment(ME))
83 return;
84 if (random(100) < QueryProp(P_CHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020085 process_chat(QueryProp(P_CHATS));
MG Mud User88f12472016-06-24 23:31:02 +020086}
87
88protected void heart_beat()
89{
90 if( InFight() ) DoAttackChat();
91 else DoChat();
92}