public Plant(PlantData p, World w, Point top_left_loc, int pheight, int f_num) { plant_index = (byte)p.plant_id; name = p.name; top_left = top_left_loc; is_empty = false; height = pheight; width = p.get_width(); passable = p.passable; pieces = new List <PlantUnit>(); int[] portions = new int[p.anatomy.Length]; int sum = 0; int use_id = 0; while (sum != pheight) { sum = 0; for (int x = 0; x < portions.Length; x++) { use_id = p.get_part_id_by_name(p.anatomy[x]); if (p.pieces[use_id].height_max != p.pieces[use_id].height_min) { portions[x] = Exilania.rand.Next(p.pieces[use_id].height_min, p.pieces[use_id].height_max + 1); sum += portions[x]; } else { sum += p.pieces[use_id].height_min; portions[x] = p.pieces[use_id].height_min; } } } Point pass = new Point(top_left_loc.X, top_left_loc.Y); int cur_top = 0; for (int x = 0; x < portions.Length; x++) { use_id = p.get_part_id_by_name(p.anatomy[x]); pass.X = ((width - p.pieces[use_id].width_max) / 2) + top_left_loc.X; pass.Y = cur_top + top_left_loc.Y; pieces.Add(new PlantUnit(portions[x], p, use_id, pass)); cur_top += portions[x]; pieces[x].update_plant_indeces(w, f_num); } }
public int destroy_part(int new_height, World w, int world_plant_id, PlantData p) { update_plant_indeces(w, -1); //add instead of subtract because Y increases as it moves south. e.g. 24 is further down on the screen compared to 23. Origin is top left corner of screen (world map). top_left.Y += (height - new_height); int old_height = height; height = (byte)new_height; ushort[] new_images = new ushort[height * width]; for (int x = 0; x < width * height; x++) { new_images[x] = images[((old_height - new_height) * width) + x]; } images = new ushort[new_images.Length]; for (int x = 0; x < images.Length; x++) { images[x] = new_images[x]; } for (int x = 0; x < p.pieces.Count; x++) { if (p.pieces[x].name.ToLower() == "cut" + piece_type.ToLower() || (piece_type.ToLower().Contains("cut") && p.pieces[x].name.ToLower() == piece_type.ToLower())) { if (p.pieces[x].random_images) { for (int i = 0; i < width; i++) { images[i] = (ushort)p.pieces[x].images[Exilania.rand.Next(0, p.pieces[x].images.Length)]; } } else { for (int i = 0; i < width; i++) { images[i] = (ushort)p.pieces[x].images[i]; } } piece_type = p.pieces[x].name; x = p.pieces.Count; } } update_plant_indeces(w, world_plant_id); //return the amount of blocks removed from this item. return(old_height * width - (new_height * width)); }
public PlantUnit(int pheight, PlantData p, int piece_num, Point ptop_left) { top_left = ptop_left; height = (byte)pheight; width = (byte)p.pieces[piece_num].width_min; piece_type = p.pieces[piece_num].name; images = new ushort[width * height]; for (int x = 0; x < images.Length; x++) { if (p.pieces[piece_num].random_images) { images[x] = (ushort)p.pieces[piece_num].images[Exilania.rand.Next(0, p.pieces[piece_num].images.Length)]; } else { images[x] = (ushort)p.pieces[piece_num].images[x]; } } }
public PlantManager() { plants = new List <PlantData>(); if (System.IO.File.Exists(@"plants.txt")) { System.IO.StreamReader r = new System.IO.StreamReader(@"plants.txt"); string line = ""; PlantData p = new PlantData(); bool cont = true; while (cont) { line = r.ReadLine(); if (line.Length == 0 || line[0] == '#') { //skip this line } else { string[] items = line.Split(':'); switch (items[0].ToLower()) { case "name": if (p.name == "") { p.name = items[1].Trim(); p.plant_id = 0; } else { p.plant_id = (ushort)plants.Count; p.get_height_range(); plants.Add(p); Exilania.text_stream.WriteLine("Plant Item '" + p.name + "' Loaded."); p = new PlantData(); p.name = items[1].Trim(); } break; case "drops": string[] pieces = items[1].Trim().Split(','); if (items[1].Trim() != "") { for (int x = 0; x < pieces.Length; x++) { pieces[x] = pieces[x].Trim(); string key = Acc.script_remove_content_of_outer_parenthesis(pieces[x]); byte val = byte.Parse(Acc.script_remove_outer_parentheses(pieces[x])); p.drops.Add(key, val); } } break; case "piece": p.pieces.Add(new PlantPiece(items[1])); break; case "anatomy": p.anatomy = items[1].Trim().Split(','); break; case "growson": items = items[1].Trim().Split(','); for (int x = 0; x < items.Length; x++) { if (items[x].Length > 0) { p.grows_on.Add(items[x].Trim().ToLower()); } } break; case "behavior-cut": p.behavior_cut = items[1].Trim(); break; case "min-distance": p.min_distance = Int32.Parse(items[1]); break; case "density": p.density = Int32.Parse(items[1]); break; case "break-below": p.break_below = bool.Parse(items[1]); break; case "below-block-remove": p.below_block_remove = bool.Parse(items[1]); break; case "material": p.material = items[1].Trim().ToUpper(); break; case "auto-spawn": p.auto_spawn = bool.Parse(items[1]); break; case "growth": string[] parts = items[1].Split('|'); for (int i = 0; i < parts.Length; i++) { p.growth_possibilities.Add(new Growth(parts[i])); } break; case "extreme-height": p.max_height = int.Parse(items[1]); break; default: Exilania.text_stream.WriteLine("UNHANDLED type " + items[0]); break; } } if (r.EndOfStream) { p.plant_id = (ushort)plants.Count; p.get_height_range(); plants.Add(p); Exilania.text_stream.WriteLine("Plant Item '" + p.name + "' Loaded."); cont = false; } } r.Close(); } else { Exilania.text_stream.Write("ERROR! No plants.txt file."); } }