public void AddFormation(SizeType sizeType, PositionType positionType, MZFormation formation) { if( _formationsBySizeDictionary == null ) _formationsBySizeDictionary = new Dictionary<SizeType, Dictionary<PositionType, List<MZFormation>>>(); if( _formationsBySizeDictionary.ContainsKey( sizeType ) == false ) { Dictionary<PositionType, List<MZFormation>> newDic = new Dictionary<PositionType, List<MZFormation>>(); _formationsBySizeDictionary.Add( sizeType, newDic ); } if( _formationsBySizeDictionary[ sizeType ].ContainsKey( positionType ) == false ) { List<MZFormation> newList = new List<MZFormation>(); _formationsBySizeDictionary[ sizeType ].Add( positionType, newList ); } formation.sizeType = sizeType; formation.positionType = positionType; _formationsBySizeDictionary[ sizeType ][ positionType ].Add( formation ); }
public MZTestFormationSetting(MZFormation formation) { MZDebug.Assert( formation != null, "formation is null" ); constructCode = formation.constructCode; name = formation.GetType().ToString(); sizeType = formation.sizeType; positionType = formation.positionType; }
MZFormation GetFormationByDecision(SizeType sizeType) { MZDebug.Assert( _formationsBySizeDictionary != null, "_formationsBySizeDictionary is null" ); MZDebug.Assert( _formationsBySizeDictionary.ContainsKey( sizeType ), "not contain size=" + sizeType.ToString() ); bool isPosAny = ( MZMath.RandomFromRange( 0, 4 ) == 0 ); Dictionary<PositionType, List<MZFormation>> listByPos = _formationsBySizeDictionary[ sizeType ]; PositionType choicePosType = PositionType.Unknow; if( isPosAny && listByPos.ContainsKey( PositionType.Any ) ) { choicePosType = PositionType.Any; } else { int selectCount = 0; while(selectCount < _currentPositionTypeOrder.Count) { PositionType tryToChoicePosType = GetNextPositionType(); if( listByPos.ContainsKey( tryToChoicePosType ) == true ) { choicePosType = tryToChoicePosType; break; } selectCount++; } if( choicePosType == PositionType.Unknow ) choicePosType = ( listByPos.ContainsKey( PositionType.Any ) )? PositionType.Any : PositionType.Unknow; } return ( choicePosType != PositionType.Unknow )? GetRandomInFormationList( listByPos[ choicePosType ] ) : null; }
public void ExecuteFormation(PositionType posType, SizeType sizeType, int constructCode, string name) { List<MZFormation> list = _formationsBySizeDictionary[ sizeType ][ posType ]; foreach( MZFormation f in list ) { if( f.GetType().ToString() == name && posType == f.positionType && f.constructCode == constructCode ) { ExecuteFormation( f ); break; } } }