Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void createMapFile()
- {
- //this part is finding all objects to save and getting their shitz like coordinates, type, face etc.
- objectId = new int[totalObjects+1];
- type = new int[totalObjects];
- face = new int[totalObjects];
- height = new int[totalObjects];
- objectX = new int[totalObjects];
- objectY = new int[totalObjects];
- obj.Clear();
- mapId = Convert.ToInt32(mapids.text);
- data = new DataBuffer();
- foreach (GameObject objs in GameObject.FindGameObjectsWithTag("Player")) //yes, cba to rename the tag lol
- {
- obj.Add(objs);
- }
- totalObjects = obj.Count;
- for( int i = 0; i < totalObjects; i++) {
- String[] objinfo = obj[i].name.Split(new char[] { '-' }, 2); //object name is objid-type to make things easier
- objectId[i] = Convert.ToInt32(objinfo[0]);
- type[i] = Convert.ToInt32(objinfo[1]);
- if (obj[i].transform.eulerAngles.y == 180) {
- face[i] = 0;
- }
- else if (obj[i].transform.eulerAngles.y == 270)
- {
- face[i] = 1;
- }
- else if (obj[i].transform.eulerAngles.y == 0)
- {
- face[i] = 2;
- }
- else if (obj[i].transform.eulerAngles.y == 90)
- {
- face[i] = 3;
- }
- if (obj[i].transform.position.y == 0) {
- height[i] = 0;
- } else if (obj[i].transform.position.y == 2) {
- height[i] = 1;
- } else if (obj[i].transform.position.y == 4) {
- height[i] = 2;
- } else if (obj[i].transform.position.y == 6) {
- height[i] = 3;
- }
- objectX[i] = (int)obj[i].transform.position.x;
- objectY[i] = (int)obj[i].transform.position.z;
- }
- //actual writing starts here
- int addedObj = 0;
- int objID = 0;//-1;
- do
- {
- int objOffset = 0;//object ids are not stored, just the difference from the last one
- if (addedObj == 0)
- objOffset = objectId[addedObj] + 1;
- else if (addedObj == totalObjects)
- {//reach the end
- objOffset = 0;
- }
- else
- {
- objOffset = (objectId[addedObj] - objectId[addedObj - 1]);
- }
- data.writeSmart((byte)37, objOffset);
- if (objOffset == 0)//stops writting
- break;
- int j1 = 0;
- objID += objOffset;
- do
- {
- int height1 = height[addedObj];
- int localY1 = objectY[addedObj];
- int localX1 = objectX[addedObj];
- int type1 = type[addedObj];
- int face1 = face[addedObj];
- int y = 0;
- int x = 0;
- int k1 = 0;
- int type_face = 0;
- x = localX1;
- y = localY1;
- int tempj1 = 0;
- tempj1 += y;
- tempj1 += x << 6;
- tempj1 += height1 << 12;
- k1 = (tempj1 - j1) + 1;
- j1 = tempj1;
- data.writeSmart((byte)37, k1);
- type_face = (type1 << 2) + face1;
- data.writeByte(type_face);
- if (objectId[addedObj + 1] > objectId[addedObj] || addedObj + 1 == totalObjects)
- {
- addedObj++;
- data.writeSmart((byte)37, 0);
- break;
- }
- else
- {
- addedObj++;
- }
- } while (true);
- } while (true);
- data.writeFile("F:/"+mapId+".dat", data.GetBytesFromList());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement