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