PsyOps

Tracker

Nov 23rd, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 32.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using AlphaCore;
  6. using AlphaCore.Events;
  7.  
  8. namespace MarioKart
  9. {
  10.     [Behavior("Tracker", "true", "1.1", "PsyOps", "Tracks players in the race.")]
  11.     [CommandHelp("!load 1", "Loads default map.", ModLevels.Sysop)]
  12.     [CommandHelp("!add", "Includes you in the player list.", ModLevels.Sysop)]
  13.     [CommandHelp("!add <name>", "Includes <name> in the player list.", ModLevels.Sysop)]
  14.     public class Tracker : BotEventListener
  15.     {
  16.  
  17.         //           +----------+
  18.         //           | Commands |
  19.         //           +----------+
  20.         public Tracker()
  21.         {
  22.             RegisterCommand("!debug", toggle_debug); // Toggles debug o_0
  23.             RegisterCommand("!load", load_map2);
  24.             RegisterCommand("!prog", show_prog);
  25.             RegisterTimedEvent("MK_Init",5000,intitialize);
  26.             RegisterTimedEvent("Downgrade",250,p_downgrade);
  27.             RegisterTimedEvent("UpgradeL", 250, l_upgrade);
  28.             RegisterTimedEvent("UpgradeM", 500, m_upgrade);
  29.             RegisterTimedEvent("UpgradeH", 750, h_upgrade);
  30.         }
  31.         //-------------------------------------\\
  32.  
  33.         //           +-----------+
  34.         //           | Variables |
  35.         //           +-----------+
  36.         bool GameOn = false;                      // Is game in progress?
  37.         List<Player> p_list = new List<Player>(); // Main player list
  38.         bool debug = false;                       // Debug mode on or off
  39.         Map loaded_map;                           // This is where the current map will be loaded
  40.         int rankLvz_prefix = 600;                 // the lvz prefix for ranks, 1st,2nd,3rd *objon rankLvz_prefix+rank
  41.         byte max_penalties = 5;                   // max amount of speed penalties for offtrack
  42.         //-------------------------------------\\
  43.  
  44.  
  45.         //          +-------------+
  46.         //          | Containers  |
  47.         //          +-------------+
  48.         // -------- Player Container -----------
  49.         public class Player
  50.         {
  51.             public string name;      // Player name
  52.             public ShipTypes ship;   // What ship player is in. Determines kart weight and helps with acceleration.
  53.             public int[] progress;   // Player progress depending on direction.  (index# 2)
  54.             public int[] pos;        // Player position recorded in case we need to warp them back
  55.             public int laps;         // Each track piece will be a checkpoint for now (index #4)
  56.             public bool on_track;    // on_track = is player on the track or off?
  57.             public bool[] direction; // This will be an updated bool array to tell us if player has been going forward (index# 1)
  58.             public byte[] penalty;   // Keeps track of how many penalties have been given
  59.             public byte place;       // What place player is in.
  60.  
  61.            
  62.             public Player(string name)
  63.             {
  64.                 this.name = name;
  65.             }
  66.             public Player(int[] progress )
  67.             {
  68.                 this.progress = progress;
  69.             }
  70.             public Player(ushort laps, bool on_track, int[] pos, byte[] penalty, ShipTypes ship, byte place)
  71.             {
  72.                 this.laps = laps;
  73.                 this.on_track = on_track;
  74.                 this.pos = pos;
  75.                 this.penalty = penalty;
  76.                 this.ship = ship;
  77.                 this.place = place;
  78.             }
  79.         }
  80.         // --------  Main map container  ----------
  81.         public class Map
  82.         {
  83.             public string name;                // Name of the track
  84.             public int[] ref_point;            // All regions will be based off of this point (x,y)
  85.             public List<track_region> regions; // All regions that make up the map
  86.             public byte laps;                  // how many laps
  87.             public int total_prog;             // total progress to include all regions for 1 lap
  88.            
  89.             public Map(string name)
  90.             {
  91.                 this.name = name;
  92.             }
  93.             public Map(int[] ref_point, List<track_region> regions, byte laps)
  94.             {
  95.                 this.ref_point = ref_point;
  96.                 this.regions = regions;
  97.                 this.laps = laps;
  98.             }
  99.         }
  100.         // -------  Individual region container ------
  101.         public class track_region
  102.         {
  103.             public byte type;          // is it linear or radial tracking
  104.             public int[] region_pos;   // position = x1,y1,x2,y2 (in tiles!!!! not pixels)
  105.             public int[] in_track;     // these will be points to calculate if player is inside of track
  106.             public int[] radial_point; // Point used to compare player position to
  107.             public int[] c_points;     // {lap number, total progress points to that point} (index #3)
  108.             public int[] s_point;      // Warpto point for that region, must be in the beginning
  109.  
  110.             public track_region(byte type)
  111.             {
  112.                 this.type = type;
  113.             }
  114.             public track_region(int[] region_pos, int[] radial_point, int[] c_points, int[] s_point)
  115.             {
  116.                 this.region_pos = region_pos;
  117.                 this.radial_point = radial_point;
  118.                 this.c_points = c_points;
  119.                 this.s_point = s_point;
  120.             }
  121.         }
  122.         //----------------------------------------------------------------\\
  123.  
  124.  
  125.         //          +-----------------+
  126.         //          | Player Tracking |
  127.         //          +-----------------+
  128.         // -----------  track_player  ----------------
  129.         // I will track player movement here by monitoring PlayerPosition packets
  130.         public void track_player(object sender, PlayerPositionEvent p)
  131.         {
  132.             // Make sure game is active before we track players
  133.             if (GameOn)
  134.             {
  135.                 p_list.ForEach(delegate(Player p2)
  136.                 {
  137.                     bool OnMap = false; // Is player even on the map?
  138.                     if (p2.name == p.PlayerName)
  139.                     {
  140.                         // Checking regions inside of the loaded map
  141.                         loaded_map.regions.ForEach(delegate(track_region t)
  142.                         {
  143.                             if (collision_detect(new int[] { p.MapPositionX, p.MapPositionY }, t.region_pos))
  144.                             {
  145.                                 update_progress(p,t);
  146.                                 p2.pos = new int[] {p.MapPositionX/16,p.MapPositionY/16 };
  147.                                 OnMap = true; // Player is in the map
  148.  
  149.                                 bool oldT = p2.on_track;
  150.                                 if (t.type > 8)
  151.                                 {   // Linear on track check
  152.                                     bool newT = ontrack_line(p, t);
  153.                                     if (oldT != newT)
  154.                                     { p2.on_track = newT;}
  155.                                 }
  156.                                 else
  157.                                 {   // Radial on track check
  158.                                     bool newT = ontrack_radial(p, t);
  159.                                     if (oldT != newT)
  160.                                     { p2.on_track = newT;}
  161.                                 }
  162.                             }
  163.                         });
  164.                     }
  165.                     if (OnMap == false)
  166.                     {   // checking to see if they are in the map. this is second check cause i have holes in the map
  167.                         if (collision_detect(new int[]{
  168.                             p.MapPositionX,p.MapPositionY}, new int[]{loaded_map.ref_point[0],loaded_map.ref_point[1],
  169.                             loaded_map.ref_point[0] + loaded_map.ref_point[2],loaded_map.ref_point[1]+loaded_map.ref_point[3]}) == false)
  170.                         {
  171.                             //last recorded position inside of the map
  172.                             warp(p.PlayerName, p2.pos[0], p2.pos[1]);
  173.                         }
  174.                     }
  175.                 });
  176.             }
  177.         }
  178.         // This will update players position
  179.         public void update_progress(PlayerPositionEvent p, track_region t ) // (index #3)
  180.         {
  181.             // itirating through each playe in the list
  182.             p_list.ForEach(delegate(Player p2)
  183.             {
  184.                 // if the name matches
  185.                 if (p2.name == p.PlayerName)
  186.                 {
  187.                     // Linear tracking
  188.                     if (t.type > 8)
  189.                     {
  190.                         if (t.type == 9)// X coordinates going forward
  191.                         {p2.progress[1] = t.c_points[1] + region_progress(true, p.MapPositionX, t.region_pos[0]); }
  192.                         else if (t.type == 10)// X coordinates backwards
  193.                         {p2.progress[1] = t.c_points[1] + region_progress(false, p.MapPositionX, t.region_pos[2]);}
  194.                         else if (t.type == 11) // Y coordinates going forward
  195.                         {p2.progress[1] = t.c_points[1] + region_progress(true, p.MapPositionY, t.region_pos[1]); }
  196.                         else if (t.type == 12)// Y coordinates going forward
  197.                         {p2.progress[1] = t.c_points[1] + region_progress(false, p.MapPositionY, t.region_pos[3]);}
  198.                        
  199.                     }
  200.                     // Radial tracking
  201.                     else
  202.                     {
  203.                         // Regular radial progress is just degrees
  204.                         if ((t.type == 1) || (t.type == 4) || (t.type == 6) || (t.type == 7))
  205.                         { p2.progress[1] = t.c_points[1] + get_rot(p,t); }
  206.                         // With the rest we have to subract 90 from angle to get progress
  207.                         else if ((t.type == 2) || (t.type == 3) || (t.type == 5) || (t.type == 8))
  208.                         { p2.progress[1] = t.c_points[1] + (90 - get_rot(p, t)); }
  209.                     }
  210.  
  211.                     int oldL = p2.progress[0]; // Old Lap
  212.                     int newL = t.c_points[0];  // New Lap
  213.                     // If player lap and region lap are not the same then we need to update
  214.                     if (oldL != newL)
  215.                     {
  216.                         if (newL > oldL )
  217.                         {
  218.                             if (newL - oldL < 2)
  219.                             { p2.laps++; }
  220.                             else
  221.                             { p2.laps -= 1;}
  222.                         }
  223.                         else if (oldL > newL )
  224.                         {
  225.                             if (oldL - newL < 2)
  226.                             { p2.laps -= 1;}
  227.                             else
  228.                             { p2.laps++; }
  229.                         }
  230.                     }
  231.                     // Updating segments
  232.                     p2.progress[0] = t.c_points[0];
  233.                     // Updating total progress and not just segment progress
  234.                     if (p2.laps > loaded_map.laps)
  235.                     {
  236.                         int temp1 = (p2.laps/loaded_map.laps);
  237.                         p2.progress[2] = (temp1 * loaded_map.total_prog) + p2.progress[1];
  238.                     }
  239.                     else if (p2.laps < 0)
  240.                     {
  241.                         if ((p2.laps * -1) > loaded_map.laps)
  242.                         {
  243.                             int temp1 = ((p2.laps * -1)/ loaded_map.laps);
  244.                             p2.progress[2] = ((temp1 * loaded_map.total_prog) + p2.progress[1]) * -1;
  245.                         }
  246.                         else
  247.                         { p2.progress[2] = (loaded_map.total_prog - p2.progress[1]) * -1; }
  248.                     }
  249.                     else if (p2.laps == loaded_map.laps)
  250.                     {
  251.                         p2.progress[2] = loaded_map.total_prog + p2.progress[1];
  252.                     }
  253.                     else if (p2.laps >= 0)
  254.                     { p2.progress[2] = p2.progress[1]; }
  255.                     p_list.Sort(delegate(Player p5, Player p6) { return p6.progress[2].CompareTo(p5.progress[2]); });                  
  256.                 }
  257.             });
  258.             update_place();
  259.         }
  260.         // Radial progress
  261.         public int get_rot(PlayerPositionEvent e, track_region t)
  262.         {
  263.             int send = 0;
  264.             // Formula to extract an angle
  265.             double angle = Math.Atan((double)(e.MapPositionY - t.radial_point[1]) / (double)(e.MapPositionX - t.radial_point[0])) * (180.0 / 3.14159);
  266.             // In case of a negative number we make it positive here
  267.             if (angle < 0)
  268.             { angle = angle * -1; }
  269.             send = (int)Math.Floor(angle);
  270.             return send;
  271.         }
  272.         // Linear progress
  273.         public int region_progress(bool forward, int playerVar, int regionVar)
  274.         {//(checkpoints.max added up) + (player(a) - region(a))
  275.             int send = 0;
  276.             if (forward)//or clockwise
  277.             { send = playerVar - (regionVar * 16); }
  278.             else //or backwards Counterclockwise
  279.             { send = ((regionVar * 16) + 15) - playerVar;}
  280.             return send;
  281.         }
  282.         // Update players placements
  283.         public void update_place()
  284.         {
  285.             byte new_p = 1;
  286.             p_list.ForEach(delegate(Player p)
  287.             {
  288.                 if (p.place != new_p)
  289.                 {
  290.                     message(2,p.name,"*objset -" + (rankLvz_prefix + p.place) + ",+" + (rankLvz_prefix + new_p) + ",");
  291.                     p.place = new_p;
  292.                 }
  293.                 new_p++;
  294.             });
  295.         }
  296.         //----------------------------------------------------------------\\
  297.  
  298.         //          +--------------------+
  299.         //          | On-Track Detection |
  300.         //          +--------------------+
  301.         // -----------  offtrack_line  ----------------
  302.         // Collision code for track - vertical or horizontal. Returns true if collision is detected
  303.         // int[] t = track region. upper left (x1,y1) = (t[0]),(t[1]) and (x2,y2) = (t[2]),(t[3])
  304.         public bool ontrack_line(PlayerPositionEvent p, track_region t)
  305.         {
  306.             return collision_detect(new int[] { p.MapPositionX, p.MapPositionY }, t.in_track);
  307.         }
  308.         // -----------  offtrack_radius  ----------------
  309.         // Collision code for track - elbows. Returns true if collision is detected
  310.         public bool ontrack_radial(PlayerPositionEvent p, track_region t)
  311.         {
  312.             bool send = false;
  313.             double inner = GetDistance(t.radial_point[0],t.radial_point[1],t.in_track[0] * 16,t.in_track[1] * 16);
  314.             double outer = GetDistance(t.radial_point[0], t.radial_point[1], t.in_track[2] * 16, t.in_track[3] * 16);
  315.             double player = GetDistance(t.radial_point[0], t.radial_point[1], p.MapPositionX, p.MapPositionY);
  316.             //debug_msg(inner + ":" + outer + ":" + player + ":");
  317.             if (inner < outer)
  318.             {
  319.                 if (player > inner && player < outer)
  320.                 { send = true;}
  321.             }
  322.             else
  323.             {
  324.                 if (player < inner && player > outer)
  325.                 { send = true; }
  326.             }
  327.             return send;
  328.         }
  329.         private static double GetDistance(double x1,double y1,double x2,double y2)
  330.         {
  331.             //pythagoras theorem c^2 = a^2 + b^2
  332.             //thus c = square root(a^2 + b^2)
  333.             double a = (double)(x2 - x1);
  334.             double b = (double)(y2 - y1);
  335.  
  336.             return Math.Sqrt(a * a + b * b);
  337.         }
  338.         //----------------------------------------------------------------\\
  339.  
  340.         //          +--------------------+
  341.         //          |   Chat Commands    |
  342.         //          +--------------------+
  343.         // ------------- DEBUG toggle ----------------
  344.         // toggles debug mode
  345.         public void toggle_debug(ChatEvent c)
  346.         {
  347.             if (ModLevels.Sysop == c.ModLevel)
  348.             {
  349.                 debug = !debug;
  350.                 message(3, "", "Debug mode set to:<" + debug + ">.");
  351.             }
  352.         }
  353.         public void load_map2(ChatEvent c)
  354.         {
  355.             if (ModLevels.Sysop == c.ModLevel)
  356.             {
  357.                 string[] data = (c.Message.Trim()).Split(' ');
  358.                 load_Map(byte.Parse(data[1]));
  359.                 GameOn = true;
  360.                 debug_msg("Game mode on!");
  361.             }
  362.         }
  363.         public void show_prog(ChatEvent c)
  364.         {
  365.             if (ModLevels.Sysop == c.ModLevel)
  366.             {
  367.                 p_list.ForEach(delegate(Player p)
  368.                 {
  369.                     message(3, "", "Name:<" + p.name + ">    Laps:<"+ p.laps +"/" + loaded_map.laps + ">  Progress:<" + p.progress[1] + "/" + p.progress[2] + ">.");
  370.                 });
  371.             }
  372.         }
  373.  
  374.         //----------------------------------------------------------------\\
  375.  
  376.         //          +--------------------+
  377.         //          |   Misc Utilities   |
  378.         //          +--------------------+
  379.         // ---  General  Collision Detection  ---
  380.         public bool collision_detect(int[] player,int[] obstacle)
  381.         {
  382.             bool send = false;
  383.             if ((player[0] > obstacle[0] * 16) && (player[1] > obstacle[1] * 16) && (player[0] < obstacle[2] * 16) && (player[1] < obstacle[3] * 16))
  384.             { send = true; }
  385.             return send;
  386.         }
  387.         // Updating player ship type
  388.         public void monitor_SC(object sender, ShipChangeEvent s)
  389.         {
  390.             bool on_list = false;
  391.             p_list.ForEach(delegate(Player p)
  392.             {
  393.                 if (p.name == s.PlayerName)
  394.                 {
  395.                     on_list = true;
  396.                     p.ship = s.ShipType;
  397.                 }
  398.             });
  399.             if (on_list == false && s.PreviousShipType == ShipTypes.Spectator)
  400.             {
  401.                 Player add = new Player(s.PlayerName);
  402.                 add.progress = new int[] { 1, 0 ,0};
  403.                 add.penalty = new byte[] { 0, max_penalties };
  404.                 add.ship = s.ShipType;
  405.                 add.on_track = true;
  406.                 add.place = 8;
  407.                 p_list.Add(add);
  408.                 debug_msg("Player:<" + s.PlayerName + "> added to main player list.");
  409.                 warp(s.PlayerName, 133, 843);
  410.                 message(2, s.PlayerName, "*shipreset");
  411.             }
  412.             else if (s.ShipType == ShipTypes.Spectator)
  413.             {
  414.                 p_list.ForEach(delegate(Player p)
  415.                 {
  416.                     if (p.name == s.PlayerName)
  417.                     {
  418.                         p_list.Remove(p);
  419.                         debug_msg("Player:<" + s.PlayerName + "> has been deleted from the main player list.");
  420.                     }
  421.                 });
  422.             }
  423.         }
  424.         // messages that are only displayed when debug is set to true
  425.         public void debug_msg(string msg)
  426.         {
  427.             if (debug)
  428.             {
  429.                 message(3, "", msg);
  430.             }
  431.         }
  432.         public void p_downgrade()
  433.         {
  434.             p_list.ForEach(delegate(Player p)
  435.             {
  436.                 if (p.on_track == false && p.penalty[0] < p.penalty[1] )
  437.                 {
  438.                     p.penalty[0] += 1;
  439.                     message(2, p.name, "*prize #-12");
  440.                 }
  441.             });
  442.         }
  443.         public void l_upgrade()
  444.         {
  445.             p_list.ForEach(delegate(Player p)
  446.             {
  447.                 if (p.on_track && p.penalty[0] > 0)
  448.                 {
  449.                     if (p.ship == ShipTypes.Leviathon || p.ship == ShipTypes.Weasel || p.ship == ShipTypes.Lancaster)
  450.                     {
  451.                         p.penalty[0] -= 1;
  452.                         message(2, p.name, "*prize #12");
  453.                     }
  454.                 }
  455.             });
  456.         }
  457.         public void m_upgrade()
  458.         {
  459.             p_list.ForEach(delegate(Player p)
  460.             {
  461.                 if (p.on_track && p.penalty[0] > 0)
  462.                 {
  463.                     if (p.ship == ShipTypes.Warbird || p.ship == ShipTypes.Spider)
  464.                     {
  465.                         p.penalty[0] -= 1;
  466.                         message(2, p.name, "*prize #12");
  467.                     }
  468.                 }
  469.             });
  470.         }
  471.         public void h_upgrade()
  472.         {
  473.             p_list.ForEach(delegate(Player p)
  474.             {
  475.                 if (p.on_track && p.penalty[0] > 0)
  476.                 {
  477.                     if (p.ship == ShipTypes.Javelin || p.ship == ShipTypes.Terrier || p.ship == ShipTypes.Shark)
  478.                     {
  479.                         p.penalty[0] -= 1;
  480.                         message(2, p.name, "*prize #12");
  481.                     }
  482.                 }
  483.             });
  484.         }
  485.         // Initializes bot
  486.         public void intitialize()
  487.         {
  488.             message(4, "", "@MK_Initialize@");
  489.             GameOn = true;
  490.             message(3, "", "Debug mode is set to:<" + debug + ">.");
  491.             message(3, "", "MarioKart module initialized.Game Mode On.");
  492.             message(1, "", "*specall");
  493.             RemoveTimedEvent("MK_Init");
  494.             load_Map(1);
  495.             message(3, "", "Map loaded:<" + loaded_map.name + ">.");
  496.         }
  497.         // just a shortcut to warping someone
  498.         public void warp(string name, int x, int y)
  499.         {
  500.             message(2, name, "*warpto " + x + " " + y);
  501.         }
  502.         // ----- Shortcut for sending messages ------
  503.         public void message(ushort type, string name, string msg)
  504.         {
  505.             //creating chat event
  506.             ChatEvent notify = new ChatEvent();
  507.             //extracting playername from EventArgs e
  508.             notify.PlayerName = name;
  509.  
  510.             // Setting Chat type here
  511.             if (type == 1) // Public
  512.             {
  513.                 notify.ChatType = ChatTypes.Public;
  514.             }
  515.             else if (type == 2) // Private
  516.             {
  517.                 notify.ChatType = ChatTypes.Private;
  518.             }
  519.             else if (type == 3) // Arena
  520.             {
  521.                 notify.ChatType = ChatTypes.Arena;
  522.             }
  523.             else if (type == 4) // Zone
  524.             {
  525.                 notify.ChatType = ChatTypes.Zone;
  526.             }
  527.            
  528.             // Including the passed msg
  529.             notify.Message = msg;
  530.             if (type != 4)
  531.             {
  532.                 //sending message
  533.                 SendGameEvent(notify);
  534.             }
  535.             else
  536.             {
  537.                 SendCoreEvent(notify);
  538.             }
  539.         }
  540.  
  541.         //          +--------------------+
  542.         //          |      M A P S       |
  543.         //          +--------------------+
  544.         //-------------------------------------------
  545.         public void load_Map(int map)
  546.         {
  547.             if (map == 1)
  548.             {   //----------------------------- 1,2,3,4,5 ,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
  549.                 byte[] region_type = new byte[]{9,2,7,2,11,4,5,4,3,12, 6, 5, 4,10, 3,12, 1, 8, 1, 9}; // what region type 1-12
  550.                 int[][] region_pos = new int[][]{
  551.                     new int[]{125,0,158,37},    //1
  552.                     new int[]{159,0,206,37},    //2
  553.                     new int[]{159,38,205,83},   //3
  554.                     new int[]{206,37,250,84},   //4
  555.                     new int[]{206,85,250,101},  //5
  556.                     new int[]{206,102,250,149}, //6
  557.                     new int[]{159,102,205,148}, //7
  558.                     new int[]{159,149,206,188}, //8
  559.                     new int[]{112,149,158,188}, //9
  560.                     new int[]{112,102,157,148}, //10
  561.                     new int[]{112,63,154,101},  //11
  562.                     new int[]{69,60,111,101},   //12
  563.                     new int[]{65,102,111,188},  //13
  564.                     new int[]{44,106,64,188},   //14
  565.                     new int[]{0,102,43,188},    //15
  566.                     new int[]{0,85,44,101},     //16
  567.                     new int[]{0,37,43,84},      //17
  568.                     new int[]{44,38,88,78},     //18
  569.                     new int[]{43,0,90,37},      //19
  570.                     new int[]{91,0,124,37},     //20
  571.                 }; // x1,y1,x2,y2 in tiles!!!!!!!!!
  572.                 int[][] on_track = new int[][] {
  573.                     new int[]{125,7,159,22},    //1
  574.                     new int[]{159,22,159,7},    //2
  575.                     new int[]{190,38,175,38},   //3
  576.                     new int[]{206,69,206,54},   //4
  577.                     new int[]{222,85,237,102},  //5
  578.                     new int[]{222,102,237,102}, //6
  579.                     new int[]{190,148,175,148}, //7
  580.                     new int[]{175,149,190,149}, //8
  581.                     new int[]{143,149,128,149}, //9
  582.                     new int[]{128,102,143,149}, //10
  583.                     new int[]{112,86,112,71},   //11
  584.                     new int[]{96,101,81,101},   //12
  585.                     new int[]{81,102,96,102},   //13
  586.                     new int[]{44,118,65,133},   //14
  587.                     new int[]{28,102,13,102},   //15
  588.                     new int[]{13,85,28,102},    //16
  589.                     new int[]{28,84,13,84},     //17
  590.                     new int[]{44,54,44,69},     //18
  591.                     new int[]{75,37,60,37},     //19
  592.                     new int[]{91,7,125,22}     //20
  593.                 };
  594.                 int[][] spoint = new int[][] {
  595.                     new int[]{129,14},  //1
  596.                     new int[]{163,15},  //2
  597.                     new int[]{182,14},  //3
  598.                     new int[]{211,62},  //4
  599.                     new int[]{229,88},  //5
  600.                     new int[]{228,107}, //6
  601.                     new int[]{201,125}, //7
  602.                     new int[]{181,152}, //8
  603.                     new int[]{154,172}, //9
  604.                     new int[]{135,144}, //10
  605.                     new int[]{134,197}, //11
  606.                     new int[]{108,78},  //12
  607.                     new int[]{87,105},  //13
  608.                     new int[]{60,126},  //14
  609.                     new int[]{40,126},  //15
  610.                     new int[]{20,98},   //16
  611.                     new int[]{20,80},   //17
  612.                     new int[]{47,61},   //18
  613.                     new int[]{68,33},   //19
  614.                     new int[]{94,14}    //20
  615.                 };
  616.                 Map test_map = new Map("Test Map");
  617.                 test_map.ref_point = new int[] {380,440,250,188};
  618.                 List<track_region> all_region = new List<track_region>();
  619.                 int acc_prog = 0;
  620.                 for (int i = 0; i < region_type.Length; i++)
  621.                 {
  622.                     track_region add = new track_region(region_type[i]);
  623.                     // Making sure the points are all based off of ref point
  624.                     add.region_pos = new int[]{
  625.                         region_pos[i][0] + test_map.ref_point[0], // X1
  626.                         region_pos[i][1] + test_map.ref_point[1], // Y1
  627.                         region_pos[i][2] + test_map.ref_point[0], // X2
  628.                         region_pos[i][3] + test_map.ref_point[1]};// Y2
  629.                     // For radial we need to find the point to compare the player with
  630.                     add.radial_point = get_rpoint(region_type[i], region_pos[i], test_map.ref_point);
  631.                     add.c_points = new int[] { (i + 1),acc_prog}; // adding to the total progress
  632.                     acc_prog = acc_prog + get_regionprog(region_type[i], region_pos[i]);
  633.                     add.in_track = new int[] {
  634.                     on_track[i][0] += test_map.ref_point[0],
  635.                     on_track[i][1] += test_map.ref_point[1],
  636.                     on_track[i][2] += test_map.ref_point[0],
  637.                     on_track[i][3] += test_map.ref_point[1]
  638.                     };
  639.                     add.s_point = spoint[i];
  640.                     add.s_point = new int[] {
  641.                     spoint[i][0] += test_map.ref_point[0],
  642.                     spoint[i][1] += test_map.ref_point[1],
  643.                     };
  644.                     all_region.Add(add);
  645.                 }
  646.                 test_map.laps = (byte)all_region.Count;
  647.                 test_map.regions = all_region;
  648.                 test_map.total_prog = acc_prog;
  649.                 loaded_map = test_map;
  650.                 debug_msg("Map Loaded. <" + loaded_map.name + ">.");
  651.             }
  652.         }
  653.         // Finding the very last pixel on the corner corresponding with that track type
  654.         public int[] get_rpoint(byte type,int[] pos, int[] ref_p)
  655.         {
  656.             int[] send = {69,69};
  657.             // using x,y cause its too damn confusing for me to use pos[]
  658.             int x1 = (pos[0] + ref_p[0]) * 16;
  659.             int y1 = (pos[1] + ref_p[1]) * 16;
  660.             int x2 = (pos[2] + ref_p[0]) * 16;
  661.             int y2 = (pos[3] + ref_p[1]) * 16;
  662.            
  663.             // Grouping similar track types. They are measured off of same point
  664.             if (type == 1 || type == 5)
  665.             { send = new int[] {x2 + 15, y2 + 15}; }
  666.             else if (type == 2 || type == 6)
  667.             { send = new int[] { x1, y2 + 15};}
  668.             else if (type == 3 || type == 7)
  669.             { send = new int[] { x2 + 15, y1};}
  670.             else if (type == 4 || type == 8)
  671.             { send = new int[] { x1, y1 };}
  672.             return send;
  673.         }
  674.         // Using this to add up all progress for entire map
  675.         public int get_regionprog(byte type,int[] pos)
  676.         {
  677.             int send = 0;
  678.             if (type == 9 || type == 10)                    // horizontal
  679.             { send = ((pos[2] * 16) + 15) - (pos[0] * 16); }
  680.             else if (type == 11 || type == 12)              // vertical
  681.             { send = ((pos[3] * 16) + 15) - (pos[1] * 16);}
  682.             else                                            // its radial. all 90 points
  683.             { send = 90; }
  684.             return send;
  685.         }
  686.         public override void Dispose()
  687.         {
  688.             throw new NotImplementedException();
  689.         }
  690.     }
  691. }
  692. //          +--------------------+
  693. //          |    Changelog       |
  694. //          +--------------------+
  695. //-------------------------------------------
  696. //1.0   Added player position to player container. Also changed code to warp back function.
  697. //-------------------------------------------
  698.  
  699. //-----------------------------------------------------------------\\ index# 1
  700. /* I will begin a timer at start of game. Every x/100s
  701.  * I will compare progress to last stored progress and determine if
  702.  * the player lost or gained distance and store it as a true/false.
  703.  * from there i can check the last x amount of bools to see if there
  704.  * is a pattern of falses to know if player is going the wrong way
  705.  * this is to ensure i dont display a "going backwards" message
  706.  * every time the player is knocked back.*/
  707. //------------------------------------------------------------------\\ index# 2
  708. /* progress[] = {laps,progress}
  709.  * if horizontal or vertical progress will be:
  710.  * progress = xcoord  or
  711.  * progress = ycoord
  712.  * if its an elbow it will be recorded in radians:
  713.  * progress = degrees */
  714. //------------------------------------------------------------------\\ index# 3
  715. /* Radial progress will have 90 points max for its region
  716.  * Current progress for clockwise:
  717.  * (checkpoints.max added up) + [(player(angle) - region.start(angle)]
  718.  * Current progress for counter-clockwise:
  719.  * (checkpoints.max added up) + (region_angle.end - player.angle)
  720.  *
  721.  * Linear will use the following:
  722.  * total progress for region = ((a2 * 16) + 15) - (a1 * 16)
  723.  * where a = x or y coordinates depending on region type (hor or vert)
  724.  * to figure out current progress for L->R or U->D :
  725.  * (checkpoints.max added up) + (player(a) - region(a))  --where a = x or y
  726.  * progress for R->L or D->U then: --where a = x or y--
  727.  * (checkpoints.max added up) + [(region(a2) - player(a))]*/
  728.  //------------------------------------------------------------------\\ index #4
  729. /* checkpoint[1] will be all checkpoints added up to that point */
Advertisement
Add Comment
Please, Sign In to add comment