MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // DANCETOOL.C Stand: 10.12.94 Dancer |
| 2 | // |
| 3 | // Kleines Tool zum Schreiben und Nachsehen von Details. |
| 4 | // |
| 5 | // |
| 6 | |
| 7 | inherit "std/thing"; |
| 8 | |
| 9 | #include <properties.h> |
| 10 | #include <defines.h> |
| 11 | #include <wizlevels.h> |
| 12 | |
| 13 | #define bs( x ) break_string( x, 78 ) |
| 14 | |
| 15 | private int i, counter, first_detail_line, startline, endline; |
| 16 | private string *detail_shorts, *newstring, *file_lines, *new_lines; |
| 17 | private string detail_long, save_string, old_file, new_file, actual_file, |
| 18 | detail_text; |
| 19 | |
| 20 | void create() |
| 21 | { |
| 22 | ::create(); |
| 23 | SetProp( P_AUTOLOADOBJ,1 ); |
| 24 | SetProp( P_NAME, "Dancers Sandtigerkralle" ); |
| 25 | SetProp( P_GENDER, FEMALE ); |
| 26 | SetProp( P_SHORT, "Dancers Sandtigerkralle" ); |
| 27 | SetProp( P_LONG, bs( "Die Sandtigerkralle von Dancer ist "+ |
| 28 | "ein kleines Tool, mit dem Du gewoehnliche Details "+ |
| 29 | "in allen Raeumen nachschauen und in Deinen eigenen "+ |
| 30 | "hinzufuegen kannst. Weitere Informationen kannst Du "+ |
| 31 | "mit dem Befehl <dancetool> bekommen." ) ); |
| 32 | SetProp( P_ARTICLE, 2 ); |
| 33 | SetProp( P_WEIGHT, 500 ); |
| 34 | SetProp( P_VALUE, 10000 ); |
| 35 | SetProp( P_NOBUY, 1 ); |
| 36 | SetProp( P_NODROP, 1 ); |
| 37 | AddId( "kralle" ); |
| 38 | AddId( "sandtigerkralle" ); |
| 39 | AddId( "tigerkralle" ); |
| 40 | AddId( "dancetool" ); |
| 41 | AddId( "dancertool" ); |
| 42 | seteuid(getuid(this_object())); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | void init() |
| 47 | { |
| 48 | if (!IS_LEARNER(this_player())) return; |
| 49 | ::init(); |
| 50 | add_action("query_add_details", "show_detail" ); |
| 51 | add_action("query_add_details", "show_details" ); |
| 52 | add_action("query_add_details", "sd" ); |
| 53 | add_action("set_add_detail", "add_detail" ); |
| 54 | add_action("set_add_detail", "add_details" ); |
| 55 | add_action("set_add_detail", "ad" ); |
| 56 | add_action("give_info", "dancetool" ); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | int give_info() |
| 61 | { |
| 62 | write( "-----------------------------------------------------------------------------\n" ); |
| 63 | write( "Die Sandtigerkralle ermoeglicht folgende Befehle:\n" ); |
| 64 | write( "\nadd_detail, add_details oder ad:\n" ); |
| 65 | write( bs( "Ruft einen kleinen AddDetail-Editor auf, mit dem Du "+ |
| 66 | "Details in Deine eigenen Raeume einfuegen kannst. Als Argument "+ |
| 67 | "kann hinter den Befehl der Filename eines Raumes eingegeben "+ |
| 68 | "werden. Wird kein Argument eingegeben, so wird der Raum "+ |
| 69 | "genommen, in dem Du gerade stehst. Achtung: Es koennen "+ |
| 70 | "nur Details in Raeume eingefuegt haben, die bereits ein "+ |
| 71 | "AddDetail in ihrem create() haben. Du musst die Lupe haben, "+ |
| 72 | "da der Raum nach dem Einfuegen des Details automatisch "+ |
| 73 | "neu geladen wird." ) ); |
| 74 | write( "\nshow_detail, show_details oder sd:\n" ); |
| 75 | write( bs( "Zeigt Dir alle Zeilen des angesprochenen Raumes bzw. "+ |
| 76 | "des Raumes in dem Du stehst, die ein AddDetail "+ |
| 77 | "beinhalten. So kannst Du kontrollieren, welche Details "+ |
| 78 | "Du schon eingebaut hast." ) ); |
| 79 | write( "-----------------------------------------------------------------------------\n" ); |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | int renew_variables() |
| 85 | { |
| 86 | i = counter = first_detail_line = startline = endline = 0; |
| 87 | detail_shorts = newstring = file_lines = new_lines = ({}); |
| 88 | detail_long = save_string = old_file = new_file = actual_file = detail_text = 0; |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | |
| 94 | int query_add_details( string str ) |
| 95 | { |
| 96 | string old_file, *file_lines, new_file, *new_lines, actual_file; |
| 97 | int i, counter, first_detail_line, startline, endline; |
| 98 | |
| 99 | actual_file = ""; |
| 100 | |
| 101 | if ( !str ) actual_file = object_name( environment( this_player() ) )+".c"; |
| 102 | else |
| 103 | { |
| 104 | if ( str[0..0] == "/" ) |
| 105 | { |
| 106 | if ( str[<2..] != ".c" ) |
| 107 | actual_file = str+".c"; |
| 108 | else |
| 109 | actual_file = str; |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | if ( str[<2..] != ".c" ) |
| 114 | actual_file = this_player()->QueryProp( P_CURRENTDIR )+ |
| 115 | "/"+str+".c"; |
| 116 | else |
| 117 | actual_file = this_player()->QueryProp( P_CURRENTDIR )+ |
| 118 | "/"+str; |
| 119 | } |
| 120 | } |
| 121 | if ( file_size( actual_file )==-1 ) |
| 122 | { |
| 123 | write( "File: "+actual_file+" nicht gefunden!\n" ); |
| 124 | return 1; |
| 125 | } |
| 126 | call_other( actual_file, "???" ); |
| 127 | write( "\n-----------------------------------------------------------------------------\n" ); |
| 128 | write( "Aktuelles File: "+actual_file+"\n" ); |
| 129 | write( "Filegroesse: "+file_size( actual_file )+"\n" ); |
| 130 | write( "Userid des Files: "+getuid( find_object( actual_file ) )+"\n" ); |
| 131 | new_file = ""; |
| 132 | counter = 0; |
| 133 | first_detail_line = 0; |
| 134 | old_file = read_file( actual_file ); |
| 135 | file_lines = ({ "dummy" }) + old_explode( old_file, "\n" ); |
| 136 | startline = 1; |
| 137 | endline = sizeof( file_lines )-1; |
| 138 | for( i = startline; i <= endline; i++ ) |
| 139 | { |
| 140 | new_file = new_file+file_lines[ i ]+"\n"; |
| 141 | if ( strstr( file_lines[i], "AddDetail" ) != -1 ) |
| 142 | { |
| 143 | write( file_lines[i]+"\n" ); |
| 144 | if ( !first_detail_line ) first_detail_line = i; |
| 145 | counter = counter + 1; |
| 146 | } |
| 147 | } |
| 148 | write( "Details found: "+counter+".\n" ); |
| 149 | write( "-----------------------------------------------------------------------------\n" ); |
| 150 | return 1; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | int set_add_detail( string str ) |
| 155 | { |
| 156 | |
| 157 | renew_variables(); |
| 158 | |
| 159 | if ( !str ) actual_file = object_name( environment( this_player() ) )+".c"; |
| 160 | else |
| 161 | { |
| 162 | if ( str[0..0] == "/" ) |
| 163 | { |
| 164 | if ( str[<2..] != ".c" ) |
| 165 | actual_file = str+".c"; |
| 166 | else |
| 167 | actual_file = str; |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | if ( str[<2..] != ".c" ) |
| 172 | actual_file = this_player()->QueryProp( P_CURRENTDIR )+ |
| 173 | "/"+str+".c"; |
| 174 | else |
| 175 | actual_file = this_player()->QueryProp( P_CURRENTDIR )+ |
| 176 | "/"+str; |
| 177 | } |
| 178 | } |
| 179 | if ( file_size( actual_file )==-1 ) |
| 180 | { |
| 181 | write( "File: "+actual_file+" nicht gefunden!\n" ); |
| 182 | return 1; |
| 183 | } |
| 184 | call_other( actual_file, "???" ); |
| 185 | write( "\n-----------------------------------------------------------------------------\n" ); |
| 186 | write( "Aktuelles File: "+actual_file+"\n" ); |
| 187 | write( "Filegroesse: "+file_size( actual_file )+"\n" ); |
| 188 | write( "Userid des Files: "+getuid( find_object( actual_file ) )+"\n" ); |
| 189 | new_file = ""; |
| 190 | new_lines = ({ "dummy" }); |
| 191 | counter = 0; |
| 192 | first_detail_line = 0; |
| 193 | old_file = read_file( actual_file ); |
| 194 | file_lines = ({ "dummy" }) + old_explode( old_file, "\n" ); |
| 195 | startline = 1; |
| 196 | endline = sizeof( file_lines )-1; |
| 197 | for( i = startline; i <= endline; i++ ) |
| 198 | { |
| 199 | new_file = new_file+file_lines[ i ]+"\n"; |
| 200 | if ( strstr( file_lines[i], "AddDetail" ) != -1 ) |
| 201 | { |
| 202 | if ( !first_detail_line ) first_detail_line = i; |
| 203 | counter = counter + 1; |
| 204 | } |
| 205 | } |
| 206 | if ( !first_detail_line ) |
| 207 | { |
| 208 | write( bs( "Es wurden im File "+actual_file+" keine "+ |
| 209 | "Details gefunden! Um Details hinzufuegen zu koennen, "+ |
| 210 | "muss mindestens ein AddDetail bereits vorhanden sein!" ) ); |
| 211 | write( "-----------------------------------------------------------------------------\n" ); |
| 212 | return 1; |
| 213 | } |
| 214 | write( "Details found: "+counter+".\n" ); |
| 215 | write( "-----------------------------------------------------------------------------\n" ); |
| 216 | write( "Bitte die Detail-Kuerzel eingeben:\n(Bemerkung: "+ |
| 217 | "die Kuerzel muessen mit Leerzeichen getrennt sein, "+ |
| 218 | "Abbruch mit 'q'.)\n->" ); |
| 219 | input_to( "get_detail_short" ); |
| 220 | return 1; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | int get_detail_short( string str ) |
| 225 | { |
| 226 | string dummy; |
| 227 | if ( str == "q" ) |
| 228 | { |
| 229 | tell_object( this_player(), "Abgebrochen!\n" ); |
| 230 | return 1; |
| 231 | } |
| 232 | detail_shorts = map( old_explode( str, " " ),#'lower_case); |
| 233 | dummy = break_string(implode(sort_array(map(detail_shorts,#'lower_case),#'>),", ")+":",78); |
| 234 | write( "-----------------------------------------------------------------------------\n" ); |
| 235 | write( bs ( "Bitte Beschreibung eingeben fuer das Detail mit den Namen \n" ) ); |
| 236 | write( dummy+"( Abbruch mit 'q'.)\n->" ); |
| 237 | input_to( "get_detail_long" ); |
| 238 | return 1; |
| 239 | } |
| 240 | |
| 241 | |
| 242 | int get_detail_long( string str ) |
| 243 | { |
| 244 | if ( str == "q" ) |
| 245 | { |
| 246 | write( "Abgebrochen!\n" ); |
| 247 | write( "-----------------------------------------------------------------------------\n" ); |
| 248 | return 1; |
| 249 | } |
| 250 | detail_long = break_string( "break_string( \""+str, 60 ); |
| 251 | save_string = " AddDetail( ({ "; |
| 252 | for( i = 0; i < sizeof( detail_shorts ); i ++ ) |
| 253 | { |
| 254 | if ( !(i%3) && i ) |
| 255 | save_string = save_string + "\n "; |
| 256 | if ( i < sizeof( detail_shorts ) - 1 ) |
| 257 | detail_shorts[ i ] = "\""+detail_shorts[ i ]+"\", "; |
| 258 | else |
| 259 | detail_shorts[ i ] = "\""+detail_shorts[ i ]+"\" "; |
| 260 | save_string = save_string + detail_shorts[ i ]; |
| 261 | write( detail_shorts[ i ]+"\n" ); |
| 262 | } |
| 263 | save_string = save_string + "}), \n"; |
| 264 | newstring = old_explode( detail_long,"\n"); |
| 265 | i = 0; |
| 266 | for( i = 0; i<sizeof(newstring); i++) |
| 267 | { |
| 268 | if ( i < sizeof(newstring)-1 ) |
| 269 | { |
| 270 | if ( i==0||!i ) |
| 271 | save_string = save_string +" "+newstring[i]+" \"+\n"; |
| 272 | else |
| 273 | save_string = save_string +" \""+ newstring[i]+" \"+\n"; |
| 274 | |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | if ( i==0||!i ) |
| 279 | save_string = save_string +" "+ newstring[i]+"\", 78 ) );"; |
| 280 | else |
| 281 | save_string = save_string +" \""+ newstring[i]+"\", 78 ) );"; |
| 282 | } |
| 283 | } |
| 284 | new_lines += ({ "dummy" }); |
| 285 | for ( i = 1; i < first_detail_line; i++ ) |
| 286 | { |
| 287 | new_lines += ({ file_lines[i] }); |
| 288 | } |
| 289 | new_lines += ({ save_string }); |
| 290 | for ( i = first_detail_line + 1; i <= endline+1; i++ ) |
| 291 | new_lines += ({ file_lines[ i - 1 ] }); |
| 292 | write( "-----------------------------------------------------------------------------\n" ); |
| 293 | write( bs( "Folgende Zeilen werden in die Datei "+actual_file+" geschrieben, falls `j` eingegeben wird:\n" ) ); |
| 294 | write( save_string+"\n" ); |
| 295 | write( "\nDetail speichern? (j/n)\n->" ); |
| 296 | input_to( "save_detail" ); |
| 297 | return 1; |
| 298 | } |
| 299 | |
| 300 | |
| 301 | int save_detail( string str ) |
| 302 | { |
| 303 | if ( str != "j" && str != "ja" && str != "Ja" && str != "J" ) |
| 304 | { |
| 305 | write( "Abgebrochen!\n" ); |
| 306 | write( "-----------------------------------------------------------------------------\n" ); |
| 307 | return 1; |
| 308 | } |
| 309 | if ( !rm( actual_file ) ) |
| 310 | { |
| 311 | write( "File: "+actual_file+" wurde nicht gefunden!\n" ); |
| 312 | return 1; |
| 313 | } |
| 314 | for ( i = 2; i <= endline+2; i++ ) |
| 315 | write_file( actual_file, new_lines[i]+"\n" ); |
| 316 | //write( new_lines[i]+"\n" ); |
| 317 | write( "Das Detail wurde in die Datei geschrieben.\n" ); |
| 318 | this_player()->command_me( "here make" ); |
| 319 | write( "-----------------------------------------------------------------------------\n" ); |
| 320 | return 1; |
| 321 | } |