public Component GetClosestComponent(int x, int y, ComponentFilter cf) { Component result = null; int componentType = cf.Type; List<Component> components = m_vComponents[componentType]; Vector v = new Vector(x,y); double maxLengthSquared = 0; if (components.Count > 0) { foreach(var c in components) { if(cf.TestComponent(c)) { GameObject go = c.GetParent(); double lengthSquared = (v - go.GetPosition()).LengthSquared; if(lengthSquared < maxLengthSquared || result == null) { maxLengthSquared = lengthSquared; result = c; } } } } return result; }
public Component GetClosestComponent(int x, int y, ComponentFilter cf) { Component result = null; int componentType = cf.Type; List <Component> components = m_vComponents[componentType]; Vector v = new Vector(x, y); double maxLengthSquared = 0; if (components.Count > 0) { foreach (var c in components) { if (cf.TestComponent(c)) { GameObject go = c.GetParent(); double lengthSquared = (v - go.GetPosition()).LengthSquared; if (lengthSquared < maxLengthSquared || result == null) { maxLengthSquared = lengthSquared; result = c; } } } } return(result); }
public Component GetClosestComponent(int x, int y, ComponentFilter cf) { Component component = null; int type = cf.Type; List <Component> list = this.m_vComponents[type]; Vector vector = new Vector((double)x, (double)y); double num = 0.0; if (list.Count > 0) { foreach (Component current in list) { if (cf.TestComponent(current)) { GameObject parent = current.GetParent(); double lengthSquared = (vector - parent.GetPosition()).LengthSquared; if (lengthSquared < num || component == null) { num = lengthSquared; component = current; } } } } return(component); }
public bool ProductionCompleted() { var result = false; //localiser le camp le plus proche pour envoyer l'unit //incrementer ce camp var cf = new ComponentFilter(0); var x = GetParent().X; var y = GetParent().Y; var cm = GetParent().GetLevel().GetComponentManager(); var c = cm.GetClosestComponent(x, y, cf); while (c != null) { Data d = null; if (m_vUnits.Count > 0) { d = m_vUnits[0].Data; } if (!((UnitStorageComponent)c).CanAddUnit((CombatItemData)d)) { //Storage camp is full cf.AddIgnoreObject(c.GetParent()); c = cm.GetClosestComponent(x, y, cf); } else { break; } } if (c != null) { var cd = (CombatItemData)m_vUnits[0].Data; ((UnitStorageComponent)c).AddUnit(cd); StartProducingNextUnit(); result = true; } else { m_vIsWaitingForSpace = true; } return(result); }
public bool ProductionCompleted() { var result = false; var cf = new ComponentFilter(0); var x = GetParent().X; var y = GetParent().Y; var cm = GetParent().Avatar.GetComponentManager(); var c = cm.GetClosestComponent(x, y, cf); while (c != null) { Data d = null; if (m_vUnits.Count > 0) { d = m_vUnits[0].Data; } if (!((UnitStorageComponent)c).CanAddUnit((CombatItemData)d)) { cf.AddIgnoreObject(c.GetParent()); c = cm.GetClosestComponent(x, y, cf); } else { break; } } if (c != null) { var cd = (CombatItemData)m_vUnits[0].Data; ((UnitStorageComponent)c).AddUnit(cd); StartProducingNextUnit(); result = true; } else { m_vIsWaitingForSpace = true; } return(result); }
public bool ProductionCompleted() { bool result = false; //localiser le camp le plus proche pour envoyer l'unit //incrementer ce camp ComponentFilter cf = new ComponentFilter(0); int x = GetParent().X; int y = GetParent().Y; ComponentManager cm = GetParent().GetLevel().GetComponentManager(); Component c = cm.GetClosestComponent(x, y, cf); while (c != null) { Data d = null; if (m_vUnits.Count > 0) d = m_vUnits[0].Data; if (!((UnitStorageComponent)c).CanAddUnit((CombatItemData)d)) { //Storage camp is full cf.AddIgnoreObject(c.GetParent()); c = cm.GetClosestComponent(x, y, cf); } else break; } if(c != null) { var cd = (CombatItemData)m_vUnits[0].Data; ((UnitStorageComponent)c).AddUnit(cd); StartProducingNextUnit(); result = true; } else { m_vIsWaitingForSpace = true; } return result; }