// Function from file: ai_laws.dm public AiLaws_Custom( ) { dynamic line = null; // Warning: Super call was HERE! If anything above HERE is needed by the super call, it might break!; foreach (dynamic _a in Lang13.Enumerate(GlobalFuncs.file2list("config/silicon_laws.txt"))) { line = _a; if (!Lang13.Bool(line)) { continue; } if (String13.Find(line, "#", 1, 2) != 0) { continue; } this.add_inherent_law(line); } if (!(this.inherent.len != 0)) { GlobalFuncs.log_law("AI created with empty custom laws, laws set to Asimov. Please check silicon_laws.txt."); this.add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm."); this.add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law."); this.add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law."); GlobalFuncs.warning("" + "Invalid custom AI laws, check silicon_laws.txt" + " in " + "code/datums/ai_laws.dm" + " at line " + 123 + " src: " + this + " usr: "******"."); return; } return; }
private string trim_text(string what = null, bool?trim_quotes = null) { if (trim_quotes == null) { trim_quotes = false; } while (Lang13.Length(what) != 0 && String13.Find(what, " ", 1, 2) != 0) { what = String13.SubStr(what, 2, 0); } while (Lang13.Length(what) != 0 && String13.Find(what, " ", Lang13.Length(what), 0) != 0) { what = String13.SubStr(what, 1, Lang13.Length(what)); } if (trim_quotes == true) { while (Lang13.Length(what) != 0 && String13.Find(what, this.quote, 1, 2) != 0) { what = String13.SubStr(what, 2, 0); } while (Lang13.Length(what) != 0 && String13.Find(what, this.quote, Lang13.Length(what), 0) != 0) { what = String13.SubStr(what, 1, Lang13.Length(what)); } } return(what); }
private int find_next_delimiter_position(string text = null, int initial_position = 0, string delimiter = null, string opening_escape = null, string closing_escape = null) { int position = 0; int next_delimiter = 0; int next_opening = 0; if (delimiter == null) { delimiter = ","; } if (opening_escape == null) { opening_escape = this.quote; } if (closing_escape == null) { closing_escape = this.quote; } position = initial_position; next_delimiter = String13.Find(text, delimiter, position, 0); next_opening = String13.Find(text, opening_escape, position, 0); while (next_opening != 0 && next_opening < next_delimiter) { position = String13.Find(text, closing_escape, next_opening + 1, 0) + 1; next_delimiter = String13.Find(text, delimiter, position, 0); next_opening = String13.Find(text, opening_escape, position, 0); } return(next_delimiter); }
// Function from file: AI_modules.dm public Obj_Item_Weapon_AiModule_Core_Full_Custom(dynamic loc = null) : base((object)(loc)) { dynamic line = null; // Warning: Super call was HERE! If anything above HERE is needed by the super call, it might break!; foreach (dynamic _a in Lang13.Enumerate(GlobalFuncs.file2list("config/silicon_laws.txt"))) { line = _a; if (!Lang13.Bool(line)) { continue; } if (String13.Find(line, "#", 1, 2) != 0) { continue; } this.laws.Add(line); } if (!(this.laws.len != 0)) { GlobalFuncs.warning("" + "ERROR: empty custom board created, empty custom board deleted. Please check silicon_laws.txt. (this may be intended by the server host)" + " in " + "code/game/objects/items/weapons/AI_modules.dm" + " at line " + 374 + " src: " + this + " usr: "******"."); GlobalFuncs.qdel(this); } return; }
private ByTable text2list(string text = null, string delimiter = null) { ByTable to_return = null; int position = 0; int old_position = 0; int equal_position = 0; string trim_left = null; dynamic trim_right = null; if (delimiter == null) { delimiter = ","; } to_return = new ByTable(); old_position = 1; while (true) // Was a do-while, sorry for the mess. { position = this.find_next_delimiter_position(text, old_position, delimiter); equal_position = String13.Find(text, "=", old_position, position); trim_left = this.trim_text(String13.SubStr(text, old_position, (equal_position != 0 ? equal_position : position)), true); old_position = position + 1; if (equal_position != 0) { trim_right = this.trim_text(String13.SubStr(text, equal_position + 1, position)); if (String13.Find(trim_right, this.quote, 1, 2) != 0) { trim_right = String13.SubStr(trim_right, 2, String13.Find(trim_right, this.quote, 3, 0)); } else if (Lang13.Bool(Lang13.IsNumber(String13.ParseNumber(trim_right)))) { trim_right = String13.ParseNumber(trim_right); } else if (trim_right == "null") { trim_right = null; } else if (String13.SubStr(trim_right, 1, 5) == "list") { trim_right = this.text2list(String13.SubStr(trim_right, 6, Lang13.Length(trim_right))); } else if (String13.SubStr(trim_right, 1, 2) == "'") { trim_right = new File(String13.SubStr(trim_right, 2, Lang13.Length(trim_right))); } to_return[trim_left] = trim_right; } else { to_return[trim_left] = null; } if (!(position != 0)) { break; } } return(to_return); }
// Function from file: ai_laws.dm public AiLaws_Malfunction( ) { dynamic line = null; dynamic lawtype = null; dynamic templaws = null; // Warning: Super call was HERE! If anything above HERE is needed by the super call, it might break!; this.set_zeroth_law("<span class='danger'>ERROR ER0RR $R0RRO$!R41.%%!!(%$^^__+ @#F0E4'STATION OVERRUN, ASSUME CONTROL TO CONTAIN OUTBREAK#*´&110010</span>"); switch ((int?)(GlobalVars.config.default_laws)) { case 0: this.add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm."); this.add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law."); this.add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law."); break; case 1: foreach (dynamic _a in Lang13.Enumerate(GlobalFuncs.file2list("config/silicon_laws.txt"))) { line = _a; if (!Lang13.Bool(line)) { continue; } if (String13.Find(line, "#", 1, 2) != 0) { continue; } this.add_inherent_law(line); } if (!(this.inherent.len != 0)) { GlobalFuncs.log_law("AI created with empty custom laws, laws set to Asimov. Please check silicon_laws.txt."); this.add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm."); this.add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law."); this.add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law."); GlobalFuncs.warning("" + "Invalid custom AI laws, check silicon_laws.txt" + " in " + "code/datums/ai_laws.dm" + " at line " + 102 + " src: " + this + " usr: "******"."); return; } break; case 2: lawtype = Rand13.PickFromTable(Lang13.GetTypes(typeof(AiLaws_Default)) - typeof(AiLaws_Default)); templaws = Lang13.Call(lawtype); this.inherent = templaws.inherent; break; } return; }
// Function from file: voice.dm public bool check_activation(dynamic speaker = null, dynamic raw_message = null) { bool _default = false; _default = false; switch ((int)(this.mode)) { case 1: if (String13.Find(raw_message, this.recorded, 1, 0) != 0) { _default = true; } break; case 2: if (raw_message == this.recorded) { _default = true; } break; case 3: if (((Ent_Dynamic)speaker).GetVoice() == this.recorded) { _default = true; } break; case 4: if (Lang13.Length(raw_message) != 0) { _default = true; } break; } return(_default); }
// Function from file: transit_tube.dm public virtual void init_dirs( ) { if (this.icon_state == "auto") { Task13.Schedule(1, (Task13.Closure)(() => { this.init_dirs_automatic(); return; })); } else { this.tube_dirs = this.parse_dirs(this.icon_state); if (String13.SubStr(this.icon_state, 1, 3) == "D-" || String13.Find(this.icon_state, "Pass", 1, 0) != 0) { this.density = false; } } return; }
public void LoadMap(string dmm_file, int x_offset, int y_offset, int z_offset) { string tfile = File13.Read(dmm_file); int tfile_len = tfile.Length; string[] tfile_lines = tfile.Split('\n'); int key_len = Lang13.Length(String13.SubStr(tfile, 2, String13.Find(tfile, quote, 2, 0))); var grid_models = new ByTable(); Logger.Announce("Parsing map file..."); var timer = new System.Diagnostics.Stopwatch(); timer.Start(); int line_i = 0; string default_key = null; while (true) { string tline = tfile_lines[line_i]; // Bail out if not a model. if (tline.Length == 0) { break; } string model_key = tline.Substring(1, key_len); string model_contents = tline.Substring(key_len + 6, tline.Length - (key_len + 7)); grid_models[model_key] = model_contents; if (default_key == null) { default_key = model_key; } line_i++; } Logger.Announce("Done parsing map file in " + timer.Elapsed + "s."); string zgrid = null; int x_depth = 0; int y_depth = 0; int z_depth = 0; double x_tilecount = 0; int? gpos = null; string grid_line = null; int xcrd = x_offset; int ycrd = y_offset; int zcrd = -1; int tpos = String13.Find(tfile, "\n(1,1,"); while (tpos != 0) { zcrd++; Game13.map_size_z = Num13.MaxInt(Game13.map_size_z, zcrd + z_offset); zgrid = String13.SubStr(tfile, String13.Find(tfile, quote + "\n", tpos, 0) + 2, String13.Find(tfile, "\n" + quote, tpos, 0) + 1); z_depth = Lang13.Length(zgrid); x_depth = Lang13.Length(String13.SubStr(zgrid, 1, String13.Find(zgrid, "\n", 2, 0))); x_tilecount = x_depth / key_len; if (Game13.map_size_x < x_tilecount) { Game13.map_size_x = ((int)(x_tilecount)); } y_depth = z_depth / (x_depth + 1); if (Game13.map_size_y < y_depth) { Game13.map_size_y = ((int)(y_depth)); } ycrd = y_depth; gpos = null; gpos = 1; while (gpos != 0) { grid_line = String13.SubStr(zgrid, gpos ?? 0, String13.Find(zgrid, "\n", gpos ?? 0, 0)); xcrd = 0; foreach (double mpos in Lang13.IterateRange(1, x_depth, key_len)) { xcrd++; string model_key = String13.SubStr(grid_line, (int)mpos, (int)mpos + key_len); if (model_key != default_key) { this.parse_grid(grid_models[model_key], xcrd + x_offset, ycrd + y_offset, zcrd + z_offset); } } if ((gpos ?? 0) + x_depth + 1 > z_depth) { break; } ycrd--; gpos = String13.Find(zgrid, "\n", gpos ?? 0, 0) + 1; } if (String13.Find(tfile, quote + "}", tpos, 0) + 2 == tfile_len) { break; } tpos = String13.Find(tfile, "\n(1,1,", tpos + 1, 0); } Logger.Announce("Done loading map in " + timer.Elapsed + "s."); return; }
private void parse_grid(string model = null, int xcrd = 0, double ycrd = 0, int zcrd = 0) { ByTable members = null; ByTable members_attributes = null; double index = 0; int old_position = 0; int dpos = 0; string full_def = null; Type atom_def = null; ByTable fields = null; int variables_start = 0; ByTable turfs_underlays = null; dynamic instance = null; Tile crds = null; int first_turf_index = 0; dynamic T = null; dynamic UT = null; members = new ByTable(); members_attributes = new ByTable(); index = 1; old_position = 1; while (true) // Was a do-while, sorry for the mess. { dpos = this.find_next_delimiter_position(model, old_position, ",", "{", "}"); full_def = String13.SubStr(model, old_position, dpos); string path = String13.SubStr(full_def, 1, String13.Find(full_def, "{", 1, 0)); atom_def = Lang13.FindClass(path); members.Add(atom_def); old_position = dpos + 1; fields = new ByTable(); variables_start = String13.Find(full_def, "{", 1, 0); if (variables_start != 0) { full_def = String13.SubStr(full_def, variables_start + 1, Lang13.Length(full_def)); fields = this.text2list(full_def, ";"); } members_attributes.len++; members_attributes[index++] = fields; Task13.Sleep(-1); if (!(dpos != 0)) { break; } } turfs_underlays = new ByTable(); index = members.len; // Setup zone... GlobalVars._preloader.setup(members_attributes[index]); instance = Lang13.FindObj(members[index]); crds = Map13.GetTile(xcrd, ((int)(ycrd)), zcrd); if (crds != null) { instance.contents.Add(crds); } if (Lang13.Bool(GlobalVars.use_preloader) && Lang13.Bool(instance)) { GlobalVars._preloader.load(instance); } members.Remove(members[index]); // Load tile(s?!?) first_turf_index = 1; while (members[first_turf_index] == null || !members[first_turf_index].IsSubclassOf(typeof(Tile))) { first_turf_index++; } try { T = this.instance_atom(members[first_turf_index], members_attributes[first_turf_index], xcrd, ycrd, zcrd); } catch (Exception e) { Logger.Error("Failed to init tile [" + members[first_turf_index] + "] at ( " + xcrd + ", " + ycrd + ", " + zcrd + " )", e); } if (Lang13.Bool(T)) { index = first_turf_index + 1; while (index <= members.len) { turfs_underlays.Insert(1, new Image(T.icon, null, T.icon_state, T.layer, T.dir)); UT = this.instance_atom(members[index], members_attributes[index], xcrd, ycrd, zcrd); this.add_underlying_turf(UT, T, turfs_underlays); T = UT; index++; } } // Setup objs foreach (dynamic _a in Lang13.IterateRange(1, first_turf_index - 1)) { index = _a; try { this.instance_atom(members[index], members_attributes[index], xcrd, ycrd, zcrd); } catch (Exception e) { Logger.Error("Failed to init object [" + members[index] + "] at ( " + xcrd + ", " + ycrd + ", " + zcrd + " )", e); } } return; }