Bobot_mapping.c (2)

void FUSION_MAPPING_ShowNodes()
{    int nbplayers;

    nbplayers=G_CountPlayers();
    if (nbplayers>1)
    {    AP("cp \"\n\n\n\nYou must be alone in the map to display the nodes.\n\" 1");
        shownodes = qfalse;
        return;
    }
    if (shownodes)
    {    FUSION_MAPPING_HideNodes();
        return;
    }
    AP("cp \"\n\n\n\nDisplaying nodes ^1ON\n\" 1");
    shownodes = qtrue;
    BOBOT_MAPPING_CalculateVisibleNodes();
}

void FUSION_MAPPING_ShowConnection( int from, int to ,int type)
{
    if ((number_conn <= MAX_CONNEXIONS) && (from != INVALID) && (to != INVALID) && (from != to))
    {    connections[number_conn] = G_Spawn();
        connections[number_conn]->s.eType = ET_EVENTS + EV_RAILTRAIL;
        connections[number_conn]->classname = "node_connection";
        connections[number_conn]->eventTime = level.time;
        connections[number_conn]->r.eventTime = level.time;
        connections[number_conn]->freeAfterEvent = qfalse;
        G_SetOrigin( connections[number_conn], nodes[from].origin );
        trap_LinkEntity( connections[number_conn] );
        VectorCopy(nodes[to].origin, connections[number_conn]->s.origin2);
        connections[number_conn]->s.otherEntityNum2 = 0;
        connections[number_conn]->s.dmgFlags = type;
        number_conn++;
    }
}

void FUSION_MAPPING_SetConnectionCost( int from, int to, int new_cost )
{    int i;

    for (i = 0; i < MAX_NODELINKS; i++)
    {    if (nodes[from].links[i].targetNode == to)
        {    if (new_cost == 32000)
            {    nodes[from].links[i].targetNode = INVALID;
                nodes[from].links[i].cost = 0;
                if (shownodes)
                {    AP("cp \"\n\n\n\nLink destroyed.\n\" 1");    }
            }
            else
            {    nodes[from].links[i].cost = (float) new_cost;
                if (shownodes)
                {    AP(va("cp \"\n\n\n\nNode %i to node %i : new cost %i (last cost %f)\n\" 1", from,to,new_cost,nodes[from].links[i].cost)); }       
            }
            return;
        }
    }
}

char TypeNode[1000];

