예제 #1
0
//--------------------------- Render -------------------------------------
//
//------------------------------------------------------------------------
void Raven_Bot::Render()                                         
{
  //when a bot is hit by a projectile this value is set to a constant user
  //defined value which dictates how long the bot should have a thick red
  //circle drawn around it (to indicate it's been hit) The circle is drawn
  //as long as this value is positive. (see Render)
  m_iNumUpdatesHitPersistant--;


  if (isDead() || isSpawning()) return;
  
  gdi->BluePen();
  
  m_vecBotVBTrans = WorldTransform(m_vecBotVB,
                                   Pos(),
                                   Facing(),
                                   Facing().Perp(),
                                   Scale());

  gdi->ClosedShape(m_vecBotVBTrans);
  
  //draw the head
  (gdi->*(m_pTeam->GetPen()))();
  gdi->Circle(Pos(), 6.0 * Scale().x);


  //render the bot's weapon
  m_pWeaponSys->RenderCurrentWeapon();

  //render a thick red circle if the bot gets hit by a weapon
  if (m_bHit)
  {
    gdi->ThickRedPen();
    gdi->HollowBrush();
    gdi->Circle(m_vPosition, BRadius()+1);

    if (m_iNumUpdatesHitPersistant <= 0)
    {
      m_bHit = false;
    }
  }

  gdi->TransparentText();
  gdi->TextColor(0,255,0);

  if (UserOptions->m_bShowBotIDs)
  {
    gdi->TextAtPos(Pos().x -10, Pos().y-20, ttos(ID()));
  }

  if (UserOptions->m_bShowBotHealth)
  {
    gdi->TextAtPos(Pos().x-40, Pos().y-5, "H:"+ ttos(Health()));
  }

  if (UserOptions->m_bShowScore)
  {
    gdi->TextAtPos(Pos().x-40, Pos().y+10, "Scr:"+ ttos(Score()));
  }    
}
예제 #2
0
bool Raven_Bot::canStepBackward(Vector2D& PositionOfStep)const
{
  static const double StepDistance = BRadius() * 2;

  PositionOfStep = Pos() - Facing() * StepDistance - Facing() * BRadius();

  return canWalkTo(PositionOfStep);
}
예제 #3
0
bool Raven_Bot::canStepRight(Vector2D& PositionOfStep)const
{
  static const double StepDistance = BRadius() * 2;

  PositionOfStep = Pos() + Facing().Perp() * StepDistance + Facing().Perp() * BRadius();

  return canWalkTo(PositionOfStep);
}
예제 #4
0
void ParticleHandler::spawnPoof(const std::shared_ptr<Object> &object)
{
    Facing facing_z = object->ori.facing_z;
    for (int cnt = 0; cnt < object->getProfile()->getParticlePoofAmount(); cnt++)
    {
        ParticleHandler::get().spawnParticle(object->getOldPosition(), facing_z, object->getProfile()->getSlotNumber(), object->getProfile()->getParticlePoofProfile(),
                                             ObjectRef::Invalid, GRIP_LAST, object->team, object->ai.owner, ParticleRef::Invalid, cnt);

        facing_z += Facing(object->getProfile()->getParticlePoofFacingAdd());
    }
}
예제 #5
0
void NLight::GenerateShadowBuffers()
{
    //oh boy why didn't i comment this while i coded it; it's pretty damn complicated. I'll try my best to reinterpret and explain what i was thinking.
    if (!Texture)
    {
        return;
    }
    //Compares it's current position and scale from memory, if it hasn't changed from last generation then don't regenerate it!
    if (PositionMemory == GetRealPos() && ScaleMemory == GetScale())
    {
        return;
    }
    glm::vec3 Pos = GetRealPos();
    Shadows.clear();
    //Figures out what size of a box of map tiles we should loop through. FIXME: Make it more accurately decide which map tiles to loop through.
    float Max = std::max(GetScale().x, GetScale().y);
    //For every map tile in a massive area around the light...
    for (float x = -Max;x<Max;x+=GetGame()->GetMap()->GetTileSize())
    {
        for (float y = -Max;y<Max;y+=GetGame()->GetMap()->GetTileSize())
        {
            //Get the tile object at the current loop position
            NTile* Tile = GetGame()->GetMap()->GetTile(Pos+glm::vec3(x,y,0));
            //If the tile doesn't block light or doesn't exist, skip it!
            if (Tile == NULL || !Tile->IsOpaque())
            {
                continue;
            }
            float TS = GetGame()->GetMap()->GetTileSize()/2.f;
            //Generate points in the four corners of the tile.
            glm::vec3 TPos = GetGame()->GetMap()->TilePos(Pos+glm::vec3(x,y,0));
            glm::vec3 Points[4];
            Points[0] = TPos+glm::vec3(TS,TS,0);
            Points[1] = TPos+glm::vec3(TS,-TS,0);
            Points[2] = TPos+glm::vec3(-TS,-TS,0);
            Points[3] = TPos+glm::vec3(-TS,TS,0);
            std::vector<glm::vec4> Faces;
            //Generate faces (two points = face, each tile has 4 faces)
            NTile* CheckTile = GetGame()->GetMap()->GetTile(Tile->X,Tile->Y-1,Tile->Z);
            if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
            {
                Faces.push_back(glm::vec4(Points[1].x,Points[1].y,Points[2].x,Points[2].y));
            }
            CheckTile = GetGame()->GetMap()->GetTile(Tile->X,Tile->Y+1,Tile->Z);
            if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
            {
                Faces.push_back(glm::vec4(Points[3].x,Points[3].y,Points[0].x,Points[0].y));
            }
            CheckTile = GetGame()->GetMap()->GetTile(Tile->X-1,Tile->Y,Tile->Z);
            if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
            {
                Faces.push_back(glm::vec4(Points[2].x,Points[2].y,Points[3].x,Points[3].y));
            }
            CheckTile = GetGame()->GetMap()->GetTile(Tile->X+1,Tile->Y,Tile->Z);
            if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
            {
                Faces.push_back(glm::vec4(Points[0].x,Points[0].y,Points[1].x,Points[1].y));
            }
            for (unsigned int i=0;i<Faces.size();i++)
            {
                //Remove front faces
                if (!Facing(glm::vec2(Pos.x,Pos.y),Faces[i]))
                {
                    continue;
                }
                //Generate shadow mesh by extruding back faces.
                float Radians = -atan2(Pos.x-Faces[i].x,Pos.y-Faces[i].y)-PI/2.f;
                float BRadians = -atan2(Pos.x-Faces[i].z,Pos.y-Faces[i].w)-PI/2.f;
                Shadows.push_back(glm::vec3(Faces[i].x,Faces[i].y,TPos.z));
                Shadows.push_back(glm::vec3(Faces[i].z,Faces[i].w,TPos.z));
                Shadows.push_back(glm::vec3(Faces[i].z+cos(BRadians)*GetScale().x,Faces[i].w+sin(BRadians)*GetScale().y,TPos.z));
                Shadows.push_back(glm::vec3(Faces[i].x+cos(Radians)*GetScale().x,Faces[i].y+sin(Radians)*GetScale().y,TPos.z));
            }
        }
    }

    //3d lighting time, honestly the 2d doesn't work when there's any openings between floors.
    /*for (float x = -Max;x<Max;x+=GetGame()->GetMap()->GetTileSize())
    {
        for (float y = -Max;y<Max;y+=GetGame()->GetMap()->GetTileSize())
        {
            for (float z = -Max;z<Max;z+=GetGame()->GetMap()->GetTileSize())
            {
                //Get the tile object at the current loop position
                NTile* Tile = GetGame()->GetMap()->GetTile(Pos+glm::vec3(x,y,z));
                //If the tile doesn't block light or doesn't exist, skip it!
                if (Tile == NULL || !Tile->IsOpaque())
                {
                    continue;
                }
                float TS = GetGame()->GetMap()->GetTileSize()/2.f;
                //Generate points in the eight verts of the tile.
                glm::vec3 TPos = GetGame()->GetMap()->TilePos(Pos+glm::vec3(x,y,z));
                glm::vec3 Points[8];
                Points[0] = TPos+glm::vec3(TS,TS,0);
                Points[1] = TPos+glm::vec3(TS,-TS,0);
                Points[2] = TPos+glm::vec3(-TS,-TS,0);
                Points[3] = TPos+glm::vec3(-TS,TS,0);
                Points[4] = TPos+glm::vec3(TS,TS,TS*2.f);
                Points[5] = TPos+glm::vec3(TS,-TS,TS*2.f);
                Points[6] = TPos+glm::vec3(-TS,-TS,TS*2.f);
                Points[7] = TPos+glm::vec3(-TS,TS,TS*2.f);
                std::vector< std::vector<glm::vec3> > Faces;
                //Generate faces (four points = face, each tile has 6 faces)
                NTile* CheckTile = GetGame()->GetMap()->GetTile(Tile->X,Tile->Y-1,Tile->Z);
                if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
                {
                    //Faces.push_back(glm::vec4(Points[1].x,Points[1].y,Points[2].x,Points[2].y));
                    std::vector<glm::vec3> Face;
                    Face.push_back(Points[1]);
                    Face.push_back(Points[2]);
                    Face.push_back(Points[6]);
                    Face.push_back(Points[5]);
                    Faces.push_back(Face);
                }
                CheckTile = GetGame()->GetMap()->GetTile(Tile->X,Tile->Y+1,Tile->Z);
                if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
                {
                    //Faces.push_back(glm::vec4(Points[3].x,Points[3].y,Points[0].x,Points[0].y));
                    std::vector<glm::vec3> Face;
                    Face.push_back(Points[3]);
                    Face.push_back(Points[0]);
                    Face.push_back(Points[4]);
                    Face.push_back(Points[7]);
                    Faces.push_back(Face);
                }
                CheckTile = GetGame()->GetMap()->GetTile(Tile->X-1,Tile->Y,Tile->Z);
                if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
                {
                    //Faces.push_back(glm::vec4(Points[2].x,Points[2].y,Points[3].x,Points[3].y));
                    std::vector<glm::vec3> Face;
                    Face.push_back(Points[2]);
                    Face.push_back(Points[3]);
                    Face.push_back(Points[7]);
                    Face.push_back(Points[6]);
                    Faces.push_back(Face);
                }
                CheckTile = GetGame()->GetMap()->GetTile(Tile->X+1,Tile->Y,Tile->Z);
                if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
                {
                    //Faces.push_back(glm::vec4(Points[0].x,Points[0].y,Points[1].x,Points[1].y));
                    std::vector<glm::vec3> Face;
                    Face.push_back(Points[0]);
                    Face.push_back(Points[1]);
                    Face.push_back(Points[5]);
                    Face.push_back(Points[4]);
                    Faces.push_back(Face);
                }
                CheckTile = GetGame()->GetMap()->GetTile(Tile->X,Tile->Y,Tile->Z-1);
                if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
                {
                    std::vector<glm::vec3> Face;
                    Face.push_back(Points[0]);
                    Face.push_back(Points[1]);
                    Face.push_back(Points[3]);
                    Face.push_back(Points[2]);
                    Faces.push_back(Face);
                }
                CheckTile = GetGame()->GetMap()->GetTile(Tile->X,Tile->Y,Tile->Z+1);
                if ((CheckTile && !CheckTile->IsOpaque()) || !CheckTile)
                {
                    std::vector<glm::vec3> Face;
                    Face.push_back(Points[4]);
                    Face.push_back(Points[5]);
                    Face.push_back(Points[7]);
                    Face.push_back(Points[6]);
                    Faces.push_back(Face);
                }
                for (unsigned int i=0;i<Faces.size();i++)
                {
                    //Remove front faces
                    if (Facing(glm::vec3(Pos.x,Pos.y,Pos.z),Faces[i]))
                    {
                        continue;
                    }
                    //Generate shadow mesh by extruding back faces.
                    //float Radians = -atan2(Pos.x-Faces[i].x,Pos.y-Faces[i].y)-PI/2.f;
                    //float BRadians = -atan2(Pos.x-Faces[i].z,Pos.y-Faces[i].w)-PI/2.f;
                    glm::vec3 ExtrudeA = glm::normalize(Faces[i][0]-Pos);
                    glm::vec3 ExtrudeB = glm::normalize(Faces[i][1]-Pos);
                    Shadows.push_back(Faces[i][0]);
                    Shadows.push_back(Faces[i][1]);
                    Shadows.push_back(Faces[i][0]+ExtrudeA*GetScale()); //these go very far away so shadows are long
                    Shadows.push_back(Faces[i][1]+ExtrudeB*GetScale());

                    glm::vec3 ExtrudeA = glm::normalize(Faces[i][1]-Pos);
                    glm::vec3 ExtrudeB = glm::normalize(Faces[i][2]-Pos);
                    Shadows.push_back(Faces[i][1]);
                    Shadows.push_back(Faces[i][2]);
                    Shadows.push_back(Faces[i][1]+ExtrudeA*GetScale());
                    Shadows.push_back(Faces[i][2]+ExtrudeB*GetScale());

                    ExtrudeA = glm::normalize(Faces[i][2]-Pos);
                    ExtrudeB = glm::normalize(Faces[i][3]-Pos);
                    Shadows.push_back(Faces[i][2]);
                    Shadows.push_back(Faces[i][3]);
                    Shadows.push_back(Faces[i][2]+ExtrudeA*GetScale());
                    Shadows.push_back(Faces[i][3]+ExtrudeB*GetScale());

                    ExtrudeA = glm::normalize(Faces[i][3]-Pos);
                    ExtrudeB = glm::normalize(Faces[i][0]-Pos);
                    Shadows.push_back(Faces[i][3]);
                    Shadows.push_back(Faces[i][0]);
                    Shadows.push_back(Faces[i][3]+ExtrudeA*GetScale());
                    Shadows.push_back(Faces[i][0]+ExtrudeB*GetScale());
                }
            }
        }
    }*/

    glBindBuffer(GL_ARRAY_BUFFER,Buffers[2]);
    glBufferData(GL_ARRAY_BUFFER,Shadows.size()*sizeof(glm::vec3),&Shadows[0],GL_STATIC_DRAW);
    PositionMemory = GetRealPos();
    ScaleMemory = GetScale();
}
예제 #6
0
bool spawn_file_read(ReadContext& ctxt, spawn_file_info_t& info)
{
    info = spawn_file_info_t();

    // Until we hit something else than newlines, whitespaces or comments.
    while (true)
    {
        ctxt.skipWhiteSpaces();
        ctxt.skipNewLines();
        if (ctxt.is('/'))
        {
            ctxt.readSingleLineComment(); /// @todo Add and use ReadContext::skipSingleLineComment().
            continue;
        }
        if (!ctxt.isWhiteSpace() && !ctxt.isNewLine() && !ctxt.is('/'))
        {
            break;
        }
    }
    if (ctxt.isAlpha()||ctxt.is('%')||ctxt.is('_'))
    {
        ctxt._buffer.clear();
        // Read everything into the buffer until a ':', a new line, an error or the end of the input is reached.
        do
        {
            ctxt.saveAndNext();
        } while (!ctxt.is(':') && !ctxt.isNewLine() && !ctxt.is(ReadContext::Traits::endOfInput()) &&
                 !ctxt.is(ReadContext::Traits::error()));
        if (ctxt.is(ReadContext::Traits::error()))
        {
            throw Id::LexicalErrorException(__FILE__, __LINE__, Ego::Script::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                            "read error");
        }
        if (ctxt.is(ReadContext::Traits::endOfInput()))
        {
            return false;
        }
        if (!ctxt.is(':'))
        {
            throw Id::LexicalErrorException(__FILE__, __LINE__, Ego::Script::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                            "expected `:`");
        }
        ctxt.next();

        info.spawn_comment = Ego::trim_ws(ctxt._buffer.toString());      
       
        info.do_spawn = true;

        vfs_read_string_lit(ctxt, info.spawn_name);

        info.pname = &(info.spawn_name);
        if (info.spawn_name == "NONE")
        {
            // A random name is selected.
            info.pname = nullptr;
        }

        info.slot = ctxt.readIntegerLiteral();

        info.pos[kX] = ctxt.readRealLiteral() * Info<float>::Grid::Size();
        info.pos[kY] = ctxt.readRealLiteral() * Info<float>::Grid::Size();
        info.pos[kZ] = ctxt.readRealLiteral() * Info<float>::Grid::Size();

        info.facing = Facing::FACE_NORTH;
        info.attach = ATTACH_NONE;
        char chr = ctxt.readPrintable();
        switch (Ego::toupper(chr))
        {
            case 'S': info.facing = Facing::FACE_SOUTH;       break;
            case 'E': info.facing = Facing::FACE_EAST;        break;
            case 'W': info.facing = Facing::FACE_WEST;        break;
            case 'N': info.facing = Facing::FACE_NORTH;       break;
            case '?': info.facing = Facing(FACE_RANDOM);      break;
            case 'L': info.attach = ATTACH_LEFT;      break;
            case 'R': info.attach = ATTACH_RIGHT;     break;
            case 'I': info.attach = ATTACH_INVENTORY; break;
            default:
            {
                throw Id::SyntacticalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                                    "invalid enumeration element");
            }
        };
        info.money = ctxt.readIntegerLiteral();

        //If the skin type is a '?' character then it means random skin else it's an integer
        ctxt.skipWhiteSpaces();
        if(ctxt.is('?')) {
            info.skin = ObjectProfile::NO_SKIN_OVERRIDE;
            ctxt.next();
        }
        else {
            info.skin = ctxt.readIntegerLiteral();
        }

        info.passage = ctxt.readIntegerLiteral();
        info.content = ctxt.readIntegerLiteral();
        info.level = ctxt.readIntegerLiteral();
        info.stat = ctxt.readBool();

        ctxt.readPrintable();   ///< BAD! Unused ghost value

        chr = ctxt.readPrintable();
        info.team = (chr - 'A') % Team::TEAM_MAX;
        
        return true;
    }
    else if (ctxt.is('#'))
    {
        ctxt.next();
        info.do_spawn = false;

        std::string what = ctxt.readName();
        if (what != "dependency")
        {
            throw Id::SyntacticalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(),ctxt.getLineNumber()),
                                                "syntax error");
        }
        std::string who;
        ctxt.skipWhiteSpaces();
        if (ctxt.is('%'))
        {
            who = ctxt.readReference();
        }
        else
        {
            who = ctxt.readName();
        }
        if (who.empty()) /// @todo Verify that this is unnecessary based on the definition of readName.
        {
            throw Id::SyntacticalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                                "syntax error");
        }
        int slot = ctxt.readIntegerLiteral();
        // Store the data.
        info.spawn_comment = who;
        info.slot = slot;
        return true;
    }
    else if (!ctxt.is(ReadContext::Traits::endOfInput()))
    {
        throw Id::LexicalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                        "junk after end of spawn file");
    }
    return false;
}