Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1. class GrassSeeder : EventHandler {
  2.  
  3.     Array<String> flats;
  4.    
  5.     const actorClass = "GrassPatch2";
  6.    
  7.     override void OnRegister() {
  8.    
  9.         flats.push("G000M800");
  10.    
  11.     }
  12.    
  13.     override void WorldLoaded(WorldEvent e) {
  14.    
  15.         for (int i = 0; i < level.sectors.size(); i++){
  16.        
  17.             Sector sec = level.sectors[i];
  18.        
  19.             TextureID tex = sec.GetTexture(0);
  20.            
  21.             String name = TexMan.GetName(tex);            
  22.            
  23.             if (flats.find(name) != flats.size()) {
  24.                        
  25.                 // boundary box of sector
  26.                 double left = sec.lines[0].v1.p.x;
  27.                 double right = sec.lines[0].v1.p.x;                
  28.                 double top = sec.lines[0].v1.p.y;
  29.                 double bottom = sec.lines[0].v1.p.y;            
  30.                
  31.                 // size box to sector boundary
  32.                 for (int j = 0; j < sec.lines.size(); j++) {
  33.                
  34.                     double x = sec.lines[j].v1.p.x;
  35.                     double y = sec.lines[j].v1.p.y;
  36.                    
  37.                     // expand box to fit if vertex lies outside
  38.                     if (x < left)   { left = x;   }                    
  39.                     if (x > right)  { right = x;  }                  
  40.                     if (y > top)    { top = y;    }                    
  41.                     if (y < bottom) { bottom = y; }
  42.                    
  43.                 }                
  44.                
  45.                 Util.Log("Left: "..left);
  46.                 Util.Log("Right: "..right);
  47.                 Util.Log("Top: "..top);
  48.                 Util.Log("Bottom: "..bottom);
  49.  
  50.                 double area = abs(right - left) * abs(top - bottom);
  51.                 int pop =  area / 1000;
  52.                
  53.                 Util.Log("Area: "..area);
  54.                 Util.Log("Pop: "..pop);
  55.                                
  56.                 for (int k = 0; k < pop; k++) {                    
  57.                    
  58.                     Vector2 candidate = (frandom(left, right), frandom(top, bottom));
  59.                    
  60.                     // native static Sector PointInSector(Vector2 pt);
  61.                    
  62.                     if (Sector.PointInSector(candidate).Index() == sec.Index()) {
  63.                    
  64.                         // Util.Log("DING  "..candidate);
  65.                        
  66.                         Actor.Spawn("HealthBonus", (candidate.x, candidate.y, -999999999));
  67.                    
  68.                     }                    
  69.                 }            
  70.             }        
  71.         }    
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement