コード例 #1
0
ファイル: ObjectFactory.cpp プロジェクト: AsherBond/sirikata
Object* ObjectFactory::object(const UUID& id) {
    assert( mObjectIDs.find(id) != mObjectIDs.end() );

    ObjectMap::iterator it = mObjects.find(id);
    if (it != mObjects.end()) return it->second;

    Object* new_obj = new Object(this, id, motion(id), bounds(id), registerQuery(id), queryAngle(id), mContext);
    mObjects[id] = new_obj;
    return new_obj;
}
コード例 #2
0
ファイル: droprules.c プロジェクト: thunderk/stormwar
/*----------------------------------------------------------------------------*/
Bool
DropRules_check(DropRules rules, WorldCoord posx, WorldCoord posy)
{
    RegisterResult* regi;
    RegisterResult* reg_pres;
    
    /*check if it can be registered*/
    if (registerIsOutbound(posx, posy))
    {
        return FALSE;
    }
    
    /*check denyground*/
    if (rules->denyground)
    {
        if (groundGetState(posx, posy))
        {
            return FALSE;
        }
    }
    
    reg_pres = registerQuery(posx, posy, NULL, NULL, REGISTER_PRESENCE);
    
    /*check needground*/
    if (rules->needground)
    {
        if (!groundGetState(posx, posy))
        {
            /*there is no ground under*/
            /*check if there is an entity that can play the role of ground*/
            if (!matchOne(rules->ground_entities, reg_pres))
            {
                FREE(reg_pres);
                return FALSE;
            }
        }
    }
    
    /*check allowed entities*/
    regi = reg_pres;
    while (regi->piece != NULL)
    {
        if (!searchEntityList(rules->allowed_entities, Piece_getEntity(regi->piece)))
        {
            /*an unallowed entity was found*/
            FREE(reg_pres);
            return FALSE;
        }
        regi++;
    }
    
    /*check ground connexity*/
    if (rules->groundconnexity)
    {
        Bool pass = FALSE;
        
        if (!registerIsOutbound(posx - 1, posy))
        {
            if (groundGetState(posx - 1, posy))
            {
                pass = TRUE;
            }
            else
            {
                RegisterResult* r;
                
                r = registerQuery(posx - 1, posy, NULL, NULL, REGISTER_PRESENCE);
                if (matchOne(rules->ground_entities, r))
                {
                    pass = TRUE;
                }
                FREE(r);
            }
        }
        if ((!pass) && (!registerIsOutbound(posx + 1, posy)))
        {
            if (groundGetState(posx + 1, posy))
            {
                pass = TRUE;
            }
            else
            {
                RegisterResult* r;
                
                r = registerQuery(posx + 1, posy, NULL, NULL, REGISTER_PRESENCE);
                if (matchOne(rules->ground_entities, r))
                {
                    pass = TRUE;
                }
                FREE(r);
            }
        }
        if ((!pass) && (!registerIsOutbound(posx, posy - 1)))
        {
            if (groundGetState(posx, posy - 1))
            {
                pass = TRUE;
            }
            else
            {
                RegisterResult* r;
                
                r = registerQuery(posx, posy - 1, NULL, NULL, REGISTER_PRESENCE);
                if (matchOne(rules->ground_entities, r))
                {
                    pass = TRUE;
                }
                FREE(r);
            }
        }
        if ((!pass) && (!registerIsOutbound(posx, posy + 1)))
        {
            if (groundGetState(posx, posy + 1))
            {
                pass = TRUE;
            }
            else
            {
                RegisterResult* r;
                
                r = registerQuery(posx, posy + 1, NULL, NULL, REGISTER_PRESENCE);
                if (matchOne(rules->ground_entities, r))
                {
                    pass = TRUE;
                }
                FREE(r);
            }
        }
        
        if (!pass)
        {
            FREE(reg_pres);
            return FALSE;
        }
    }
    
    /*all checks passed*/
    FREE(reg_pres);
    return TRUE;
}