Example #1
0
func (self *disband) Options(v dip.Validator, nation dip.Nation, src dip.Province) (result dip.Options) {
	if v.Phase().Type() == cla.Adjustment {
		if v.Graph().Has(src) {
			if unit, actualSrc, ok := v.Unit(src); ok {
				if unit.Nation == nation {
					if _, _, balance := cla.AdjustmentStatus(v, unit.Nation); balance < 0 {
						result = dip.Options{
							dip.SrcProvince(actualSrc): nil,
						}
					}
				}
			}
		}
	} else if v.Phase().Type() == cla.Retreat {
		if v.Graph().Has(src) {
			if unit, actualSrc, ok := v.Dislodged(src); ok {
				if unit.Nation == nation {
					result = dip.Options{
						dip.SrcProvince(actualSrc): nil,
					}
				}
			}
		}
	}
	return
}
Example #2
0
File: move.go Project: arlm/godip
func (self *move) Options(v dip.Validator, nation dip.Nation, src dip.Province) (result dip.Options) {
	if v.Phase().Type() == cla.Retreat {
		if !self.flags[cla.ViaConvoy] {
			if v.Graph().Has(src) {
				if unit, actualSrc, ok := v.Dislodged(src); ok {
					if unit.Nation == nation {
						for _, dst := range cla.PossibleMoves(v, src, false, true) {
							if _, _, foundUnit := v.Unit(dst); !foundUnit {
								if !v.Bounce(src, dst) {
									if result == nil {
										result = dip.Options{}
									}
									if result[dip.SrcProvince(actualSrc)] == nil {
										result[dip.SrcProvince(actualSrc)] = dip.Options{}
									}
									result[dip.SrcProvince(actualSrc)][dst] = nil
								}
							}
						}
					}
				}
			}
		}
	} else if v.Phase().Type() == cla.Movement {
		if v.Graph().Has(src) {
			if unit, actualSrc, ok := v.Unit(src); ok {
				if unit.Nation == nation {
					if !self.flags[cla.ViaConvoy] || unit.Type == cla.Army {
						for _, dst := range cla.PossibleMoves(v, src, true, false) {
							if !self.flags[cla.ViaConvoy] {
								if result == nil {
									result = dip.Options{}
								}
								if result[dip.SrcProvince(actualSrc)] == nil {
									result[dip.SrcProvince(actualSrc)] = dip.Options{}
								}
								result[dip.SrcProvince(actualSrc)][dst] = nil
							} else {
								if cp := cla.AnyConvoyPath(v, src, dst, false, nil); len(cp) > 1 {
									if result == nil {
										result = dip.Options{}
									}
									if result[dip.SrcProvince(actualSrc)] == nil {
										result[dip.SrcProvince(actualSrc)] = dip.Options{}
									}
									result[dip.SrcProvince(actualSrc)][dst] = nil
								}
							}
						}
					}
				}
			}
		}
	}
	return
}
Example #3
0
File: hold.go Project: arlm/godip
func (self *hold) Options(v dip.Validator, nation dip.Nation, src dip.Province) (result dip.Options) {
	if v.Phase().Type() == cla.Movement {
		if v.Graph().Has(src) {
			if unit, actualSrc, ok := v.Unit(src); ok {
				if unit.Nation == nation {
					result = dip.Options{
						dip.SrcProvince(actualSrc): nil,
					}
				}
			}
		}
	}
	return
}