aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/starting.go (1327B)


      1 package main
      2 
      3 import "fmt"
      4 
      5 func (server *server) startingPosition(side uint16) (playerPosition, error) {
      6 	data := playerPosition{Playfield: []uint32{954, 952, 950}[side]}
      7 
      8 	// Enter just beyond the authored backyard door, using the normal zone clearance.
      9 	door := server.zoneLinks["target"][data.Playfield].Doors[0]
     10 	data.Position, data.Rotation = door.Position, door.Rotation
     11 	x, y, z, w := door.Rotation[0], door.Rotation[1], door.Rotation[2], door.Rotation[3]
     12 	data.Position[0] += 2.5 * (2*x*z + 2*y*w)
     13 	data.Position[2] += 2.5 * (1 - 2*x*x - 2*y*y)
     14 	ground, _ := server.terrain[data.Playfield].elevation(data.Position[0], data.Position[2])
     15 	data.Position[1] = ground + 0.75
     16 
     17 	// Assign the first supported backyard; its original allocation policy is unknown.
     18 	for playfield, zone := range server.zoneLinks["target"] {
     19 		for _, entrance := range zone.Doors {
     20 			if entrance.Destination != data.Playfield || entrance.DestinationDoor != door.ID {
     21 				continue
     22 			}
     23 			if data.ReturnDoor == nil || playfield < data.ReturnDoor.Playfield ||
     24 				playfield == data.ReturnDoor.Playfield && entrance.ID < data.ReturnDoor.Door {
     25 				data.ReturnDoor = &doorOrigin{playfield, entrance.ID}
     26 			}
     27 		}
     28 	}
     29 	if data.ReturnDoor == nil {
     30 		return playerPosition{}, fmt.Errorf("training ground has no backyard entrance")
     31 	}
     32 	return data, nil
     33 }