public void Add(Event e){ if(e.TimeToExecute() == turn){ //0-time action list.Insert(0, e); } else{ if(list.Count == 0 || (list.Count > 0 && list[0] == null)){ list.Insert(0, e); } else{ if (list.Count > 0 && e >= list[list.Count - 1]) { list.Insert(list.Count, e); } else{ if (list.Count > 0 && e < list[0]) { list.Insert(0, e); } else{ //it's going between two events Event current = list[list.Count - 1]; int cr = list.Count; while(true){ cr--; if (e >= list[cr]) { list.Insert(cr + 1, e); return; } } /*if(e.TimeToExecute() == current.Value.TimeToExecute()){ if(e.type != EventType.MOVE){ list.AddAfter(current,e); return; } else{ while(current.Value.type != EventType.MOVE){ if(current == list.First){ list.AddFirst(e); return; } else{ if(e.TimeToExecute() != current.Previous.Value.TimeToExecute()){ list.AddBefore(current,e); return; } else{ current = current.Previous; } } } list.AddAfter(current,e); return; } } else{ if(e < current.Value){ if(e > current.Previous.Value){ list.AddBefore(current,e); return; } else{ current = current.Previous; } } } }*/ } } } } }