home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 November / Chip_2002-11_cd1.bin / oddech / orbital / orbital.exe / src / target.cpp < prev    next >
C/C++ Source or Header  |  2002-07-14  |  9KB  |  238 lines

  1. ///////////////////////////////////////////////
  2. // 
  3. //  Snipe2d ludum dare 48h compo entry
  4. //
  5. //  Jari Komppa aka Sol 
  6. //  http://iki.fi/sol
  7. // 
  8. ///////////////////////////////////////////////
  9. // License
  10. ///////////////////////////////////////////////
  11. // 
  12. //     This software is provided 'as-is', without any express or implied
  13. //     warranty.    In no event will the authors be held liable for any damages
  14. //     arising from the use of this software.
  15. // 
  16. //     Permission is granted to anyone to use this software for any purpose,
  17. //     including commercial applications, and to alter it and redistribute it
  18. //     freely, subject to the following restrictions:
  19. // 
  20. //     1. The origin of this software must not be misrepresented; you must not
  21. //        claim that you wrote the original software. If you use this software
  22. //        in a product, an acknowledgment in the product documentation would be
  23. //        appreciated but is not required.
  24. //     2. Altered source versions must be plainly marked as such, and must not be
  25. //        misrepresented as being the original software.
  26. //     3. This notice may not be removed or altered from any source distribution.
  27. // 
  28. // (eg. same as ZLIB license)
  29. //
  30. ///////////////////////////////////////////////
  31. //
  32. // Houses are taken from a satellite picture of glasgow.
  33. //
  34. // The sources are a mess, as I didn't even try to do anything
  35. // really organized here.. and hey, it's a 48h compo =)
  36. //
  37. #include "snipe2d.h"
  38.  
  39. void target()
  40. {
  41.     static int lastBadGuys = -1;
  42.     static int lastVIPs = -1;
  43.     static int badGuysChangeTick = 0;
  44.     static int VIPsChangeTick = 0;
  45.  
  46.     int tick = GetTickCount();
  47.  
  48.     if (lastBadGuys != gBadGuyCount)
  49.     {
  50.         lastBadGuys = gBadGuyCount;
  51.         badGuysChangeTick = tick;
  52.     }
  53.     if (lastVIPs != gVIPCount)
  54.     {
  55.         lastVIPs = gVIPCount;
  56.         VIPsChangeTick = tick;
  57.     }
  58.     
  59.     if ( SDL_LockSurface(gScreen) < 0 ) 
  60.         return;
  61.  
  62.     int i;
  63.     short *tgt = (short*)gScreen->pixels;
  64.  
  65.     if (gReloading)    
  66.     {
  67.         float distance = gReloading / (float)RELOAD_TIME;
  68.         distance = distance * distance * distance;
  69.  
  70.         int ofs = (gScreen->pitch / 2) * 240;
  71.         for (i = 0; i < 640; i++, ofs++)
  72.             tgt[ofs] = (short)0;
  73.  
  74.         ofs = 320;
  75.         for (i = 0; i < 480; i++, ofs += gScreen->pitch / 2)
  76.             tgt[ofs] = (short)0;
  77.  
  78.         ofs = (gScreen->pitch / 2) * (int)(240 + distance * 200);
  79.         for (i = 0; i < 640; i++, ofs++)
  80.             tgt[ofs] = (short)0xC000;
  81.         
  82.         ofs = (gScreen->pitch / 2) * (int)(240 - distance * 200);
  83.         for (i = 0; i < 640; i++, ofs++)
  84.             tgt[ofs] = (short)0xC000;
  85.  
  86.         ofs = (int)(320 + distance * 300);
  87.         for (i = 0; i < 480; i++, ofs += gScreen->pitch / 2)
  88.             tgt[ofs] = (short)0xC000;
  89.  
  90.         ofs = (int)(320 - distance * 300);
  91.         for (i = 0; i < 480; i++, ofs += gScreen->pitch / 2)
  92.             tgt[ofs] = (short)0xC000;
  93.  
  94.         SDL_UnlockSurface(gScreen);
  95.  
  96.     }
  97.     else // not reloading
  98.     {
  99.         int ofs = (gScreen->pitch / 2) * 240;
  100.         for (i = 0; i < 640; i++, ofs++)
  101.             tgt[ofs] = (short)0xff00;
  102.  
  103.         ofs = 320;
  104.         for (i = 0; i < 480; i++, ofs += gScreen->pitch / 2)
  105.             tgt[ofs] = (short)0xff00;
  106.  
  107.         SDL_UnlockSurface(gScreen);
  108.     }
  109.     
  110.     int row;
  111.     row = 196;
  112.     print(324, row, COLOR_YELLOW, "time:    %02d:%02d", ((GetTickCount() - gGameStartTick) / 60000), ((GetTickCount() - gGameStartTick) / 1000)%60);
  113.     row += 7;
  114.     if ((tick - VIPsChangeTick) < 500)
  115.         print(324, row, COLOR_GREEN, "VIPs    %6d", gVIPCount);
  116.     else
  117.         print(324, row, COLOR_YELLOW, "VIPs    %6d", gVIPCount);
  118.     row += 7;
  119.     if ((tick - badGuysChangeTick) < 500)
  120.         print(324, row, COLOR_RED, "Threat  %6d", gBadGuyCount);
  121.     else
  122.         print(324, row, COLOR_YELLOW, "Threat  %6d", gBadGuyCount);
  123.     row += 7;
  124.     print(324, row, COLOR_YELLOW, "Score%09.8d", gScore);
  125.     row += 7;
  126.     print(324, row, COLOR_YELLOW, "FPS     %3.3f", (gFrameCount * 1000.0f) / (tick - gStartTick));
  127.     row += 7;
  128.     print(324, row, COLOR_YELLOW, "Zoom  %7.0fx", (1.0f / gCoordScale) * 100);
  129.     row = 244;
  130.     if (gSightedCharacter == NULL)
  131.     {
  132.         print(278, row, COLOR_YELLOW, "%10x", (tick >> 4) *  700);
  133.         row += 7;
  134.         print(278, row, COLOR_YELLOW, "%10x", (tick >> 3) *  1337);
  135.         row += 7;
  136.         print(278, row, COLOR_YELLOW, "%10x", (tick >> 2) *  4);
  137.         row += 7;
  138.         print(278, row, COLOR_YELLOW, "%10x", (tick >> 1) *  4935);
  139.         row += 7;
  140.         print(278, row, COLOR_YELLOW, "%10x", (int)(gMouseX * 0xc0c4c01a) - (tick >> 3));
  141.         row += 7;
  142.         print(278, row, COLOR_YELLOW, "%10x", (int)(gMouseY * 0xb4be2b3d) - (tick >> 4));
  143.         row += 7;
  144.         print(278, row, COLOR_YELLOW, "%10x", (tick << 4) *  4095);
  145.         row += 7;
  146.         print(278, row, COLOR_YELLOW, "%10x", (int)(gMouseZ * 0xf00ba573) - (tick >> 5));
  147.     }
  148.     else
  149.     {
  150.         print(238, row, COLOR_YELLOW, "%20s", "Citizen profile");
  151.         row += 7;
  152.         row += 7;
  153.         print(238, row, COLOR_YELLOW, "%20s", "Coordinates");
  154.         row += 7;
  155.         print(238, row, COLOR_YELLOW, "     %6.2f - %6.2f", gSightedCharacter->mX, gSightedCharacter->mY);
  156.         row += 7;
  157.         row += 7;
  158.         print(238, row, COLOR_YELLOW, "%20s", "Classification");
  159.         row += 7;
  160.         switch (gSightedCharacter->mType)
  161.         {
  162.         case 0:
  163.             print(239, row + 1, COLOR_BLACK, "%20s", "** THREAT **");
  164.             print(238, row, COLOR_RED, "%20s", "** THREAT **");
  165.             row += 7;
  166.             row += 7;
  167.             print(238, row, COLOR_YELLOW, "%20s", "Destination");
  168.             row += 7;
  169.             if (gSightedCharacter->mTarget != -1)
  170.             {
  171.                 print(238, row, COLOR_YELLOW, "     %6.2f - %6.2f", gCharacter[gSightedCharacter->mTarget].mX, gCharacter[gSightedCharacter->mTarget].mY);
  172.                 row += 7;
  173.                 row += 7;
  174.                 print(238, row, COLOR_YELLOW, "%20s", "Distance");
  175.                 row += 7;
  176.                 print(238, row, COLOR_YELLOW, "     %15.2f", distance(gCharacter[gSightedCharacter->mTarget].mX, gCharacter[gSightedCharacter->mTarget].mY, gSightedCharacter->mX, gSightedCharacter->mY));
  177.             }
  178.             else
  179.             print(238, row, COLOR_YELLOW, "%20s", "Unknown");
  180.             row += 7;
  181.             row += 7;
  182.             print(238, row, COLOR_YELLOW, "%20s", "VPB file ID");
  183.             row += 7;
  184.             print(238, row, COLOR_YELLOW, "      %03X-%07X/%02X", 
  185.                         ((((unsigned int)gSightedCharacter) * 7001337) & 0xfff),
  186.                         (((unsigned int)gSightedCharacter) * 1337357) & 0xfffffff,
  187.                         (((unsigned int)gSightedCharacter) * 70741)  & 0xff);
  188.  
  189.  
  190.             break;
  191.         case 1:
  192.             print(239, row + 1, COLOR_BLACK, "%20s", "- VIP -");
  193.             print(238, row, COLOR_GREEN, "%20s", "- VIP -");
  194.             row += 7;
  195.             row += 7;
  196.             print(238, row, COLOR_YELLOW, "%20s", "Destination");
  197.             row += 7;
  198.             print(238, row, COLOR_YELLOW, "     %6.2f - %6.2f", (float)gSpawnpoint[gSightedCharacter->mTarget].mX, (float)gSpawnpoint[gSightedCharacter->mTarget].mY);
  199.             row += 7;
  200.             row += 7;
  201.             print(238, row, COLOR_YELLOW, "%20s", "Distance");
  202.             row += 7;
  203.             print(238, row, COLOR_YELLOW, "     %15.2f", distance((float)gSpawnpoint[gSightedCharacter->mTarget].mX, (float)gSpawnpoint[gSightedCharacter->mTarget].mY, gSightedCharacter->mX, gSightedCharacter->mY));
  204.             row += 7;
  205.             row += 7;
  206.             print(238, row, COLOR_YELLOW, "%20s", "Net worth");
  207.             row += 7;
  208.             print(238, row, COLOR_YELLOW, "%20s", "Classified");
  209.             break;
  210.         case 2:
  211.             print(238, row, COLOR_YELLOW, "%20s", "Citizen");
  212.             row += 7;
  213.             row += 7;
  214.             print(238, row, COLOR_YELLOW, "%20s", "Net worth");
  215.             row += 7;
  216.             print(238, row, COLOR_YELLOW, "%17u KC", (((unsigned int)gSightedCharacter) * 1337357) % 71937);
  217.             break;
  218.         case 3:
  219.             print(238, row, COLOR_YELLOW, "%20s", "Splat.");
  220.             break;
  221.         case 4:
  222.             print(238, row, COLOR_BLACK, "%20s", "Missed shot");
  223.             break;
  224.         }
  225.         row += 7;
  226.  
  227.                                             
  228.     }
  229.  
  230.     if (gFrameCount > 100)
  231.     {
  232.         gFrameCount = 0;
  233.         gStartTick = tick;
  234.     }
  235.     
  236. }
  237.  
  238.