MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // living/comm.c -- communiction module for livings |
| 4 | // |
| 5 | // $Id$ |
| 6 | |
| 7 | #pragma strong_types,save_types |
| 8 | #pragma no_clone |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | #pragma range_check |
| 10 | |
Bugfix | b1d9b4d | 2021-09-14 20:07:04 +0200 | [diff] [blame^] | 11 | inherit "/std/living/comm_structs"; |
| 12 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 13 | #include <defines.h> |
Bugfix | b1d9b4d | 2021-09-14 20:07:04 +0200 | [diff] [blame^] | 14 | #include <thing/language.h> |
| 15 | #define NEED_PROTOTYPES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | #include <living/comm.h> |
Bugfix | b1d9b4d | 2021-09-14 20:07:04 +0200 | [diff] [blame^] | 17 | #undef NEED_PROTOTYPES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 18 | |
| 19 | void create_super() |
| 20 | { |
| 21 | set_next_reset(-1); |
| 22 | } |
| 23 | |
| 24 | protected string comm_guess_action() { |
| 25 | string cmd; |
| 26 | string action = query_verb(); |
| 27 | // Die Aktionen sind intern in der Regel nach den haeufigsten Kommandoverben |
| 28 | // dieser Aktion benannt. Bei einigen Aktionen sind mehrere Kommandoverben |
| 29 | // ueblich, die sollen hier noch abgehandelt werden. |
| 30 | switch(action) { |
| 31 | case "nehme": |
| 32 | // MA_TAKE == nimm |
| 33 | action = MA_TAKE; |
| 34 | break; |
| 35 | |
Bugfix | 1450fbd | 2022-10-05 23:03:44 +0200 | [diff] [blame] | 36 | case "gebe": |
| 37 | // MA_GIVE == "gib" |
| 38 | action = MA_GIVE; |
| 39 | break; |
| 40 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 41 | case "norden": |
| 42 | case "nordosten": |
| 43 | case "osten": |
| 44 | case "suedosten": |
| 45 | case "sueden": |
| 46 | case "suedwesten": |
| 47 | case "westen": |
| 48 | case "nordwesten": |
| 49 | case "oben": |
| 50 | case "unten": |
| 51 | case "betrete": |
| 52 | case "verlasse": |
| 53 | case "teleport": |
| 54 | case "teleportiere": |
| 55 | action = MA_MOVE; |
| 56 | break; |
| 57 | |
| 58 | case "unt": |
| 59 | action = MA_LOOK; |
| 60 | break; |
| 61 | |
| 62 | case "wirf": |
| 63 | if (strstr(query_command(), " weg") > -1) |
| 64 | action = MA_PUT; |
| 65 | break; |
| 66 | |
| 67 | case "stecke": |
| 68 | cmd = query_command(); |
| 69 | if (strstr(cmd, " weg") > -1) |
| 70 | action = MA_UNWIELD; |
| 71 | else if (strstr(cmd," in ") > -1) |
| 72 | action = MA_PUT; |
| 73 | break; |
| 74 | |
| 75 | case "ziehe": |
| 76 | cmd = query_command(); |
| 77 | if (strstr(cmd, " an") > -1) |
| 78 | action = MA_WEAR; |
| 79 | else if (strstr(cmd, " aus") > -1) |
| 80 | action = MA_UNWEAR; |
| 81 | break; |
| 82 | |
| 83 | case "esse": |
| 84 | case "friss": |
| 85 | action = MA_EAT; |
| 86 | break; |
| 87 | |
| 88 | case "saufe": |
| 89 | action = MA_DRINK; |
| 90 | break; |
| 91 | |
| 92 | case "hoere": |
| 93 | //MA_LISTEN == lausche |
| 94 | action = MA_LISTEN; |
| 95 | break; |
| 96 | case "lese": |
| 97 | action = MA_READ; |
| 98 | break; |
| 99 | |
| 100 | case ":": |
| 101 | case ";": |
| 102 | action = MA_EMOTE; |
| 103 | break; |
| 104 | |
| 105 | case "zerbreche": |
| 106 | case "zerstoere": |
| 107 | case "verbrenne": |
| 108 | case "entsorge": |
| 109 | action = MA_REMOVE; |
| 110 | break; |
| 111 | } |
| 112 | return action; |
| 113 | } |
| 114 | |
| 115 | protected int comm_guess_message_type(string action, mixed origin) { |
| 116 | // everything not mentioned in the switch becomes MT_LOOK. |
| 117 | switch(action) { |
| 118 | case MA_FIGHT: |
| 119 | // Kampf kann man meisten sowohl sehen als auch hoeren. |
| 120 | return MT_LOOK | MT_LISTEN; |
| 121 | case MA_LISTEN: |
| 122 | case MA_SAY: |
| 123 | return MT_LISTEN; |
| 124 | case MA_FEEL: |
| 125 | return MT_FEEL; |
| 126 | case MA_SMELL: |
| 127 | return MT_SMELL; |
| 128 | case MA_CHANNEL: |
| 129 | return MT_COMM | MT_FAR; |
| 130 | case MA_EMOTE: |
| 131 | if (objectp(origin) |
| 132 | && environment(origin) == environment()) |
| 133 | return MT_COMM; |
| 134 | else |
| 135 | return MT_COMM | MT_FAR; |
| 136 | case MA_SHOUT: |
| 137 | return MT_LISTEN | MT_FAR; |
| 138 | } |
| 139 | // die meisten Aktionen sind zumindest sichtbar... |
| 140 | return MT_LOOK; |
| 141 | } |
| 142 | |
Bugfix | b1d9b4d | 2021-09-14 20:07:04 +0200 | [diff] [blame^] | 143 | // Wrapper fuer ReceiveMsg() |
| 144 | public int* ReceiveSay(string msg, string prefix = 0, |
| 145 | struct msg_s* sense_blocked = |
| 146 | ({(<msg_s> |
| 147 | msg: "@WER1 bewegt die Lippen, Du hoerst jedoch nichts.", |
| 148 | type: MT_LOOK)})) |
| 149 | { |
| 150 | int* res = ({0, -1}); |
| 151 | |
| 152 | if(!prefix) |
| 153 | { |
| 154 | prefix = previous_object().Name(WER, 1) + " sagt: "; |
| 155 | } |
| 156 | |
| 157 | res[0] = ReceiveMsg( |
| 158 | replace_personal(msg, ({previous_object(), this_player()}) - ({0}), 1), |
| 159 | MT_LISTEN | MSG_BS_LEAVE_LFS, |
| 160 | MA_SAY, |
| 161 | prefix); |
| 162 | |
| 163 | if(res[0] == MSG_SENSE_BLOCK) |
| 164 | { |
| 165 | // Um eine Nummer zurueckzugeben, ist hier leider eine for-Schleife noetig. |
| 166 | for(int i = 0; i < sizeof(sense_blocked); ++i) |
| 167 | { |
| 168 | res[0] = ReceiveMsg( |
| 169 | replace_personal(sense_blocked[i].msg, ({previous_object(), |
| 170 | this_player()}) - ({0}), 1), |
| 171 | sense_blocked[i].type | MSG_BS_LEAVE_LFS, |
| 172 | MA_SAY, |
| 173 | sense_blocked[i].prefix); |
| 174 | if(res[0] != MSG_SENSE_BLOCK) |
| 175 | { |
| 176 | res[1] = i; |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | return res; |
| 182 | } |
| 183 | |
| 184 | public int ReceiveNotify(string msg, string action) |
| 185 | { |
| 186 | // Da MT_NOTIFICATION immer zugestellt wird, ist keine Fehlerbehandlung |
| 187 | // notwendig. |
| 188 | return ReceiveMsg( |
| 189 | msg, |
| 190 | // MSG_DONT_IGNORE waere wegen MT_NOTIFICATION inhaltlich nicht noetig, |
| 191 | // spart aber ein paar Ticks. |
| 192 | MT_NOTIFICATION | MSG_BS_LEAVE_LFS | MSG_DONT_IGNORE, |
| 193 | action); |
| 194 | } |
| 195 | |
| 196 | public int ReceiveTeilemit(string msg) |
| 197 | { |
| 198 | // Blockierte Sinne sind hier kein Problem, ergo keine Fehlerbehandlung. |
| 199 | return ReceiveMsg( |
| 200 | replace_personal(msg, ({previous_object(), this_player()}) - ({0}), 1), |
| 201 | MT_COMM | MT_FAR | MSG_BS_LEAVE_LFS | MSG_DONT_STORE, |
| 202 | MA_TELL, |
| 203 | previous_object().Name(WER, 1) + "teilt Dir mit: "); |
| 204 | } |
| 205 | |
| 206 | public int* ReceiveMultisense(struct msg_s* msgs, |
| 207 | string action = 0, int commontypes = 0) |
| 208 | { |
| 209 | int* res = ({0, -1}); |
| 210 | |
| 211 | // Um eine Nummer zurueckzugeben, ist hier leider eine for-Schleife noetig. |
| 212 | for(int i = 0; i < sizeof(msgs); ++i) |
| 213 | { |
| 214 | res[0] = ReceiveMsg( |
| 215 | replace_personal(msgs[i].msg, ({previous_object(), this_player()}), 1), |
| 216 | msgs[i].type | MSG_BS_LEAVE_LFS | commontypes, |
| 217 | action, |
| 218 | msgs[i].prefix); |
| 219 | if(res[0] == MSG_DELIVERED) |
| 220 | { |
| 221 | res[1] = i; |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | return res; |
| 226 | } |