Is there a logic error in lines 66-94 in unit.cpp?