Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GrassSeeder : EventHandler {
- Array<String> flats;
- const actorClass = "GrassPatch2";
- override void OnRegister() {
- flats.push("G000M800");
- }
- override void WorldLoaded(WorldEvent e) {
- for (int i = 0; i < level.sectors.size(); i++){
- Sector sec = level.sectors[i];
- TextureID tex = sec.GetTexture(0);
- String name = TexMan.GetName(tex);
- if (flats.find(name) != flats.size()) {
- // boundary box of sector
- double left = sec.lines[0].v1.p.x;
- double right = sec.lines[0].v1.p.x;
- double top = sec.lines[0].v1.p.y;
- double bottom = sec.lines[0].v1.p.y;
- // size box to sector boundary
- for (int j = 0; j < sec.lines.size(); j++) {
- double x = sec.lines[j].v1.p.x;
- double y = sec.lines[j].v1.p.y;
- // expand box to fit if vertex lies outside
- if (x < left) { left = x; }
- if (x > right) { right = x; }
- if (y > top) { top = y; }
- if (y < bottom) { bottom = y; }
- }
- Util.Log("Left: "..left);
- Util.Log("Right: "..right);
- Util.Log("Top: "..top);
- Util.Log("Bottom: "..bottom);
- double area = abs(right - left) * abs(top - bottom);
- int pop = area / 1000;
- Util.Log("Area: "..area);
- Util.Log("Pop: "..pop);
- for (int k = 0; k < pop; k++) {
- Vector2 candidate = (frandom(left, right), frandom(top, bottom));
- // native static Sector PointInSector(Vector2 pt);
- if (Sector.PointInSector(candidate).Index() == sec.Index()) {
- // Util.Log("DING "..candidate);
- Actor.Spawn("HealthBonus", (candidate.x, candidate.y, -999999999));
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement