Simon

Untitled

Sep 11th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.01 KB | None | 0 0
  1. #include "simulation/Elements.h"
  2. //#TPT-Directive ElementClass Element_EMP PT_EMP 134
  3. Element_EMP::Element_EMP()
  4. {
  5.     Identifier = "DEFAULT_PT_EMP";
  6.     Name = "EMP";
  7.     Colour = PIXPACK(0x66AAFF);
  8.     MenuVisible = 1;
  9.     MenuSection = SC_ELEC;
  10.     Enabled = 1;
  11.    
  12.     Advection = 0.0f;
  13.     AirDrag = 0.00f * CFDS;
  14.     AirLoss = 0.90f;
  15.     Loss = 0.00f;
  16.     Collision = 0.0f;
  17.     Gravity = 0.0f;
  18.     Diffusion = 0.0f;
  19.     HotAir = 0.0f   * CFDS;
  20.     Falldown = 0;
  21.    
  22.     Flammable = 0;
  23.     Explosive = 0;
  24.     Meltable = 0;
  25.     Hardness = 3;
  26.    
  27.     Weight = 100;
  28.    
  29.     Temperature = R_TEMP+0.0f   +273.15f;
  30.     HeatConduct = 121;
  31.     Description = "Breaks activated electronics.";
  32.    
  33.     State = ST_SOLID;
  34.     Properties = TYPE_SOLID|PROP_LIFE_DEC;
  35.    
  36.     LowPressure = IPL;
  37.     LowPressureTransition = NT;
  38.     HighPressure = IPH;
  39.     HighPressureTransition = NT;
  40.     LowTemperature = ITL;
  41.     LowTemperatureTransition = NT;
  42.     HighTemperature = ITH;
  43.     HighTemperatureTransition = NT;
  44.    
  45.     Update = &Element_EMP::update;
  46.     Graphics = &Element_EMP::graphics;
  47. }
  48.  
  49. //#TPT-Directive ElementHeader Element_EMP static int update(UPDATE_FUNC_ARGS)
  50. int Element_EMP::update(UPDATE_FUNC_ARGS)
  51.  {
  52.     int r,rx,ry,ok=0,t,n,nx,ny;
  53.     if (parts[i].life)
  54.         return 0;
  55.     for (rx=-2; rx<3; rx++)
  56.         for (ry=-2; ry<3; ry++)
  57.             if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
  58.             {
  59.                 r = pmap[y+ry][x+rx];
  60.                 if (!r)
  61.                     continue;
  62.                 if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4)
  63.                 {
  64.                     ok=1;
  65.                     break;
  66.                 }
  67.             }
  68.     if (!ok)
  69.         return 0;
  70.     parts[i].life=220;
  71.     sim->emp_decor += 3;
  72.     if (sim->emp_decor > 40)
  73.         sim->emp_decor = 40;
  74.     for (r=0; r<=sim->parts_lastActiveIndex; r++)
  75.     {
  76.         t=parts[r].type;
  77.         rx=parts[r].x;
  78.         ry=parts[r].y;
  79.         if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0))
  80.         {
  81.             int is_elec=0;
  82.             if ((parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT ||
  83.                     parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH) || t==PT_WIRE || t==PT_SWCH)
  84.             {
  85.                 is_elec=1;
  86.                 if (sim->elements[parts[r].type].HeatConduct && rand()%100==0)
  87.                     parts[r].temp = restrict_flt(parts[r].temp+3000.0f, MIN_TEMP, MAX_TEMP);
  88.                 if (rand()%80==0)
  89.                     sim->part_change_type(r, rx, ry, PT_BREC);
  90.                 else if (rand()%120==0)
  91.                     sim->part_change_type(r, rx, ry, PT_NTCT);
  92.             }
  93.            
  94.             for (nx=-2; nx<3; nx++)
  95.                 for (ny=-2; ny<3; ny++)
  96.                     if (rx+nx>=0 && ry+ny>=0 && rx+nx<XRES && ry+ny<YRES && (rx || ry))
  97.                     {
  98.                         n = pmap[ry+ny][rx+nx];
  99.                         if (!n)
  100.                             continue;
  101.                         /*if ((n&0xFF)==PT_BTRY && rand()%60==0)
  102.                         {
  103.                             part_change_type(n>>8, rx+nx, ry+ny, PT_PLSM);
  104.                             parts[n>>8].life=rand()%100+70;
  105.                             parts[n>>8].temp+=3000;
  106.                         }*/
  107.  
  108.                         //Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor
  109.                         //So not affected by spark on metl, watr etc
  110.                         if (is_elec)
  111.                         {
  112.                             if (((n&0xFF)==PT_METL || (n&0xFF)==PT_BMTL) && rand()%280==0)
  113.                             {
  114.                                 parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP);
  115.                             }
  116.                             if ((n&0xFF)==PT_BMTL && rand()%160==0)
  117.                             {
  118.                                 sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);//TODO: Redundant, was this meant to be BRMT or something?
  119.                                 parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
  120.                             }
  121.                             if ((n&0xFF)==PT_METL && rand()%300==0)
  122.                             {
  123.                                 sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);
  124.                             }
  125.                             if ((n&0xFF)==PT_WIFI && rand()%8==0)
  126.                             {
  127.                                 //Randomise channel
  128.                                 parts[n>>8].temp = rand()%MAX_TEMP;
  129.                             }
  130.                             if ((n&0xFF)==PT_WIFI && rand()%16==0)
  131.                             {
  132.                                 sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC);
  133.                                 parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
  134.                             }
  135.                         }
  136.                         if ((n&0xFF)==PT_SWCH && rand()%100==0)
  137.                         {
  138.                             sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BREC);
  139.                         }
  140.                         if ((n&0xFF)==PT_SWCH && rand()%100==0)
  141.                         {
  142.                             parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP);
  143.                         }
  144.                         if ((n&0xFF)==PT_ARAY && rand()%60==0)
  145.                         {
  146.                             sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC);
  147.                             parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
  148.                         }
  149.                         if (t==PT_DLAY && rand()%70==0)
  150.                         {
  151.                             //Randomise delay
  152.                             parts[n>>8].temp = (rand()%256) + 273.15f;
  153.                         }
  154.                     }
  155.         }
  156.     }
  157.     return 0;
  158. }
  159.  
  160.  
  161. //#TPT-Directive ElementHeader Element_EMP static int graphics(GRAPHICS_FUNC_ARGS)
  162. int Element_EMP::graphics(GRAPHICS_FUNC_ARGS)
  163.  
  164. {
  165.     if(cpart->life)
  166.     {
  167.         *colr = cpart->life*1.5;
  168.         *colg = cpart->life*1.5;
  169.         *colb = 200-(cpart->life);
  170.         if (*colr>255)
  171.             *colr = 255;
  172.         if (*colg>255)
  173.             *colg = 255;
  174.         if (*colb>255)
  175.             *colb = 255;
  176.         if (*colb<=0)
  177.             *colb = 0;
  178.     }
  179.     return 0;
  180. }
  181.  
  182.  
  183. Element_EMP::~Element_EMP() {}
Advertisement
Add Comment
Please, Sign In to add comment