Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.79 KB | None | 0 0
  1.  public void createMapFile()
  2.     {
  3.  
  4.         //this part is finding all objects to save and getting their shitz like coordinates, type, face etc.
  5.        
  6.         objectId = new int[totalObjects+1];
  7.         type = new int[totalObjects];
  8.     face = new int[totalObjects];
  9.    height = new int[totalObjects];
  10.     objectX = new int[totalObjects];
  11.     objectY = new int[totalObjects];
  12.        
  13.         obj.Clear();
  14.         mapId = Convert.ToInt32(mapids.text);
  15.        
  16. data = new DataBuffer();
  17.              foreach (GameObject objs in GameObject.FindGameObjectsWithTag("Player")) //yes, cba to rename the tag lol
  18.         {
  19.             obj.Add(objs);
  20.         }
  21.        
  22.             totalObjects =  obj.Count;
  23.        
  24.        
  25.        
  26.             for( int i = 0; i < totalObjects; i++) {
  27.            
  28.  
  29.                 String[] objinfo = obj[i].name.Split(new char[] { '-' }, 2); //object name is objid-type to make things easier
  30.                 objectId[i] = Convert.ToInt32(objinfo[0]);
  31.  
  32.                 type[i] = Convert.ToInt32(objinfo[1]);
  33.                
  34.             if (obj[i].transform.eulerAngles.y == 180) {
  35.                 face[i] = 0;
  36.             }
  37.             else if (obj[i].transform.eulerAngles.y == 270)
  38.             {
  39.                 face[i] = 1;
  40.             }
  41.        
  42.             else if (obj[i].transform.eulerAngles.y == 0)
  43.             {
  44.                 face[i] = 2;
  45.             }
  46.             else if (obj[i].transform.eulerAngles.y == 90)
  47.             {
  48.                 face[i] = 3;
  49.             }
  50.  
  51.             if (obj[i].transform.position.y == 0) {
  52.                 height[i] = 0;
  53.             } else if (obj[i].transform.position.y == 2) {
  54.                 height[i] = 1;
  55.             } else if (obj[i].transform.position.y == 4) {
  56.                 height[i] = 2;
  57.             } else if (obj[i].transform.position.y == 6) {
  58.                 height[i] = 3;
  59.             }
  60.  
  61.             objectX[i] = (int)obj[i].transform.position.x;
  62.             objectY[i] = (int)obj[i].transform.position.z;
  63.  
  64.         }
  65.        
  66.  
  67. //actual writing starts here
  68.          
  69.  
  70.     int addedObj = 0;
  71.  
  72.         int objID = 0;//-1;
  73.  
  74.         do
  75.         {
  76.             int objOffset = 0;//object ids are not stored, just the difference from the last one
  77.             if (addedObj == 0)
  78.                 objOffset = objectId[addedObj] + 1;
  79.             else if (addedObj == totalObjects)
  80.             {//reach the end
  81.                 objOffset = 0;
  82.             }
  83.             else
  84.             {
  85.                 objOffset = (objectId[addedObj] - objectId[addedObj - 1]);
  86.             }
  87.             data.writeSmart((byte)37, objOffset);
  88.             if (objOffset == 0)//stops writting
  89.                 break;
  90.  
  91.             int j1 = 0;
  92.  
  93.             objID += objOffset;
  94.  
  95.             do
  96.             {
  97.  
  98.                 int height1 = height[addedObj];
  99.                 int localY1 = objectY[addedObj];
  100.                 int localX1 = objectX[addedObj];
  101.                 int type1 = type[addedObj];
  102.                 int face1 = face[addedObj];
  103.  
  104.                 int y = 0;
  105.                 int x = 0;
  106.                 int k1 = 0;
  107.                 int type_face = 0;
  108.  
  109.                 x = localX1;
  110.                 y = localY1;
  111.  
  112.                 int tempj1 = 0;
  113.                 tempj1 += y;
  114.                 tempj1 += x << 6;
  115.                 tempj1 += height1 << 12;
  116.  
  117.                 k1 = (tempj1 - j1) + 1;
  118.                 j1 = tempj1;
  119.  
  120.                 data.writeSmart((byte)37, k1);
  121.  
  122.                 type_face = (type1 << 2) + face1;
  123.                 data.writeByte(type_face);
  124.  
  125.                 if (objectId[addedObj + 1] > objectId[addedObj] || addedObj + 1 == totalObjects)
  126.                 {
  127.                     addedObj++;
  128.                     data.writeSmart((byte)37, 0);
  129.                     break;
  130.                 }
  131.                 else
  132.                 {
  133.                     addedObj++;
  134.                 }
  135.  
  136.             } while (true);
  137.  
  138.         } while (true);
  139.  
  140.         data.writeFile("F:/"+mapId+".dat", data.GetBytesFromList());
  141.  
  142.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement