예제 #1
0
/**
 * Prepare for a new turn.
 */
void BattleUnit::prepareNewTurn()
{
	// recover TUs
	int TURecovery = _unit->getTimeUnits();
	// Each fatal wound to the left or right leg reduces the soldier's TUs by 10%.
	TURecovery -= (TURecovery * (_fatalWounds[BODYPART_LEFTLEG]+_fatalWounds[BODYPART_RIGHTLEG] * 10))/100;
	setTimeUnits(TURecovery);

	// recover energy
	if (!isOut())
	{
		int ENRecovery = _unit->getTimeUnits() / 3;
		// Each fatal wound to the body reduces the soldier's energy recovery by 10%.
		ENRecovery -= (_energy * (_fatalWounds[BODYPART_TORSO] * 10))/100;
		_energy += ENRecovery;
		if (_energy > _unit->getStamina())
			_energy = _unit->getStamina();
	}

	// suffer from fatal wounds
	_health -= getFatalWounds();

	// suffer from fire
	if (_fire > 0)
	{
		_health -= RNG::generate(5, 10);
		_fire--;
	}

	if (_health < 0)
		_health = 0;

	// recover stun 1pt/turn
	if (_stunlevel > 0)
		stun(-1);

	if (!isOut())
	{
		int chance = 100 - (2 * getMorale());
		if (RNG::generate(1,100) <= chance)
		{
			int type = RNG::generate(0,100);
			_status = (type<=33?STATUS_BERSERK:STATUS_PANICKING); // 33% chance of berserk, panic can mean freeze or flee, but that is determined later
		}
		else
		{
			// succesfully avoided panic
			// increase bravery experience counter
			if (chance > 1)
				_expBravery++;
		}
	}

	_dontReselect = false;
}
예제 #2
0
/*
 * Get the unit's minimap sprite index. Used to display the unit on the minimap
 * @return the unit minimap index
 */
int BattleUnit::getMiniMapSpriteIndex () const
{
	int unitSpriteId;
	//minimap sprite index:
	// * 0-2   : Xcom soldier
	// * 3-5   : Civilian
	// * 6-8   : alien
	// * 9-11  : Dead unit
	// * 12-23 : Xcom HWP
	// * 24-35 : Alien big terror unit(cyberdisk, ...)
	if (isOut())
	{
		return 9;
	}
	switch (getFaction())
	{
	case FACTION_HOSTILE:
		unitSpriteId = 3;
		break;
	case FACTION_NEUTRAL:
		unitSpriteId = 6;
		break;
	default:
		unitSpriteId = 0;
	}
	return unitSpriteId;
}
예제 #3
0
파일: CQuxian.cpp 프로젝트: ZTOMarcy/GPS
bool CQuxian::isBeginIntoRange(){
	if (isIn() || isOut()){
		return true;
	}else{
		return false;
	}
}
예제 #4
0
char hardware_flashlightIsOn()
{
    if(isOut(LED_PIN) && !isHigh(LED_PIN)) 
        return 1;

    return 0;
}
예제 #5
0
/*
 * Get the unit's minimap sprite index. Used to display the unit on the minimap
 * @return the unit minimap index
 */
int BattleUnit::getMiniMapSpriteIndex () const
{
	//minimap sprite index:
	// * 0-2   : Xcom soldier
	// * 3-5   : Alien
	// * 6-8   : Civilian
	// * 9-11  : Item
	// * 12-23 : Xcom HWP
	// * 24-35 : Alien big terror unit(cyberdisk, ...)
	if (isOut())
	{
		return 9;
	}
	switch (getFaction())
	{
	case FACTION_HOSTILE:
		if (_armor->getSize() == 1)
			return 3;
		else
			return 24;
	case FACTION_NEUTRAL:
		return 6;
	default:
		if (_armor->getSize() == 1)
			return 0;
		else
			return 12;
	}
}
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();
setOut(LED_PIN);
	puts_P(PSTR( "Still Image Host Demo running.\r\n" ));

//	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	uint32_t count = 0;
	for (;;)
	{
		Camera_Task();
		USB_USBTask();
		if(count++ >= 1000)
		{
			count = 0;
			if(isOut(LED_PIN) && !isHigh(LED_PIN))
			{
				setHigh(LED_PIN);
			}
			else
			{
				setLow(LED_PIN);
			}
		}
	}
}
예제 #7
0
파일: board.cpp 프로젝트: opieproject/opie
bool Board::isWay(int pos, int dir, Square sq) {
    int p1 = move(pos, dir, 2);
    if (p1 == OUT)
        return (sq == out ? TRUE : FALSE);
    int p2, p3;
    if (dir == N || dir == S) {
        p2 = move(p1, E);
        p3 = move(p1, W);
    } else {
        p2 = move(p1, N);
        p3 = move(p1, S);
    }
    switch (sq) {
        case out    : return isOut(p1) | isOut(p2) | isOut(p3);
        case empty  : return isEmpty(p1) & isEmpty(p2) & isEmpty(p3);
        case brick  : return isBrick(p1) | isBrick(p2) | isBrick(p3);
        case prison : return isPrison(p1) | isPrison(p2) | isPrison(p3);
        case gate   : return isGate(p1) & isGate(p2) & isGate(p3);
        case tunnel : return isTunnel(p1) &
                             (isTunnel(p2) || isEmpty(p2)) &
                             (isTunnel(p3) || isEmpty(p3));
        default     : return FALSE;
    }
}
예제 #8
0
파일: 4.cpp 프로젝트: RosenX/Code
    long long fill(const Node &loc, vector< vector<int> > &H, int m, int n){
        int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
        long long sum = 0;
        bool flag[110][110];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                flag[i][j] = false;
            }
        }

        int minh = 20000;
        queue< pair<int, int> > que;
        vector< pair<int, int> > hasVisited;
        que.push(make_pair(loc.x, loc.y));
        flag[loc.x][loc.y] = true;
        hasVisited.push_back(make_pair(loc.x, loc.y));
        while(!que.empty()){
            pair<int, int> cur = que.front();
            que.pop();
            for(int i = 0; i < 4; i++){
                int x = cur.first + dir[i][0], y = cur.second + dir[i][1];
                if(isOut(x, y, m, n)){
                    minh = 0;
                    break;
                }
                if(flag[x][y]) continue;
                if(H[x][y] < H[loc.x][loc.y]){
                    minh = 0;
                    break;
                }else if(H[x][y] > H[loc.x][loc.y]){
                    minh = min(H[x][y], minh);
                }else{
                    flag[x][y] = true;
                    hasVisited.push_back(make_pair(x, y));
                    que.push(make_pair(x, y));
                }
            }
            if(minh == 0)break;
        }
        if(minh){
            for(auto t : hasVisited){
                sum += minh - H[t.first][t.second];
                H[t.first][t.second] = minh;
            }
        }
        return sum;
    }
예제 #9
0
bool AstarFlexible::checkNearby()
{
	int i=0,j=0,x=0,y=0,k=0,g=0,h=0;
	
	AstarNode* searchedNode;
	
	for(;k<DEFAULT_NEARS_LENGTH;k++){
		//near=defaultNears[k];
		i=defaultNears[k][0];
		j=defaultNears[k][1];
		
		x=m_current->getX()+i;
		y=m_current->getY()+j;
		
		//结束提前,可对目标是障碍物进行寻路。(例:人物要对某个建筑进行操作,比如攻击,要走到建筑旁边才可以)
		if (isEnd(x,y ,i ,j)) {//如果是斜着寻路,则要对旁边是否有障碍物进行判断。
			return true;//查找成功
		}
		
		if(!isOut(x,y) && isWorkableWithCrossSide(x ,y ,i ,j)){
			if(!isInClose(x ,y)){
				g=m_current->getG()+(i==0||j==0?ASTAR_G_LINE:ASTAR_G_CROSS);
				searchedNode=getFromOpen(x ,y);
				if(searchedNode!=NULL){
					//在开起列表中,比较G值
					if (g < searchedNode->getG()) {
						//有最小F值,重新排序
						setOpenSeqNode(searchedNode,g);
					}
				}else {
					//没有搜索过,直接添加到开起列表中
					h=getH(x ,y);
					AstarNode* astarNode=new AstarNode();
					astarNode->init(x ,y,g,h);
					astarNode->setParent(m_current);
					addToOpen(astarNode);
					astarNode->release();
				}
			}
		}
	}
	return false;
}
void smallestEnclosingSphere(SrPoint3D*	sp,int nsp,VertexList& vertexList,const VertexIterator& end,SrSphere3D& sphere)
{
	createSphere(sp, nsp,sphere);
	if( nsp==4 )
		return;
	VertexIterator iterator = vertexList.begin();
	for( ; end != iterator ; )
	{
		const SrPoint3D& p = *iterator;
		if( isOut(p,sphere) )
		{
			sp[ nsp ] = p;
			smallestEnclosingSphere( sp, nsp + 1 , vertexList , iterator , sphere);
			vertexList.splice(vertexList.begin(),vertexList,iterator++ );
		}
		else
		{
			iterator++;
		}
	}
}
예제 #11
0
bool AstarFlexible::search()
{
	
	//如果开始和结束点是同一点、终点超出范围,不必寻路。
	if (isEnd(m_start->getX(),m_start->getY())|| isOut(m_end->getX(),m_end->getY())){
		return false;
	}
	
	while (m_openSeq->count()) {
		//取得下一个搜索点 
		getNext();
		removeFromOpen(m_current);
		//添加到closes
		addToClose(m_current->getX(),m_current->getY());
		
		//处理相邻结点
		if(checkNearby()){
			return true;
		}
	}
	return false;
}
예제 #12
0
파일: CQuxian.cpp 프로젝트: ZTOMarcy/GPS
int CQuxian::run(){
	if (isStop()){
		SetMessage(_T("中途停车"));
		return 0;
	}
	if (!isInTestRange()){
		SetMessage(_T("出界"));
		return 0;
	}
	if (flag_in == false){
		if (isIn()){
			flag_in = true;
		}
	}
	if ((flag_in == true)&&(flag_out==false)){
		if (isOut()){
			flag_out = true;
			SetMessage(_T("结束"));
			return 0;
		}
	}
	return 1;
}
예제 #13
0
/**
 * Initializes the sequence.
 * does a lot of validity checking.
 */
void MeleeAttackBState::init()
{
	if (_initialized) return;
	_initialized = true;

	_weapon = _action.weapon;
	if (!_weapon) // can't hit without weapon
	{
		_parent->popState();
		return;
	}

	_unit = _action.actor;

	bool reactionShoot = _unit->getFaction() != _parent->getSave()->getSide();
	_ammo = _action.weapon->getAmmoForAction(BA_HIT, reactionShoot ? nullptr : &_action.result);
	if (!_ammo)
	{
		_parent->popState();
		return;
	}

	if (!_parent->getSave()->getTile(_action.target)) // invalid target position
	{
		_parent->popState();
		return;
	}

	if (_unit->isOut() || _unit->isOutThresholdExceed())
	{
		// something went wrong - we can't shoot when dead or unconscious, or if we're about to fall over.
		_parent->popState();
		return;
	}

	// reaction fire
	if (reactionShoot)
	{
		// no ammo or target is dead: give the time units back and cancel the shot.
		auto target = _parent->getSave()->getTile(_action.target)->getUnit();
		if (!target || target->isOut() || target->isOutThresholdExceed() || target != _parent->getSave()->getSelectedUnit())
		{
			_parent->popState();
			return;
		}
		_unit->lookAt(_action.target, _unit->getTurretType() != -1);
		while (_unit->getStatus() == STATUS_TURNING)
		{
			_unit->turn();
		}
	}

	//spend TU
	if (!_action.spendTU(&_action.result))
	{
		_parent->popState();
		return;
	}


	AIModule *ai = _unit->getAIModule();

	if (_unit->getFaction() == _parent->getSave()->getSide() &&
		_unit->getFaction() != FACTION_PLAYER &&
		_parent->_debugPlay == false &&
		ai && ai->getTarget())
	{
		_target = ai->getTarget();
	}
	else
	{
		_target = _parent->getSave()->getTile(_action.target)->getUnit();
	}

	int height = _target->getFloatHeight() + (_target->getHeight() / 2) - _parent->getSave()->getTile(_action.target)->getTerrainLevel();
	_voxel = _action.target.toVexel() + Position(8, 8, height);

	if (_unit->getFaction() == FACTION_HOSTILE)
	{
		_hitNumber = _weapon->getRules()->getAIMeleeHitCount() - 1;
	}

	performMeleeAttack();
}
예제 #14
0
int sci_call(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out)
{
    std::vector<Parameter> params(30);
    std::vector<int> output_order(nout);
    wchar_t* interf = NULL;
    if (nin < 1)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), fname, 1);
        return 1;
    }

    //1st is the interface name
    if (scilab_isString(env, in[0]) == 0 || scilab_isScalar(env, in[0]) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
        return 1;
    }

    scilab_getString(env, in[0], &interf);

    ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(interf);
    if (func == NULL)
    {
        Scierror(999, _("%s: unable to find entry point %ls.\n"), fname, interf);
        return 1;
    }

    int pos = 1;
    bool hasOutputs = true;
    //inputs
    while (1)
    {
        //check "out" to break loop
        if (isOut(env, in[pos]))
        {
            hasOutputs = true;
            break;
        }

        if (pos > nin)
        {
            break;
        }

        int type = 0;
        if (nin < pos + 2)
        {
            Scierror(77, _("%s: Wrong number of input argument(s).\n"), fname);
            return 1;
        }

        type = scilab_getType(env, in[pos]);
        if (type != sci_matrix && type != sci_strings)
        {
            Scierror(77, _("%s: Wrong type for input argument #%d: A real matrix or a string expected.\n"), fname, pos + 1);
            return 1;
        }

        //data

        //position
        if (scilab_isDouble(env, in[pos + 1]) == 0 || scilab_isScalar(env, in[pos + 1]) == 0)
        {
            Scierror(77, _("%s: Wrong type for input argument #%d : A real scalar expected.\n"), fname, pos + 2);
            return 1;
        }

        double param_pos = 0;
        scilab_getDouble(env, in[pos + 1], &param_pos);

        //type
        if (scilab_isString(env, in[pos + 2]) == 0 || scilab_isScalar(env, in[pos + 2]) == 0)
        {
            Scierror(77, _("%s: Wrong type for input argument #%d : string expected.\n"), fname, pos + 3);
            return 1;
        }

        void* data = NULL;
        int row = 0;
        int col = 0;

        wchar_t* param_type = NULL;
        scilab_getString(env, in[pos + 2], &param_type);

        if (param_type[0] == L'c' || type == sci_strings)
        {
            if (param_type[0] != L'c' || type != sci_strings)
            {
                Scierror(77, _("%s: Wrong type for input argument #%d : string expected.\n"), fname, pos + 1);
                return 1;
            }
        }

        bool alloc = false;
        switch (param_type[0])
        {
            case L'c':
            {
                wchar_t* strs = NULL;
                scilab_getString(env, in[pos], &strs);
                char* c = wide_string_to_UTF8(strs);
                data = c;
                alloc = true;
                break;
            }
            case L'd':
            {
                double* dbls = NULL;
                scilab_getDoubleArray(env, in[pos], &dbls);
                data = dbls;
                break;
            }
            case L'r':
            {
                double* dbls = NULL;
                int size = scilab_getSize(env, in[pos]);
                scilab_getDoubleArray(env, in[pos], &dbls);
                float* f = (float*)malloc(size * sizeof(float));
                for (int i = 0; i < size; ++i)
                {
                    f[i] = (float)dbls[i];
                }

                data = f;
                alloc = true;
                break;
            }
            case L'i':
            {
                double* dbls = NULL;
                int size = scilab_getSize(env, in[pos]);
                scilab_getDoubleArray(env, in[pos], &dbls);
                int* ints = (int*)malloc(size * sizeof(int));
                for (int i = 0; i < size; ++i)
                {
                    ints[i] = (int)dbls[i];
                }

                data = ints;
                alloc = true;
                break;
            }
            default:
            {
                Scierror(77, _("%s: Wrong value for input argument #%d: '%s', '%s', '%s' or '%s' expected.\n"), fname, pos + 3, "d", "r", "i", "c");
                return 1;
            }
        }

        scilab_getDim2d(env, in[pos], &row, &col);

        Parameter& p = params[(int)param_pos - 1];
        p.alloc = alloc;
        p.data = data;
        p.row = row;
        p.col = col;
        p.type = param_type[0];

        pos += 3;
    }

    int output_pos = 0;
    //outputs
    if (hasOutputs)
    {
        ++pos; //avoid "out"
        while (1)
        {
            //check if is 3 or 1 arg ...
            if (scilab_isDouble(env, in[pos]) == 0)
            {
                Scierror(77, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), fname, pos + 1);
                return 1;
            }

            if (scilab_isScalar(env, in[pos]))
            {
                double dorder = 0;
                scilab_getDouble(env, in[pos], &dorder);
                int order = (int)dorder;
                if (params[order - 1].data == nullptr)
                {
                    Scierror(77, _("%s: Wrong value for input argument #%d.\n"), fname, pos + 1);
                    return 1;
                }

                pos += 1;
                output_order[output_pos] = order - 1;
            }
            else
            {
                //dims
                double* dims = 0;
                scilab_getDoubleArray(env, in[pos], &dims);
                int size = (int)dims[0] * (int)dims[1];

                //pos
                if (scilab_isDouble(env, in[pos + 1]) == 0 || scilab_isScalar(env, in[pos + 1]) == 0)
                {
                    Scierror(77, _("%s: Wrong type for input argument #%d : A real scalar expected.\n"), fname, pos + 2);
                    return 1;
                }

                double param_pos = 0;
                scilab_getDouble(env, in[pos + 1], &param_pos);

                //type
                if (scilab_isString(env, in[pos + 2]) == 0 || scilab_isScalar(env, in[pos + 2]) == 0)
                {
                    Scierror(77, _("%s: Wrong type for input argument #%d : string expected.\n"), fname, pos + 3);
                    return 1;
                }

                wchar_t* param_type = NULL;
                scilab_getString(env, in[pos + 2], &param_type);

                void* data = NULL;

                switch (param_type[0])
                {
                    case L'c':
                    {
                        data = malloc((size + 1) * sizeof(char));
                        break;
                    }
                    case L'd':
                    {
                        data = malloc(size * sizeof(double));
                        break;
                    }
                    case L'r':
                    {
                        data = malloc(size * sizeof(float));
                        break;
                    }
                    case L'i':
                    {
                        data = malloc(size * sizeof(int));
                        break;
                    }
                }
                Parameter& p = params[(int)param_pos - 1];
                p.row = (int)dims[0];
                p.col = (int)dims[1];
                p.alloc = true;
                p.type = param_type[0];
                p.data = data;
                pos += 3;
                output_order[output_pos] = (int)param_pos - 1;
            }

            ++output_pos;

            if (pos + 1 > nin)
            {
                break;
            }
        }

    }
    //the unbelievable call !
    ((fct)func->functionPtr)(params[0].data, params[1].data, params[2].data, params[3].data, params[4].data, params[5].data, params[6].data, params[7].data, params[8].data, params[9].data,
                             params[10].data, params[11].data, params[12].data, params[13].data, params[14].data, params[15].data, params[16].data, params[17].data, params[18].data, params[19].data,
                             params[20].data, params[21].data, params[22].data, params[23].data, params[24].data, params[25].data, params[26].data, params[27].data, params[28].data, params[29].data);

    //create output variables
    for (int i = 0; i < nout; ++i)
    {
        Parameter& p = params[output_order[i]];

        switch (p.type)
        {
            case L'c':
            {
                wchar_t* w = to_wide_string((char*)p.data);
                scilabVar var = scilab_createString(env, w);
                out[i] = var;
                FREE(w);
                break;
            }
            case L'd':
            {
                scilabVar var = scilab_createDoubleMatrix2d(env, p.row, p.col, 0);
                scilab_setDoubleArray(env, var, (double*)p.data);
                out[i] = var;
                break;
            }
            case L'r':
            {
                double* d = NULL;
                scilabVar var = scilab_createDoubleMatrix2d(env, p.row, p.col, 0);
                scilab_getDoubleArray(env, var, &d);
                int size = p.row * p.col;
                for (int j = 0; j < size; ++j)
                {
                    d[j] = (double)((float*)p.data)[j];
                }

                out[i] = var;
                break;
            }
            case L'i':
            {
                double* d = NULL;
                scilabVar var = scilab_createDoubleMatrix2d(env, p.row, p.col, 0);
                scilab_getDoubleArray(env, var, &d);
                int size = p.row * p.col;
                for (int j = 0; j < size; ++j)
                {
                    d[j] = (double)((int*)p.data)[j];
                }

                out[i] = var;
                break;
            }
        }
    }
    return STATUS_OK;
}