public override double[] compareTo(Part otherPart) { if (otherPart.GetType() == this.GetType()) { List <double> differenceInStats = new List <double>(); Mobility comparablePart = (Mobility)otherPart; differenceInStats.AddRange(base.compareTo(otherPart)); differenceInStats.Add(comparablePart.getClimbAngle() - CLIMB_ANGLE); differenceInStats.Add(comparablePart.getMaxSpeed() - MAX_SPEED); differenceInStats.Add(comparablePart.getMaxForce() - MAX_FORCE); return(differenceInStats.ToArray()); } else { return(base.compareTo(otherPart)); } }
public override bool equals(Part part) { Mobility mobility = (Mobility)part; return(base.equals(part) && CLIMB_ANGLE == mobility.getClimbAngle() && MAX_SPEED == mobility.getMaxSpeed() && MAX_FORCE == mobility.getMaxForce()); }
public Robot(string name, bool human, Head head, Body body, Mobility mobility, Attachment[] attachments) { Point position = new Point(); cachedPosition = position; cachedAngle = position; force = new Point(); damageReceived = 0; damageDealt = 0; active = true; positionInitialized = false; HUMAN = human; if (name != default && name != "") { this.name = name; } else { this.name = DEFAULT_NAME; } HEAD = head; BODY = body; MOBILITY = mobility; ATTACHMENTS = new Carousel <Attachment>(); ATTACHMENTS.AddRange(attachments); if (HEAD == null || BODY == null || MOBILITY == null || !ATTACHMENTS.Exists(attachment => attachment.isWeapon())) { throw new Exception("Some parts of a robot are missing. Robots with missing parts will deleted."); } else { GAME_OBJECT = new GameObject(); GAME_OBJECT.AddComponent <Rigidbody>(); Vector3 robotFootprint = GAME_OBJECT.AddComponent <BoxCollider>().bounds.size; GAME_OBJECT.GetComponent <Collider>().isTrigger = true; GAME_OBJECT.GetComponent <Rigidbody>().useGravity = true; setConstraints(); Vector3 rescale = GAME_OBJECT.transform.localScale; rescale.x = (float)SCALE / robotFootprint.x; rescale.y = (float)SCALE / robotFootprint.z; rescale.z = (float)SCALE / robotFootprint.z; GAME_OBJECT.transform.localScale = rescale; HEAD.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false); BODY.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false); MOBILITY.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false); Vector3 robotPosition = GAME_OBJECT.transform.position = position.toVector3(); MOBILITY.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, 0, robotPosition.z); BODY.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER, robotPosition.z); if (HEAD.getShape() == Shape.SHAPES.HEMISPHERE) { HEAD.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER + BODY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y - HEAD.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y / 2, robotPosition.z); } else { HEAD.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER + BODY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y, robotPosition.z); } double attachmentWeight = 0; if (ATTACHMENTS != null && ATTACHMENTS.Count > 0) { foreach (Attachment attachment in ATTACHMENTS) { attachmentWeight += attachment.getWeight(); } } WEIGHT = HEAD.getWeight() + BODY.getWeight() + MOBILITY.getWeight() + attachmentWeight; MAX_ATTACHMENTS = BODY.getMaxAttachments(); CLIMB_ANGLE = MOBILITY.getClimbAngle(); MAX_SPEED = MOBILITY.getMaxSpeed(); MAX_FORCE = MOBILITY.getMaxForce(); Vector3 footprint = GAME_OBJECT.AddComponent <BoxCollider>().bounds.size; SIZE = new Dimension(footprint.x, footprint.y, footprint.z); } }
public Robot(string name, bool human, Part[] parts) { Point position = new Point(); cachedPosition = position; cachedAngle = position; force = new Point(); damageReceived = 0; damageDealt = 0; active = true; positionInitialized = false; HUMAN = human; if (name != default && name != "") { this.name = name; } else { this.name = DEFAULT_NAME; } ATTACHMENTS = new Carousel <Attachment>(); foreach (Part part in parts) { if (part is Head) { HEAD = (Head)part; } else if (part is Body) { BODY = (Body)part; } else if (part is Mobility) { MOBILITY = (Mobility)part; } else { ATTACHMENTS.Add((Attachment)part); } } if (HEAD == null || BODY == null || MOBILITY == null || !ATTACHMENTS.Exists(attachment => attachment.isWeapon())) { throw new Exception(); } else { if (HEAD.GAME_OBJECT == default) { HEAD = new Head(HEAD.getID(), HEAD.getImage(), HEAD.getWeight(), HEAD.getShape(), HEAD.getDurability(), HEAD.getRemainingDurability()); } if (BODY.GAME_OBJECT == default) { BODY = new Body(BODY.getID(), BODY.getImage(), BODY.getWeight(), BODY.getShape(), BODY.getDurability(), BODY.getRemainingDurability(), BODY.getMaxAttachments()); } if (MOBILITY.GAME_OBJECT == default) { MOBILITY = new Mobility(MOBILITY.getID(), MOBILITY.getImage(), MOBILITY.getWeight(), MOBILITY.getShape(), MOBILITY.getDurability(), MOBILITY.getRemainingDurability(), MOBILITY.getClimbAngle(), MOBILITY.getMaxSpeed(), MOBILITY.getMaxForce()); } GAME_OBJECT = new GameObject(); GAME_OBJECT.AddComponent <Rigidbody>(); Vector3 robotFootprint = GAME_OBJECT.AddComponent <BoxCollider>().bounds.size; GAME_OBJECT.GetComponent <Collider>().isTrigger = true; GAME_OBJECT.GetComponent <Rigidbody>().useGravity = true; setConstraints(); Vector3 rescale = GAME_OBJECT.transform.localScale; rescale.x = (float)SCALE / robotFootprint.x; rescale.y = (float)SCALE / robotFootprint.z; rescale.z = (float)SCALE / robotFootprint.z; GAME_OBJECT.transform.localScale = rescale; HEAD.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false); BODY.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false); MOBILITY.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false); Vector3 robotPosition = GAME_OBJECT.transform.position = position.toVector3(); MOBILITY.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, 0, robotPosition.z); BODY.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER, robotPosition.z); if (HEAD.getShape() == Shape.SHAPES.HEMISPHERE) { HEAD.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER + BODY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y - HEAD.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y / 2, robotPosition.z); } else { HEAD.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER + BODY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y, robotPosition.z); } double attachmentWeight = 0; if (ATTACHMENTS != null && ATTACHMENTS.Count > 0) { foreach (Attachment attachment in ATTACHMENTS) { attachmentWeight += attachment.getWeight(); } } WEIGHT = HEAD.getWeight() + BODY.getWeight() + MOBILITY.getWeight() + attachmentWeight; MAX_ATTACHMENTS = BODY.getMaxAttachments(); CLIMB_ANGLE = MOBILITY.getClimbAngle(); MAX_SPEED = MOBILITY.getMaxSpeed(); MAX_FORCE = MOBILITY.getMaxForce(); Vector3 footprint = GAME_OBJECT.AddComponent <BoxCollider>().bounds.size; SIZE = new Dimension(footprint.x, footprint.y, footprint.z); } }