Advertisement
Guest User

Dynamic surfaces by Emilijo "Correlli" Lovrich

a guest
Mar 14th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 17.13 KB | None | 0 0
  1. /*  surface.inc
  2.  *
  3.  *  (c) Copyright 2015, Emilijo "Correlli" Lovrich
  4.  *
  5.  *  Credits: - Incognito for streamer plugin,
  6.  *           - Y_Less for foreach/iterator.
  7. */
  8.  
  9. #define MAX_SURFACES                                                            (10)
  10. #define MAX_SURFACE_OBJECTS                                                     (3000)
  11.  
  12. #define S_X_OFFSET                                                              (0)
  13. #define S_Y_OFFSET                                                              (1)
  14. #define S_HEIGHT                                                                (2)
  15. #define S_X_START                                                               (3)
  16. #define S_Y_START                                                               (4)
  17. #define S_X_END                                                                 (5)
  18. #define S_Y_END                                                                 (6)
  19. #define S_X_ROT                                                                 (7)
  20. #define S_Y_ROT                                                                 (8)
  21. #define S_Z_ROT                                                                 (9)
  22. #define S_STREAM                                                                (10)
  23. #define S_DRAW                                                                  (11)
  24.  
  25. #define OBJ_DBG_MSG
  26.  
  27. enum DataSurface
  28. {
  29.     Model,
  30.     World,
  31.     Interior,
  32.     Player,
  33.     Float:Property_Float[12],
  34.     Object[MAX_SURFACE_OBJECTS],
  35.     ObjectCount,
  36.     HorizontalCount,
  37.     VerticalCount
  38. }
  39.  
  40. new
  41.         SurfaceData[MAX_SURFACES][DataSurface], g_Count, Iterator:Iter_Surface<MAX_SURFACES>;
  42.  
  43. stock CreateSurface(object_model, Float:x_off, Float:y_off, Float:height, Float:x_start, Float:y_start, Float:x_end = 0.0, Float:y_end = 0.0, Float:x_rot = 0.0, Float:y_rot = 0.0, Float:z_rot = 0.0, world = -1, interior = -1, player = -1, Float:d_stream = 200.0, Float:d_draw = 0.0)
  44. {
  45.     new
  46.             s_id = Iter_Free(Iter_Surface);
  47.     if(s_id == -1)
  48.         return -1;
  49.  
  50.     /*
  51.  
  52.     * Example (this covers the whole San Andreas map with breakable glass objects (model: 1649)):
  53.  
  54.     * -3000.0 -> 3000.0 (3000.0 + 3000.0 = 6000.0)
  55.  
  56.     * x_off = 4.4
  57.     * 6000.0 / 4.4 = 1363.636 ~= 1364
  58.  
  59.     * y_off = 3.31
  60.     * 6000.0 / 3.31 = 1812.6888 ~= 1813
  61.  
  62.     * 1364 x 1813 = 2472932 objects in total
  63.  
  64.     */
  65.  
  66.     Surface_FixPos(x_start, y_start, x_end, y_end);
  67.  
  68.     if(x_start == x_end || y_start == y_end)
  69.     {
  70.         printf("Error at \"CreateSurface\" function for model %i - one of the starting and ending positions (X: %0.2f, Y: %0.2f) is the same.",
  71.             object_model,
  72.             x_start,
  73.             y_start
  74.         );
  75.         return -2;
  76.     }
  77.  
  78.     Iter_Add(Iter_Surface, s_id);
  79.  
  80.     SurfaceData[s_id][Model]                        =        object_model;
  81.     SurfaceData[s_id][World]                        =               world;
  82.     SurfaceData[s_id][Interior]                     =            interior;
  83.     SurfaceData[s_id][Player]                       =              player;
  84.     SurfaceData[s_id][Property_Float][S_X_OFFSET]   =               x_off;
  85.     SurfaceData[s_id][Property_Float][S_Y_OFFSET]   =               y_off;
  86.     SurfaceData[s_id][Property_Float][S_HEIGHT]     =              height;
  87.     SurfaceData[s_id][Property_Float][S_X_START]    =             x_start;
  88.     SurfaceData[s_id][Property_Float][S_Y_START]    =             y_start;
  89.     SurfaceData[s_id][Property_Float][S_X_END]      =               x_end;
  90.     SurfaceData[s_id][Property_Float][S_Y_END]      =               y_end;
  91.     SurfaceData[s_id][Property_Float][S_X_ROT]      =               x_rot;
  92.     SurfaceData[s_id][Property_Float][S_Y_ROT]      =               y_rot;
  93.     SurfaceData[s_id][Property_Float][S_Z_ROT]      =               z_rot;
  94.     SurfaceData[s_id][Property_Float][S_STREAM]     =            d_stream;
  95.     SurfaceData[s_id][Property_Float][S_DRAW]       =              d_draw;
  96.  
  97.     for(new a = 0; a < MAX_SURFACE_OBJECTS; a++)
  98.         SurfaceData[s_id][Object][a]                =   INVALID_OBJECT_ID;
  99.  
  100.     UpdateSurface(s_id);
  101.     return s_id;
  102. }
  103.  
  104. stock DestroySurface(s_id)
  105. {
  106.     if(!Iter_Contains(Iter_Surface, s_id))
  107.         return false;
  108.  
  109.     new
  110.             a;
  111.  
  112.     Iter_Remove(Iter_Surface, s_id);
  113.  
  114.     SurfaceData[s_id][Model]                        =                   0;
  115.     SurfaceData[s_id][World]                        =                   0;
  116.     SurfaceData[s_id][Interior]                     =                   0;
  117.     SurfaceData[s_id][Player]                       =   INVALID_PLAYER_ID;
  118.     for(a = 0; a < 12; a++)
  119.         SurfaceData[s_id][Property_Float][a]        =                 0.0;
  120.     for(a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  121.     {
  122.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  123.         {
  124.             DestroyDynamicObject(SurfaceData[s_id][Object][a]);
  125.             SurfaceData[s_id][Object][a]            =   INVALID_OBJECT_ID;
  126.         }
  127.     }
  128.     SurfaceData[s_id][ObjectCount]                  =                   0;
  129.     SurfaceData[s_id][HorizontalCount]              =                   0;
  130.     SurfaceData[s_id][VerticalCount]                =                   0;
  131.     return true;
  132. }
  133.  
  134. stock SetSurfaceTexture(s_id, m_index, txd_model, txd_name[], texture_name[], m_color = 0)
  135. {
  136.     if(!Iter_Contains(Iter_Surface, s_id))
  137.         return false;
  138.  
  139.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  140.     {
  141.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  142.             SetDynamicObjectMaterial(SurfaceData[s_id][Object][a], m_index, txd_model, txd_name, texture_name, m_color);
  143.     }
  144.     return true;
  145. }
  146.  
  147. stock SetSurfaceObjectTexture(s_id, slot, m_index, txd_model, txd_name[], texture_name[], m_color = 0)
  148. {
  149.     if(!Iter_Contains(Iter_Surface, s_id))
  150.         return false;
  151.     if(slot < 0 || slot >= MAX_SURFACE_OBJECTS)
  152.         return false;
  153.     if(!IsValidDynamicObject(SurfaceData[s_id][Object][slot]))
  154.         return false;
  155.     SetDynamicObjectMaterial(SurfaceData[s_id][Object][slot], m_index, txd_model, txd_name, texture_name, m_color);
  156.     return true;
  157. }
  158.  
  159. stock SetSurfaceModel(s_id, object_model, Float:x_off, Float:y_off)
  160. {
  161.     if(!Iter_Contains(Iter_Surface, s_id))
  162.         return false;
  163.  
  164.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  165.     {
  166.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  167.             Streamer_SetIntData(STREAMER_TYPE_OBJECT, SurfaceData[s_id][Object][a], E_STREAMER_MODEL_ID, object_model);
  168.     }
  169.  
  170.     SurfaceData[s_id][Model]                        =   object_model;
  171.     SurfaceData[s_id][Property_Float][S_X_OFFSET]   =          x_off;
  172.     SurfaceData[s_id][Property_Float][S_Y_OFFSET]   =          y_off;
  173.  
  174.     UpdateSurface(s_id);
  175.     return true;
  176. }
  177.  
  178. stock GetSurfaceModel(s_id)
  179. {
  180.     if(!Iter_Contains(Iter_Surface, s_id))
  181.         return false;
  182.     return SurfaceData[s_id][Model];
  183. }
  184.  
  185. stock SetSurfacePos(s_id, Float:x_start, Float:y_start, Float:x_end = 0.0, Float:y_end = 0.0)
  186. {
  187.     if(!Iter_Contains(Iter_Surface, s_id))
  188.         return false;
  189.  
  190.     Surface_FixPos(x_start, y_start, x_end, y_end);
  191.  
  192.     if(x_start == x_end || y_start == y_end)
  193.     {
  194.         printf("Error at \"SetSurfacePos\" function for surface ID %i - one of the starting and ending positions (X: %0.2f, Y: %0.2f) is the same.",
  195.             s_id,
  196.             x_start,
  197.             y_start
  198.         );
  199.         return false;
  200.     }
  201.  
  202.     SurfaceData[s_id][Property_Float][S_X_START]    =        x_start;
  203.     SurfaceData[s_id][Property_Float][S_Y_START]    =        y_start;
  204.     SurfaceData[s_id][Property_Float][S_X_END]      =          x_end;
  205.     SurfaceData[s_id][Property_Float][S_Y_END]      =          y_end;
  206.  
  207.     UpdateSurface(s_id);
  208.     return true;
  209. }
  210.  
  211. stock GetSurfacePos(s_id, &Float:x_start, &Float:y_start, &Float:x_end, &Float:y_end)
  212. {
  213.     if(!Iter_Contains(Iter_Surface, s_id))
  214.         return false;
  215.  
  216.     x_start     =   SurfaceData[s_id][Property_Float][S_X_START];
  217.     y_start     =   SurfaceData[s_id][Property_Float][S_Y_START];
  218.     x_end       =   SurfaceData[s_id][Property_Float][S_X_END]  ;
  219.     y_end       =   SurfaceData[s_id][Property_Float][S_Y_END]  ;
  220.     return true;
  221. }
  222.  
  223. stock SetSurfaceHeight(s_id, Float:height)
  224. {
  225.     if(!Iter_Contains(Iter_Surface, s_id))
  226.         return false;
  227.  
  228.     new
  229.             Float:pos[3];
  230.  
  231.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  232.     {
  233.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  234.         {
  235.             GetDynamicObjectPos(SurfaceData[s_id][Object][a], pos[0], pos[1], pos[2]);
  236.             SetDynamicObjectPos(SurfaceData[s_id][Object][a], pos[0], pos[1], height);
  237.         }
  238.     }
  239.  
  240.     SurfaceData[s_id][Property_Float][S_HEIGHT] = height;
  241.     return true;
  242. }
  243.  
  244. stock Float:GetSurfaceHeight(s_id)
  245. {
  246.     if(!Iter_Contains(Iter_Surface, s_id))
  247.         return -100.0;
  248.     return SurfaceData[s_id][Property_Float][S_HEIGHT];
  249. }
  250.  
  251. stock SetSurfaceRot(s_id, Float:x_rot, Float:y_rot, Float:z_rot)
  252. {
  253.     if(!Iter_Contains(Iter_Surface, s_id))
  254.         return false;
  255.  
  256.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  257.     {
  258.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  259.             SetDynamicObjectRot(SurfaceData[s_id][Object][a], x_rot, y_rot, z_rot);
  260.     }
  261.  
  262.     SurfaceData[s_id][Property_Float][S_X_ROT] = x_rot;
  263.     SurfaceData[s_id][Property_Float][S_Y_ROT] = y_rot;
  264.     SurfaceData[s_id][Property_Float][S_Z_ROT] = z_rot;
  265.     return true;
  266. }
  267.  
  268. stock GetSurfaceRot(s_id, &Float:x_rot, &Float:y_rot, &Float:z_rot)
  269. {
  270.     if(!Iter_Contains(Iter_Surface, s_id))
  271.         return false;
  272.  
  273.     x_rot = SurfaceData[s_id][Property_Float][S_X_ROT];
  274.     y_rot = SurfaceData[s_id][Property_Float][S_Y_ROT];
  275.     z_rot = SurfaceData[s_id][Property_Float][S_Z_ROT];
  276.     return true;
  277. }
  278.  
  279. stock SetSurfaceStreamDistance(s_id, Float:d_stream)
  280. {
  281.     if(!Iter_Contains(Iter_Surface, s_id))
  282.         return false;
  283.  
  284.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  285.     {
  286.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  287.             Streamer_SetFloatData(STREAMER_TYPE_OBJECT, SurfaceData[s_id][Object][a], E_STREAMER_STREAM_DISTANCE, d_stream);
  288.     }
  289.  
  290.     SurfaceData[s_id][Property_Float][S_STREAM] = d_stream;
  291.     return true;
  292. }
  293.  
  294. stock Float:GetSurfaceStreamDistance(s_id)
  295. {
  296.     if(!Iter_Contains(Iter_Surface, s_id))
  297.         return 0.0;
  298.     return SurfaceData[s_id][Property_Float][S_STREAM];
  299. }
  300.  
  301. stock SetSurfaceDrawDistance(s_id, Float:d_draw)
  302. {
  303.     if(!Iter_Contains(Iter_Surface, s_id))
  304.         return false;
  305.  
  306.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  307.     {
  308.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  309.             Streamer_SetFloatData(STREAMER_TYPE_OBJECT, SurfaceData[s_id][Object][a], E_STREAMER_DRAW_DISTANCE, d_draw);
  310.     }
  311.  
  312.     SurfaceData[s_id][Property_Float][S_DRAW] = d_draw;
  313.     return true;
  314. }
  315.  
  316. stock Float:GetSurfaceDrawDistance(s_id)
  317. {
  318.     if(!Iter_Contains(Iter_Surface, s_id))
  319.         return -1.0;
  320.     return SurfaceData[s_id][Property_Float][S_DRAW];
  321. }
  322.  
  323. stock SetSurfaceWorld(s_id, world)
  324. {
  325.     if(!Iter_Contains(Iter_Surface, s_id))
  326.         return false;
  327.  
  328.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  329.     {
  330.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  331.             Streamer_SetIntData(STREAMER_TYPE_OBJECT, SurfaceData[s_id][Object][a], E_STREAMER_WORLD_ID, world);
  332.     }
  333.  
  334.     SurfaceData[s_id][World] = world;
  335.     return true;
  336. }
  337.  
  338. stock GetSurfaceWorld(s_id)
  339. {
  340.     if(!Iter_Contains(Iter_Surface, s_id))
  341.         return -2;
  342.     return SurfaceData[s_id][World];
  343. }
  344.  
  345. stock SetSurfaceInterior(s_id, interior)
  346. {
  347.     if(!Iter_Contains(Iter_Surface, s_id))
  348.         return false;
  349.  
  350.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  351.     {
  352.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  353.             Streamer_SetIntData(STREAMER_TYPE_OBJECT, SurfaceData[s_id][Object][a], E_STREAMER_INTERIOR_ID, interior);
  354.     }
  355.  
  356.     SurfaceData[s_id][Interior] = interior;
  357.     return true;
  358. }
  359.  
  360. stock GetSurfaceInterior(s_id)
  361. {
  362.     if(!Iter_Contains(Iter_Surface, s_id))
  363.         return -2;
  364.     return SurfaceData[s_id][Interior];
  365. }
  366.  
  367. stock SetSurfacePlayer(s_id, player)
  368. {
  369.     if(!Iter_Contains(Iter_Surface, s_id))
  370.         return false;
  371.     if(!IsPlayerConnected(player) && player != -1)
  372.         return false;
  373.  
  374.     for(new a = 0; a < SurfaceData[s_id][ObjectCount]; a++)
  375.     {
  376.         if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  377.             Streamer_SetIntData(STREAMER_TYPE_OBJECT, SurfaceData[s_id][Object][a], E_STREAMER_PLAYER_ID, player);
  378.     }
  379.  
  380.     SurfaceData[s_id][Player] = player;
  381.     return true;
  382. }
  383.  
  384. stock GetSurfacePlayer(s_id)
  385. {
  386.     if(!Iter_Contains(Iter_Surface, s_id))
  387.         return -2;
  388.     return SurfaceData[s_id][Player];
  389. }
  390.  
  391. stock GetSurfaceObjectCount(s_id)
  392. {
  393.     if(!Iter_Contains(Iter_Surface, s_id))
  394.         return false;
  395.     return SurfaceData[s_id][ObjectCount];
  396. }
  397.  
  398. stock GetSurfaceHorizontalObjects(s_id)
  399. {
  400.     if(!Iter_Contains(Iter_Surface, s_id))
  401.         return false;
  402.     return SurfaceData[s_id][HorizontalCount];
  403. }
  404.  
  405. stock GetSurfaceVerticalObjects(s_id)
  406. {
  407.     if(!Iter_Contains(Iter_Surface, s_id))
  408.         return false;
  409.     return SurfaceData[s_id][VerticalCount];
  410. }
  411.  
  412. stock GetSurfaceSurplusObjects(s_id)
  413. {
  414.     if(!Iter_Contains(Iter_Surface, s_id))
  415.         return -1;
  416.     return (SurfaceData[s_id][ObjectCount] - (SurfaceData[s_id][HorizontalCount] * SurfaceData[s_id][VerticalCount]));
  417. }
  418.  
  419. stock UpdateSurface(s_id)
  420. {
  421.     if(!Iter_Contains(Iter_Surface, s_id))
  422.         return false;
  423.  
  424.     new
  425.             Float:coord[2], bool:calculate[2], a, bool:loop_break = false;
  426.  
  427.     if(SurfaceData[s_id][Property_Float][S_X_START] < 0.0)
  428.     {
  429.         // -3000.0, -4000.0 -> 1000.0
  430.         // -4000.0, -3000.0 -> 1000.0
  431.         if(SurfaceData[s_id][Property_Float][S_X_END] < 0.0)
  432.         {
  433.             if(SurfaceData[s_id][Property_Float][S_X_START] > SurfaceData[s_id][Property_Float][S_X_END])
  434.                 calculate[0] = true;
  435.             coord[0] = floatabs(SurfaceData[s_id][Property_Float][S_X_START] + floatabs(SurfaceData[s_id][Property_Float][S_X_END]));
  436.         }
  437.         // -3000.0, 4000.0 -> 7000.0
  438.         else
  439.             coord[0] = floatabs(SurfaceData[s_id][Property_Float][S_X_START]) + SurfaceData[s_id][Property_Float][S_X_END];
  440.     }
  441.     else
  442.     {
  443.         // 3000.0, -4000.0 -> 7000.0
  444.         if(SurfaceData[s_id][Property_Float][S_X_END] < 0.0)
  445.         {
  446.             calculate[0] = true;
  447.             coord[0] = SurfaceData[s_id][Property_Float][S_X_START] + floatabs(SurfaceData[s_id][Property_Float][S_X_END]);
  448.         }
  449.         // 3000.0, 4000.0 -> 1000.0
  450.         // 4000.0, 3000.0 -> 1000.0
  451.         else
  452.         {
  453.             if(SurfaceData[s_id][Property_Float][S_X_START] > SurfaceData[s_id][Property_Float][S_X_END])
  454.                 calculate[0] = true;
  455.             coord[0] = floatabs(SurfaceData[s_id][Property_Float][S_X_START] - SurfaceData[s_id][Property_Float][S_X_END]);
  456.         }
  457.     }
  458.  
  459.     if(SurfaceData[s_id][Property_Float][S_Y_START] < 0.0)
  460.     {
  461.         // -3000.0, -4000.0 -> 1000.0
  462.         // -4000.0, -3000.0 -> 1000.0
  463.         if(SurfaceData[s_id][Property_Float][S_Y_END] < 0.0)
  464.         {
  465.             if(SurfaceData[s_id][Property_Float][S_Y_START] > SurfaceData[s_id][Property_Float][S_Y_END])
  466.                 calculate[1] = true;
  467.             coord[1] = floatabs(SurfaceData[s_id][Property_Float][S_Y_START] + floatabs(SurfaceData[s_id][Property_Float][S_Y_END]));
  468.         }
  469.         // -3000.0, 4000.0 -> 7000.0
  470.         else
  471.             coord[1] = floatabs(SurfaceData[s_id][Property_Float][S_Y_START]) + SurfaceData[s_id][Property_Float][S_Y_END];
  472.     }
  473.     else
  474.     {
  475.         // 3000.0, -4000.0 -> 7000.0
  476.         if(SurfaceData[s_id][Property_Float][S_Y_END] < 0.0)
  477.         {
  478.             calculate[1] = true;
  479.             coord[1] = SurfaceData[s_id][Property_Float][S_Y_START] + floatabs(SurfaceData[s_id][Property_Float][S_Y_END]);
  480.         }
  481.         // 3000.0, 4000.0 -> 1000.0
  482.         // 4000.0, 3000.0 -> 1000.0
  483.         else
  484.         {
  485.             if(SurfaceData[s_id][Property_Float][S_Y_START] > SurfaceData[s_id][Property_Float][S_Y_END])
  486.                 calculate[1] = true;
  487.             coord[1] = floatabs(SurfaceData[s_id][Property_Float][S_Y_START] - SurfaceData[s_id][Property_Float][S_Y_END]);
  488.         }
  489.     }
  490.  
  491.     SurfaceData[s_id][HorizontalCount]  =   floatround(coord[0] / SurfaceData[s_id][Property_Float][S_X_OFFSET], floatround_ceil);
  492.     SurfaceData[s_id][VerticalCount]    =   floatround(coord[1] / SurfaceData[s_id][Property_Float][S_Y_OFFSET], floatround_ceil);
  493.  
  494.     g_Count = 0;
  495.  
  496.     for(a = 0; a < SurfaceData[s_id][HorizontalCount]; a++)
  497.     {
  498.         for(new b = 0; b < SurfaceData[s_id][VerticalCount]; b++)
  499.         {
  500.             if(g_Count == MAX_SURFACE_OBJECTS)
  501.             {
  502.                 printf("Error at \"UpdateSurface\" function for model %i (surface ID: %i) - limit for objects per surface is reached (%i/%i). Change the \"MAX_SURFACE_OBJECTS\" definition in your \"surface.inc\" include file if you want to have more objects per surface.",
  503.                     SurfaceData[s_id][Model],
  504.                     s_id,
  505.                     g_Count,
  506.                     (SurfaceData[s_id][HorizontalCount] * SurfaceData[s_id][VerticalCount])
  507.                 );
  508.  
  509.                 SurfaceData[s_id][HorizontalCount]  =   (a + 1);
  510.                 SurfaceData[s_id][VerticalCount]    =   (b + 1);
  511.  
  512.                 loop_break = true;
  513.                 break;
  514.             }
  515.  
  516.             if(calculate[0])    coord[0] = SurfaceData[s_id][Property_Float][S_X_START] - (SurfaceData[s_id][Property_Float][S_X_OFFSET] * a);
  517.             else                coord[0] = SurfaceData[s_id][Property_Float][S_X_START] + (SurfaceData[s_id][Property_Float][S_X_OFFSET] * a);
  518.  
  519.             if(calculate[1])    coord[1] = SurfaceData[s_id][Property_Float][S_Y_START] - (SurfaceData[s_id][Property_Float][S_Y_OFFSET] * b);
  520.             else                coord[1] = SurfaceData[s_id][Property_Float][S_Y_START] + (SurfaceData[s_id][Property_Float][S_Y_OFFSET] * b);
  521.  
  522.             if(!IsValidDynamicObject(SurfaceData[s_id][Object][g_Count]))
  523.             {
  524.                 SurfaceData[s_id][Object][g_Count] = CreateDynamicObject(
  525.                     SurfaceData[s_id][Model],
  526.                     coord[0],
  527.                     coord[1],
  528.                     SurfaceData[s_id][Property_Float][S_HEIGHT],
  529.                     SurfaceData[s_id][Property_Float][S_X_ROT],
  530.                     SurfaceData[s_id][Property_Float][S_Y_ROT],
  531.                     SurfaceData[s_id][Property_Float][S_Z_ROT],
  532.                     SurfaceData[s_id][World],
  533.                     SurfaceData[s_id][Interior],
  534.                     SurfaceData[s_id][Player],
  535.                     SurfaceData[s_id][Property_Float][S_STREAM],
  536.                     SurfaceData[s_id][Property_Float][S_DRAW]
  537.                 );
  538.             }
  539.             else
  540.             {
  541.                 SetDynamicObjectPos(
  542.                     SurfaceData[s_id][Object][g_Count],
  543.                     coord[0],
  544.                     coord[1],
  545.                     SurfaceData[s_id][Property_Float][S_HEIGHT]
  546.                 );
  547.  
  548.                 SetDynamicObjectRot(
  549.                     SurfaceData[s_id][Object][g_Count],
  550.                     SurfaceData[s_id][Property_Float][S_X_ROT],
  551.                     SurfaceData[s_id][Property_Float][S_Y_ROT],
  552.                     SurfaceData[s_id][Property_Float][S_Z_ROT]
  553.                 );
  554.             }
  555.  
  556.             g_Count++;
  557.         }
  558.  
  559.         if(loop_break)
  560.             break;
  561.     }
  562.  
  563.     if(g_Count < SurfaceData[s_id][ObjectCount])
  564.     {
  565.         for(a = g_Count; a < MAX_SURFACE_OBJECTS; a++)
  566.         {
  567.             if(IsValidDynamicObject(SurfaceData[s_id][Object][a]))
  568.             {
  569.                 DestroyDynamicObject(SurfaceData[s_id][Object][a]);
  570.                 SurfaceData[s_id][Object][a] = INVALID_OBJECT_ID;
  571.             }
  572.         }
  573.     }
  574.  
  575.     SurfaceData[s_id][ObjectCount] = g_Count;
  576.  
  577.     #if defined OBJ_DBG_MSG
  578.         printf("Created/updated %i objects at \"UpdateSurface\" function for model %i (surface ID: %i).",
  579.             g_Count,
  580.             SurfaceData[s_id][Model],
  581.             s_id
  582.         );
  583.     #endif
  584.     return g_Count;
  585. }
  586.  
  587. stock Surface_FixPos(&Float:x_start, &Float:y_start, &Float:x_end, &Float:y_end)
  588. {
  589.     if(!x_end)
  590.     {
  591.         if(x_start < 0.0)   x_end = floatabs(x_start);
  592.         else                x_end = -x_start;
  593.     }
  594.  
  595.     if(!y_end)
  596.     {
  597.         if(y_start < 0.0)   y_end = floatabs(y_start);
  598.         else                y_end = -y_start;
  599.     }
  600. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement