Advertisement
ZoriaRPG

Mapdata Getter Macros (sanity checks)

Oct 23rd, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.27 KB | None | 0 0
  1. ///----------------------------------------------------------------------------------------------------//
  2. //mapdata m-> variables
  3.     #define GET_MAPDATA_VAR_INT32(member, str) \
  4.     { \
  5.         if ( ri->mapsref == 0 ) \
  6.         { \
  7.             Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  8.             ret = -10000; \
  9.         } \
  10.         else if ( ri->mapsref == LONG_MAX ) \
  11.         { \
  12.             Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  13.             ret = -10000; \
  14.         } \
  15.         else \
  16.         { \
  17.             mapscr *m = &TheMaps[ri->mapsref]; \
  18.             ret = (m->member *10000); \
  19.         } \
  20.     } \
  21.  
  22.     #define GET_MAPDATA_VAR_INT16(member, str) \
  23.     { \
  24.         if ( ri->mapsref == 0 ) \
  25.         { \
  26.             Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  27.             ret = -10000; \
  28.         } \
  29.         else if ( ri->mapsref == LONG_MAX ) \
  30.         { \
  31.             Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  32.             ret = -10000; \
  33.         } \
  34.         else \
  35.         { \
  36.             mapscr *m = &TheMaps[ri->mapsref]; \
  37.             ret = (m->member *10000); \
  38.         } \
  39.     } \
  40.  
  41.     #define GET_MAPDATA_VAR_BYTE(member, str) \
  42.     { \
  43.         if ( ri->mapsref == 0 ) \
  44.         { \
  45.             Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  46.             ret = -10000; \
  47.         } \
  48.         else if ( ri->mapsref == LONG_MAX ) \
  49.         { \
  50.             Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  51.             ret = -10000; \
  52.         } \
  53.         else \
  54.         { \
  55.             mapscr *m = &TheMaps[ri->mapsref]; \
  56.             ret = (m->member *10000); \
  57.         } \
  58.     } \
  59.    
  60.     #define GET_MAPDATA_VAR_INDEX32(member, str, indexbound) \
  61.     { \
  62.         int indx = ri->d[0] / 10000; \
  63.         if(indx < 0 || indx > indexbound ) \
  64.         { \
  65.             Z_scripterrlog("Invalid Index passed to mapdata->%s[]: %d\n", (indx), str); \
  66.             ret = -10000; \
  67.         } \
  68.         else \
  69.         { \
  70.             if ( ri->mapsref == 0 ) \
  71.             { \
  72.                 Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  73.                 ret = -10000; \
  74.             } \
  75.             else if ( ri->mapsref == LONG_MAX ) \
  76.             { \
  77.                 Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  78.                 ret = -10000; \
  79.             } \
  80.             else \
  81.             { \
  82.                 mapscr *m = &TheMaps[ri->mapsref]; \
  83.                 ret = (m->member[indx] *10000); \
  84.             } \
  85.         } \
  86.     } \
  87.    
  88.     #define GET_MAPDATA_VAR_INDEX16(member, str, indexbound) \
  89.     { \
  90.         int indx = ri->d[0] / 10000; \
  91.         if(indx < 0 || indx > indexbound ) \
  92.         { \
  93.             Z_scripterrlog("Invalid Index passed to mapdata->%s[]: %d\n", (indx), str); \
  94.             ret = -10000; \
  95.         } \
  96.         else \
  97.         { \
  98.             if ( ri->mapsref == 0 ) \
  99.             { \
  100.                 Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  101.                 ret = -10000; \
  102.             } \
  103.             else if ( ri->mapsref == LONG_MAX ) \
  104.             { \
  105.                 Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  106.                 ret = -10000; \
  107.             } \
  108.             else \
  109.             { \
  110.                 mapscr *m = &TheMaps[ri->mapsref]; \
  111.                 ret = (m->member[indx] *10000); \
  112.             } \
  113.         } \
  114.     } \
  115.    
  116.     #define GET_MAPDATA_BYTE_INDEX(member, str, indexbound) \
  117.     { \
  118.         int indx = ri->d[0] / 10000; \
  119.         if(indx < 0 || indx > indexbound ) \
  120.         { \
  121.             Z_scripterrlog("Invalid Index passed to mapdata->%s[]: %d\n", (indx), str); \
  122.             ret = -10000; \
  123.         } \
  124.         else \
  125.         { \
  126.             if ( ri->mapsref == 0 ) \
  127.             { \
  128.                 Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  129.                 ret = -10000; \
  130.             } \
  131.             else if ( ri->mapsref == LONG_MAX ) \
  132.             { \
  133.                 Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  134.                 ret = -10000; \
  135.             } \
  136.             else \
  137.             { \
  138.                 mapscr *m = &TheMaps[ri->mapsref]; \
  139.                 ret = (m->member[indx] *10000); \
  140.             } \
  141.         } \
  142.     } \
  143.    
  144.     /*
  145.     #define GET_MAPDATA_LAYER_INDEX(member, str, indexbound) \
  146.     { \
  147.         int indx = ri->d[0] / 10000; \
  148.         mapscr *m = &TheMaps[ri->mapsref]; \
  149.         if ( indx == 0 ) \
  150.         { \
  151.             \
  152.         } \
  153.         else \
  154.         { \
  155.             ret = (m->member[indx-1] *10000); \
  156.         } \
  157.     } \
  158.     */
  159.    
  160.     #define GET_MAPDATA_LAYER_INDEX(member, str, indexbound) \
  161.     { \
  162.         int indx = ri->d[0] / 10000; \
  163.         if(indx < 0 || indx > indexbound ) \
  164.         { \
  165.             Z_scripterrlog("Invalid Index passed to mapdata->%s[]: %d\n", (indx), str); \
  166.             ret = -10000; \
  167.         } \
  168.         else \
  169.         { \
  170.             if ( ri->mapsref == 0 ) \
  171.             { \
  172.                 Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  173.                 ret = -10000; \
  174.             } \
  175.             else if ( ri->mapsref == LONG_MAX ) \
  176.             { \
  177.                 Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  178.                 ret = -10000; \
  179.             } \
  180.             else \
  181.             { \
  182.                 mapscr *m = &TheMaps[ri->mapsref]; \
  183.                 ret = (m->member[indx] *10000); \
  184.             } \
  185.         } \
  186.     } \
  187.    
  188.     #define GET_MAPDATA_BOOL_INDEX(member, str, indexbound) \
  189.     { \
  190.         int indx = ri->d[0] / 10000; \
  191.         if(indx < 0 || indx > indexbound ) \
  192.         { \
  193.             Z_scripterrlog("Invalid Index passed to mapdata->%s[]: %d\n", (indx), str); \
  194.             ret = -10000; \
  195.         } \
  196.         else \
  197.         { \
  198.             if ( ri->mapsref == 0 ) \
  199.             { \
  200.                 Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  201.                 ret = -10000; \
  202.             } \
  203.             else if ( ri->mapsref == LONG_MAX ) \
  204.             { \
  205.                 Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  206.                 ret = -10000; \
  207.             } \
  208.             else \
  209.             { \
  210.                 mapscr *m = &TheMaps[ri->mapsref]; \
  211.                 ret = (m->member[indx]?10000:0); \
  212.             } \
  213.         } \
  214.     } \
  215.    
  216.     #define GET_MAPDATA_FLAG(member, str) \
  217.     { \
  218.         long flag =  (value/10000);  \
  219.         if ( ri->mapsref == 0 ) \
  220.         { \
  221.             Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  222.             ret = -10000; \
  223.         } \
  224.         else if ( ri->mapsref == LONG_MAX ) \
  225.         { \
  226.             Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  227.             ret = -10000; \
  228.         } \
  229.         else \
  230.         { \
  231.             mapscr *m = &TheMaps[ri->mapsref]; \
  232.             ret = (m->member&flag) ? 10000 : 0); \
  233.         } \
  234.     } \
  235.    
  236.     #define GET_SCREENDATA_COMBO_VAR(member, str) \
  237.     { \
  238.         if ( ri->mapsref == 0 ) \
  239.         { \
  240.             Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  241.             ret = -10000; \
  242.         } \
  243.         else if ( ri->mapsref == LONG_MAX ) \
  244.         { \
  245.             Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  246.             ret = -10000; \
  247.         } \
  248.         else \
  249.         { \
  250.             mapscr *m = &TheMaps[ri->mapsref]; \
  251.             int pos = ri->d[0] / 10000; \
  252.             if(BC::checkComboPos(pos, str) != SH::_NoError) \
  253.             ret = -10000; \
  254.             else \
  255.                 ret = m->member[pos]*10000; \
  256.         } \
  257.     } \
  258.  
  259.     #define GET_MAPDATA_COMBO_VAR_BUF(member, str) \
  260.     { \
  261.         if ( ri->mapsref == 0 ) \
  262.         { \
  263.             Z_scripterrlog("Script attempted to use a mapdata->%s pointer that is uninitialised\n",str); \
  264.             ret = -10000; \
  265.         } \
  266.         else if ( ri->mapsref == LONG_MAX ) \
  267.         { \
  268.             Z_scripterrlog("Script attempted to use a mapdata->%s on a pointer that is uninitialised\n",str); \
  269.             ret = -10000; \
  270.         } \
  271.         else \
  272.         { \
  273.             mapscr *m = &TheMaps[ri->mapsref]; \
  274.             int pos = ri->d[0] / 10000; \
  275.             if(BC::checkComboPos(pos, str) != SH::_NoError) \
  276.                 ret = -10000; \
  277.             else \
  278.                 ret = combobuf[m->data[pos]].member * 10000; \
  279.         } \
  280.     } \
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement