Пример #1
0
//---------------------------------------------------------------------------------------------------------------------
VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent)
    : VisPath(data, parent), point4Id(NULL_ID), lineP1(nullptr), lineP4(nullptr), line(nullptr), angle1(EMPTY_ANGLE),
      angle2(EMPTY_ANGLE), kAsm1(1), kAsm2(1), kCurve(1)
{
    lineP1 = InitPoint(supportColor, this);
    lineP4 = InitPoint(supportColor, this);
    line = InitItem<QGraphicsLineItem>(mainColor, this);
}
Пример #2
0
//---------------------------------------------------------------------------------------------------------------------
VisToolLineIntersect::VisToolLineIntersect(const VContainer *data, QGraphicsItem *parent)
    :VisLine(data, parent), line1P2Id(NULL_ID), line2P1Id(NULL_ID), line2P2Id(NULL_ID), point(nullptr),
      line1P1(nullptr), line1P2(nullptr), line1(nullptr), line2P1(nullptr), line2P2(nullptr)
{
    line1P1 = InitPoint(supportColor, this);
    line1P2 = InitPoint(supportColor, this);
    line1 = InitItem<QGraphicsLineItem>(supportColor, this);

    line2P1 = InitPoint(supportColor, this);
    line2P2 = InitPoint(supportColor, this);

    point = InitPoint(mainColor, this);
}
Пример #3
0
//---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *VisToolSplinePath::getPoint(unsigned int i)
{
    if (static_cast<unsigned int>(points.size() - 1) >= i && points.isEmpty() == false)
    {
        return points.at(static_cast<int>(i));
    }
    else
    {
        QGraphicsEllipseItem * point = InitPoint(supportColor, this);
        points.append(point);
        return point;
    }
    return nullptr;
}
Пример #4
0
CTeleport::CTeleport(TCHAR *pszArgs)
{
	// RES_TELEPORT
	TCHAR *ppArgs[4];
	size_t iArgQty = Str_ParseCmds(pszArgs, ppArgs, COUNTOF(ppArgs), "=");
	if ( iArgQty < 2 )
		DEBUG_ERR(("Bad teleport def\n"));

	if ( iArgQty >= 1 )
		Read(ppArgs[0]);
	else
		InitPoint();

	if ( iArgQty >= 2 )
		m_ptDst.Read(ppArgs[1]);
	else
		m_ptDst.InitPoint();

	m_fNPC = (iArgQty >= 4) ? (ATOI(ppArgs[3]) != 0) : false;
}
Пример #5
0
void BestFirstSearch::FindMoveCostToCitiesZ(const sint32 player_idx, const sint32 z_height, 
    const double max_cost, const double min_cost)
{	
    g_search_count++; 

    
    BOOL searching = TRUE; 
    sint32 num_cities_found = 0; 
    sint32 num_cities_out_there = FindNumCitiesAtHeight(player_idx, z_height); 
    if (num_cities_out_there < 1) return; 

    
    m_priority_queue.Clear(); 

    
    MapPoint start_pos;
    MapPoint neighbor_pos; 
    double start_cost;
	g_player[player_idx]->GetCapitolPos(start_pos); 
    start_cost = -g_theWorld->GetCell(start_pos)->GetMoveCost() + ((start_pos.z != z_height) ? 1000.0 : 0) ;
    start_pos.z = z_height; 	
    Cell *neighbor_cell = g_theWorld->GetCell(start_pos);              
    neighbor_cell->m_search_count = g_search_count; 
    InitPoint(player_idx, NULL, neighbor_cell->m_point, start_pos, start_cost, max_cost);
    sint32 nodes_opened = 1;
    AstarPoint* best = neighbor_cell->m_point; 
    double past_cost;

    sint32 i; 
    sint32 bfs_loop_count =0; 
    Unit a_city;
    double dist_cost; 
    do {  
        Assert(bfs_loop_count++ < 140000); 
                
        best->m_is_expanded = TRUE;  

        past_cost = best->m_total_cost; 
        
        
        for (i=0; i <= 7; i++) { 
            
            
            if (!best->m_pos.GetNeighborPosition(WORLD_DIRECTION(i), neighbor_pos)) continue;	            
            neighbor_cell = g_theWorld->GetCell(neighbor_pos);     

            if (neighbor_cell->m_search_count == g_search_count)  
                continue; 

            
            if (InitPoint(player_idx, best, neighbor_cell->m_point, neighbor_pos, past_cost, max_cost)) {  

g_theWorld->SetColor(neighbor_pos, int(past_cost)); 
                nodes_opened++;
                neighbor_cell->m_search_count = g_search_count;    
                a_city = neighbor_cell->GetCity(); 
                if (a_city.m_id != 0) { 
                    if (a_city.GetOwner() == player_idx) { 

                        dist_cost = max(0.0, neighbor_cell->m_point->m_total_cost - min_cost); 
                        a_city.AccessData()->GetCityData()->GetHappy()->SetDistToCapitol(dist_cost); 
                        num_cities_found++;
                        if (num_cities_found == num_cities_out_there) { 
                            searching = FALSE; 
                            break; 
                        } 
                    } 
                } 
                m_priority_queue.Insert(neighbor_cell->m_point); 
            } 
        } 

        if (!searching || (m_priority_queue.Len() < 1)) { 
            break; 
        } else {                       
            best = m_priority_queue.Remove(1);                
        }        

    } while (searching);      

    
    
    g_astar_mem.MassDelete(FALSE);   
}