void BOBOT_PrintType(int node_type)
{    TypeNode[0]='\0';
    if (node_type & NODE_MOVE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Move"); }
    if (node_type & NODE_OBJECTIF_PRIM)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Primary Objective"); }
    if (node_type & NODE_OBJECTIF_SEC)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Secondary Objective"); }
    if (node_type & NODE_PRONE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Prone"); }
    if (node_type & NODE_DYNAMITE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Dynamitable"); }
    if (node_type & NODE_MINE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Mine"); }
    if (node_type & NODE_DRAPEAU)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Spawn Flag"); }
    if (node_type & NODE_MOBIL)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Mobil"); }
    if (node_type & NODE_PROTECTION)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Protection"); }
    if (node_type & NODE_CONSTRUCTION)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Construction"); }
    if (node_type & NODE_BLOCKABLE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Blockable"); }
    if (node_type & NODE_TEAM_ALLIES)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Allies"); }
    if (node_type & NODE_TEAM_AXIS)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Axis"); }
    if (node_type & NODE_CHARGE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Charge"); }
    if (node_type & NODE_ECHELLE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Ladder"); }
    if (node_type & NODE_LINKED)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Linked"); }
    if(node_type & NODE_HEALER)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Healer"); }
    if(node_type & NODE_SUPPLIER)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Supplier"); }
    if(node_type & NODE_TANK)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Tank"); }
    if(node_type & NODE_TANK_WAY)
    { Q_strcat( TypeNode,sizeof(TypeNode)," TankWay"); }
    if(node_type & NODE_HEAVY_MACHINGUN)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Heavy Machinegun"); }
    if(node_type & NODE_TAKE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Take"); }
    if(node_type & NODE_JUMP)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Jump"); }
    /*if(node_type & NODE_SNIPE)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Snipe"); }*/
    if(node_type & NODE_DUCK)
    { Q_strcat( TypeNode,sizeof(TypeNode)," Duck"); }
    if(node_type & NODE_ALLTEAM)
    { Q_strcat( TypeNode,sizeof(TypeNode)," All.Team"); }
}

void BOBOT_MAPPING_PrintConnecType(int con_type)
{    switch(con_type)
    {    case CONNEC_NORMAL:
            Q_strcat(connectionPrint,sizeof(connectionPrint)," Neuronal, ");
            break;
        case CONNEC_ALLIES:
            Q_strcat(connectionPrint,sizeof(connectionPrint)," Allied, ");
            break;
        case CONNEC_AXIS:
            Q_strcat(connectionPrint,sizeof(connectionPrint)," Axis, ");
            break;
        case CONNEC_TOUT_DROIT:
            Q_strcat(connectionPrint,sizeof(connectionPrint)," Basic, ");
            break;
        case CONNEC_ECHELLE:
            Q_strcat(connectionPrint,sizeof(connectionPrint)," Ladder, ");
            break;
/*        case CONNEC_DOOR:
            G_Printf("Door");
            break;*/
    }
}

void FUSION_MAPPING_SetNodeType( int node, int node_type )
{    char msg [MAX_TOKEN_CHARS];
   
    if (!shownodes)
    { return; }
    if (node == INVALID)
    { node = current_node; }
    Q_strcat(msg,sizeof(msg),va("Node %i ", node));
    BOBOT_PrintType(nodes[node].type);
    Q_strcat(msg,sizeof(msg),TypeNode);
    nodes[node].type = node_type;
    BOBOT_NODES_ResolveAllPaths();

    /*    joc on recalcule les graphismes  */
    if (visible_nodes[node] != NULL)
    { G_FreeEntity(visible_nodes[node]); }
    FUSION_MAPPING_CreateVisibleNode(node);
    BOBOT_PrintType(nodes[node].type);
    Q_strcat(msg,sizeof(msg),va(" reseted in %s", TypeNode));
    AP(va("cp \"\n\n\n\n%s\n\" 1", msg));
}

void FUSION_MAPPING_HideNodes()
{    int i;

    if (!shownodes)
    { return; }
    AP("cp \"\n\n\n\nDisplaying nodes ^1OFF\n\" 1");

    /*    Destroy all connections between the nodes */
    for (i = 0; i < number_conn; i++)
    {    if (connections[i] != NULL)
        {    G_FreeEntity(connections[i]);
            connections[i] = NULL;
        }
    }
    number_conn = 0;

    /*    Destroy all nodes */
    for (i = 0; i < number_of_nodes; i++)
    {    if (visible_nodes[i] != NULL)
        {    G_FreeEntity( visible_nodes[i]);
            visible_nodes[i] = NULL;
        }
    }
    shownodes = qfalse;
}
// -------------------------------------------
void FUSION_MAPPING_SetTouchConnection(int ctype)
{    if (touch_connections != 0)
    {    switch (touch_connections & CONNEC_MASK)
        {    case CONNEC_DESTROY :
                AP("cpm \"Destruction of connection : ^1OFF.\" 1");
                break;
            case CONNEC_DOUBLE:
                AP("cpm \"Creation of double connections : ^1OFF.\" 1");
                break;
            case CONNEC_SINGLE:
                AP("cpm \"Creation of single connection : ^1OFF.\" 1");
                break;
        }
        touch_connections = 0;
    }
    else if (ctype != 0)
    {    touch_connections = ctype;
        switch (ctype & CONNEC_MASK)
        {    case CONNEC_DESTROY :
                AP("cpm \"Destruction of connections : ^1ON.\"");
                break;
            case CONNEC_DOUBLE:
                BOBOT_MAPPING_PrintConnecType(ctype & ~CONNEC_MASK);
                AP("cpm \"Creation of double connections : ^1ON.\" 1");
                break;
            case CONNEC_SINGLE:
                BOBOT_MAPPING_PrintConnecType(ctype & ~CONNEC_MASK);
                AP("cpm \"Creation of single connection : ^1ON.\" 1");
                break;
        }
    }
}
void FUSION_MAPPING_SetRelocateNode()
{   
    if (relocate_node)
    {    relocate_node = qfalse;
        AP("cp \"\n\n\n\nRelocating node : ^1OFF\n\" 1");
    }
    else
    {    relocate_node = qtrue;
        AP("cp \"\n\n\n\nRelocating node : ^1ON\n\" 1");
    }
}

void FUSION_MAPPING_TouchNode ( gentity_t *entclient, gentity_t *other, trace_t *trace )
{    int j;
    int NodeFrom,NodeTo;
    int node_num = entclient->current_node;
    char NodePrint[5];
    char NodeConnect[50];
    char msg[MAX_STRING_CHARS];

    msg[0] = '\0';
    NodeFrom=0;
    NodeTo=0;
    if (!shownodes)
    { return; }
    if (node_num != current_node)
    {    /*    Select this node */
        if (entclient->r.svFlags & SVF_BOT)                    //les bot ne selectionnent pas les nodes !
        { return; }
        if (touch_connections != 0)
        {    if(touch_connections & CONNEC_DESTROY)            //Si c'est une destruction de connexion
            {    if(BOBOT_MAPPING_DestroyNodeConnection( current_node, node_num))
                {    NodeFrom=1;
                    destructionconnex++;
                }
                if(BOBOT_MAPPING_DestroyNodeConnection( node_num ,current_node))
                {    NodeTo=1;
                    destructionconnex++;
                }
            }
            else if (touch_connections & CONNEC_SINGLE)        // Si c'est une création de connexion
               {    if (BOBOT_MAPPING_CreateNodeConnection(current_node,node_num,touch_connections & ~CONNEC_MASK))
                {    NodeFrom=1;
                    creationconnex++;
                }
            }
               else
               {    if (BOBOT_MAPPING_CreateNodeConnection(node_num,current_node,touch_connections & ~CONNEC_MASK))
                {    NodeTo=1;
                    creationconnex++;
                }
                if (BOBOT_MAPPING_CreateNodeConnection(current_node,node_num,touch_connections & ~CONNEC_MASK))
                {    NodeFrom=1;
                    creationconnex++;
                }
               }
            FUSION_MAPPING_SetTouchConnection(touch_connections);
        }

        /*    Affichage des messages en gameplay */
        if(creationconnex>0)
        {    if ((NodeFrom+NodeTo)==2)
            { AP(va("cp \"\n\n\n\nConnections created between the nodes %i <==> %i.\n\" 1",current_node, node_num)); }
            else if (NodeFrom==1)
            { AP(va("cp \"\n\n\n\nConnection created between the nodes %i ==> %i.\n\" 1",current_node, node_num)); }
            else if (NodeTo==1)
            { AP(va("cp \"\n\n\n\nConnection created between the nodes %i <== %i.\n\" 1",current_node, node_num)); }
            else
            { AP(va("cp \"\n\n\n\nNo created connections between the nodes %i and %i.\n\" 1",node_num ,current_node)); }
        }
        if(destructionconnex>0)
        {    if ((NodeFrom+NodeTo)==2)
            { AP(va("cp \"\n\n\n\nConnections destroyed between the nodes %i <==> %i.\n\" 1",current_node, node_num)); }
            else if (NodeFrom==1)
            { AP(va("cp \"\n\n\n\nConnection destroyed between the nodes %i ==> %i.\n\" 1",current_node, node_num)); }
            else if (NodeTo==1)
            { AP(va("cp \"\n\n\n\nConnection destroyed between the nodes %i <== %i.\n\" 1",current_node, node_num)); }
            else
            { AP(va("cp \"\n\n\n\nThere is no connection between the nodes %i and %i.\n\" 1",node_num ,current_node)); }
        }
        current_node = node_num;
        BOBOT_PrintType(nodes[current_node].type);
        BOBOT_MAPPING_CalculateVisibleNodes();
        if((destructionconnex==0) && (creationconnex==0))
        {    Q_strcat(msg, sizeof(msg),va("^8Node.   ^7%i\n^8Radius. ^7%d\n^8Type.  ^7%s", current_node,(int)nodes[current_node].radius,TypeNode));    }
        else
        {    destructionconnex=0;
            creationconnex=0;
        }

        /*    Affichage des connexions en console. */
        connectionPrint[0]='\0';
        NodeConnect[0]='\0';
        //G_Printf("\nConnection(s)");
        for(j=0;j<MAX_NODELINKS;j++)
        {    if (nodes[current_node].links[j].targetNode != INVALID)
            {     Q_strcat(connectionPrint,sizeof(connectionPrint),va("%i",nodes[current_node].links[j].targetNode,NodePrint));
                BOBOT_MAPPING_PrintConnecType(nodes[current_node].links[j].type);
            }
        }
        if (connectionPrint[0])
        {    Q_strcat(msg,sizeof(msg),"\n^8Connec. ^7");
            Q_strcat(msg,sizeof(msg),connectionPrint);
        }
        else
        {    Q_strcat(msg,sizeof(msg),"\n^8Connection: none");    }
        if (msg[0])
        { AP(va("bp \"%s\" 1",msg)); }
    }
}
/*--------------------------------------------------------------------
    AVD Creates a new visible entity for the current node
--------------------------------------------------------------------*/
void FUSION_MAPPING_CreateVisibleNode( int i )
{    visible_nodes[i] = G_Spawn();

    /*    joc_nodes */
    visible_nodes[i]->s.eType    = ET_WAYPOINT;
    visible_nodes[i]->active    = qtrue;
    visible_nodes[i]->classname    = "node";
    visible_nodes[i]->r.svFlags    = SVF_USE_CURRENT_ORIGIN | SVF_BROADCAST;
    if (nodes[i].type & NODE_OBJECTIF_PRIM)
    { visible_nodes[i]->s.modelindex    = G_ModelIndex( "model/node_obj.md3" ); }    // model de sphere joc_node
    else
    { visible_nodes[i]->s.modelindex    = G_ModelIndex( "model/node.md3" ); }        // model de sphere joc_node
    visible_nodes[i]->current_node    = i;                                            // This is the node number
    visible_nodes[i]->touch            = FUSION_MAPPING_TouchNode;
    visible_nodes[i]->clipmask        = CONTENTS_SOLID | CONTENTS_MISSILECLIP;
    visible_nodes[i]->r.contents    = CONTENTS_TRIGGER|CONTENTS_ITEM;
    //visible_nodes[i]->think            = BOBOT_NodeThink;
    //visible_nodes[i]->splashRadius    = nodes[i].radius;
    visible_nodes[i]->s.modelindex2 = nodes[i].radius;                                //joc c'est pas bien de faire ca ;)
    //visible_nodes[i]->nextthink        = level.time + FRAMETIME;

    /*    Body, so we can touch this node ----(SA) so items sit on the ground */
    VectorSet( visible_nodes[i]->r.mins, -nodes[i].radius, -nodes[i].radius, 0 );
    VectorCopy( visible_nodes[i]->r.mins, visible_nodes[i]->r.absmin );

    /*    (SA)    so items sit on the ground */
    VectorSet( visible_nodes[i]->r.maxs, nodes[i].radius, nodes[i].radius, 2*nodes[i].radius );
    VectorCopy( visible_nodes[i]->r.maxs, visible_nodes[i]->r.absmax );
    VectorCopy(nodes[i].origin, visible_nodes[i]->s.origin);

    /*    -joc_nodes */
    G_SetOrigin (visible_nodes[i], visible_nodes[i]->s.origin);
    G_SetAngle (visible_nodes[i], visible_nodes[i]->s.angles);
    trap_LinkEntity( visible_nodes[i] );
}

/*--------------------------------------------------------------------------
    joc on affiche tous les nodes et toutes les connections c'est plus simple.
    Rend les nodes visibles
----------------------------------------------------------------------------*/
void BOBOT_MAPPING_CalculateVisibleNodes()
{    int i,j,k,z,coul;

    if (current_node == INVALID)
    { current_node = 0; }
    if (!shownodes || current_node < 0 || current_node > MAX_NODES)
    { return; }

    /*    Destroy ALL connections, bit cpu intensive, but hey */
    for (i = 0; i < number_conn; i++)
    {    if (connections[i] != NULL)
        {    G_FreeEntity(connections[i]);
            connections[i] = NULL;
        }
    }
    number_conn = 0;
    if(g_showconnections.integer == 1)
    {    for(i=0; i<number_of_nodes;i++)
        {    for (z = 0; z < MAX_NODELINKS; z++)
            {    if (nodes[i].links[z].targetNode != INVALID)
                {    k = nodes[i].links[z].targetNode;
                    for (j=0; j<MAX_NODELINKS;j++)
                    {    if (nodes[k].links[j].targetNode == i)
                        {    coul = 1;        // rouge
                            if ((nodes[k].links[j].type == CONNEC_ECHELLE) || (nodes[i].links[z].type == CONNEC_ECHELLE))
                            { coul = 2; }    // vert
                            if ((nodes[k].links[j].type == CONNEC_TOUT_DROIT) || (nodes[i].links[z].type == CONNEC_TOUT_DROIT))
                            { coul = 4;  }    // cyan
                            /*if (nodes[k].links[j].type == CONNEC_DOOR || nodes[i].links[z].type == CONNEC_DOOR)
                            { coul = 7;  }//blanc marche pas cette couleur ???*/

                            /*    on a une double connection, on l'affiche qu'une seule fois ! */
                            if(i < k)
                            { FUSION_MAPPING_ShowConnection( i, k ,coul); }    // rouge
                            break;
                        }
                    }
                    if( j == MAX_NODELINKS)
                    {    coul = 3;
                        if (nodes[i].links[z].type == CONNEC_ECHELLE)
                        { coul = 5; } //jaune
                        if (nodes[i].links[z].type == CONNEC_TOUT_DROIT)
                        { coul = 6; } //magenta
                        /*if (nodes[i].links[z].type == CONNEC_DOOR)
                        { coul = 7; }*/
                        //on a une connection a sens unique, 3= couleur bleu
                        FUSION_MAPPING_ShowConnection( i, k ,coul);
                    }
                }
            }
        }
    }
    /*    Show all nodes  */
    for (i = 0; i < number_of_nodes; i++)
    {    if (visible_nodes[i] == NULL)
        { FUSION_MAPPING_CreateVisibleNode(i); }
        else if (visible_nodes[i] != NULL)
        {    G_FreeEntity( visible_nodes[i] );
            visible_nodes[i] = NULL;
            FUSION_MAPPING_CreateVisibleNode(i);
        }
    }
}

Créer un site gratuit avec e-monsite - Signaler un contenu illicite sur ce site