bitwise shift + REP
#1

Hello dear visitors of the portal sowing!
The problem is that the shift is 128!
PHP код:
enum
{
    
GANG_ID_BALLAS// = 0
    
GANG_ID_VAGOS,
    
GANG_ID_GROVE,    
    
GANG_ID_AZTECAS,
    
GANG_ID_RIFA,
    
__LAST_GANG_ID // = 5, the value will be used hereinafter
}
enum(+= 2)
{
    
REL_SHIFT_BALLAS,    // bits 0-1
    
REL_SHIFT_VAGOS,    // = 2, bits 2-3
    
REL_SHIFT_GROVE,    // = 4, bits 4-5
    
REL_SHIFT_AZTECAS,    // ...
    
REL_SHIFT_RIFA        // ... 8-9
};
enum
{
    
GANG_REL_NEGATIVE,
    
GANG_REL_NEUTRAL,
    
GANG_REL_POSITIVE
}; 
PHP код:
new gang_relationships[__LAST_GANG_ID]; 
PHP код:
const GANG_REL_MASK 0b11111111_11111111_11111111_11111100
PHP код:
case 11103:                               //Rifa
{
    if(!
response) return 0;                                 //Ballas
    
if(PlayerInfo[playerid][p_leaders] == 12)
    {
        if(
ismysqlnull(inputtext))
            return 
SPD(playerid11103DIALOG_STYLE_INPUT"   ","С какой бандой вы желаете заключить союз\n\nRifa\n\
                                                                                                    Grove\n\
                                                                                                    Aztec\n\
                                                                                                    Vagos"
"Ок""Отмена");
    }
    if(
PlayerInfo[playerid][p_leaders] == 13)
    {
        if(
ismysqlnull(inputtext))
            return 
SPD(playerid11103DIALOG_STYLE_INPUT"   ","С какой бандой вы желаете заключить союз\n\nRifa\n\
                                                                                                    Grove\n\
                                                                                                    Ballas\n\
                                                                                                    Aztec"
"Ок""Отмена");
    }
                                      
//Grove
    
if(PlayerInfo[playerid][p_leaders] == 15)
    {
        if(
ismysqlnull(inputtext))
            return 
SPD(playerid11103DIALOG_STYLE_INPUT"   ","С какой бандой вы желаете заключить союз\n\nRifa\n\
                                                                                                    Aztec\n\
                                                                                                    Ballas\n\
                                                                                                    Vagos"
"Ок""Отмена");
    }
                                      
//Aztec
    
if(PlayerInfo[playerid][p_leaders] == 17)
    {
        if(
ismysqlnull(inputtext))
            return 
SPD(playerid11103DIALOG_STYLE_INPUT"   ","С какой бандой вы желаете заключить союз\n\nRifa\n\
                                                                                                    Grove\n\
                                                                                                    Ballas\n\
                                                                                                    Vagos"
"Ок""Отмена");
    }
                                      
//Rifa
    
if(PlayerInfo[playerid][p_leaders] == 18)
    {
        if(
ismysqlnull(inputtext))
            return 
SPD(playerid11103DIALOG_STYLE_INPUT"   ","С какой бандой вы желаете заключить союз\n\nAztec\n\
                                                                                                    Grove\n\
                                                                                                    Ballas\n\
                                                                                                    Vagos"
"Ок""Отмена");
    }
    if( 
PlayerInfo[playerid][p_leaders] == 12 ||
        
PlayerInfo[playerid][p_leaders] == 13 ||
        
PlayerInfo[playerid][p_leaders] == 15 ||
        
PlayerInfo[playerid][p_leaders] == 17 ||
        
PlayerInfo[playerid][p_leaders] == 18)
    {
        new
            
string_band_union[46],
            
my_orgazantion[8];
        switch(
PlayerInfo[playerid][p_members])
        {
            case 
12my_orgazantion "ballas";
            case 
13my_orgazantion "vagos";
            case 
15my_orgazantion "grove";
            case 
17my_orgazantion "aztecas";
            case 
18my_orgazantion "rifa";
        }
        for(new 
interator_name_bandinterator_name_band sizeof(name_diplamation); interator_name_band ++)
        {
            
printf("inputtext: %s | name_diplamation[interator_name_band][e_Name]: %s"inputtextname_diplamation[interator_name_band][e_Name]);
            if(
strcmp(inputtextname_diplamation[interator_name_band][e_Name], false) != 0)
            {
                print(
"1) Работает");
                continue;
            }
            print(
"2) Работает");
            new 
i_gang_id GetGangID(name_diplamation[interator_name_band][e_Value]);
            new 
player_gang_id GetGangID(PlayerInfo[playerid][p_members]);
            
// ID другой банды  - в переменной i
            
new shift_val i_gang_id i_gang_id;
            
gang_relationships[player_gang_id] &= GANG_REL_MASK << shift_val;
            
gang_relationships[player_gang_id] |= GANG_REL_POSITIVE << shift_val;
            
shift_val player_gang_id player_gang_id;
            
gang_relationships[i_gang_id] &= GANG_REL_MASK << shift_val;
            
gang_relationships[i_gang_id] |= GANG_REL_POSITIVE << shift_val;
            print(
"3) Работает");
            
//sting_debbag[0] = EOS;
            
//                      strcat(save_union_band_one_to_array[playerid], name_band_for_diplamation[interator_name_band]);
//                    strcat(save_union_band_two_to_array[playerid], my_orgazantion);
            
//                    format(sting_debbag, sizeof(sting_debbag), "Cоюз | После | SetPVarString | name_band_one: %s | name_band_two: %s", save_union_band_one_to_array[playerid], save_union_band_two_to_array[playerid]);
            //SendClientMessageToAll(-1, sting_debbag);
            
SPD(playerid,22201,DIALOG_STYLE_INPUT,"   ","Введите в поле ID Лидера Банды","Ок","Отмена");
            
format(string_band_unionsizeof(string_band_union), "Вы предложили союз банде %s"name_diplamation[interator_name_band][e_Name]);
            
SendClientMessage(playeridCOLOR_NEWSstring_band_union);
            print(
"4) Работает");
        }
    }

PHP код:
GetGangID(family_id)
{
    switch(
family_id)
    {
        case 
12:
            return 
GANG_ID_BALLAS;
        case 
13:
            return 
GANG_ID_VAGOS;
        case 
17:
            return 
GANG_ID_AZTECAS;
        case 
18:
            return 
GANG_ID_RIFA;
    }
    return -
1;

PHP код:
if(strcmp(cmd"/debbuging"true) == 0)
{
    new 
string_debbag[30];
    
format(string_debbagsizeof(string_debbag), "%d | %d | %d | %d"gang_relationships[GANG_ID_AZTECAS],
                                                                 
gang_relationships[GANG_ID_VAGOS],
                                                                 
PlayerInfo[playerid][p_members],
                                                                 
PlayerInfo[playerid][p_leaders]);
    
SendClientMessageToAll(-1string_debbag);

debag:
PHP код:
20:46:14inputtextLos Santos Vagos name_diplamation[interator_name_band][e_Name]: The Ballas
[20:46:141Job
[20:46:14inputtextLos Santos Vagos name_diplamation[interator_name_band][e_Name]: Los Santos Vagos
[20:46:142Job
[20:46:14i_gang_idplayer_gang_id3
[20:46:141shift_val2
[20:46:141gang_relationships[player_gang_id]: 
 GANG_REL_MASK
: -
 shift_val
2
[20:46:142gang_relationships[player_gang_id]: 
 GANG_REL_MASK
: -
 shift_val
2
[20:46:142shift_val6
[20:46:141gang_relationships[i_gang_id]: 
 GANG_REL_MASK
: -
 shift_val
6
[20:46:142gang_relationships[i_gang_id]: 128 
 GANG_REL_MASK
: -
 shift_val
6
[20:46:143Job
[20:46:144Job
[20:46:14inputtextLos Santos Vagos name_diplamation[interator_name_band][e_Name]: Grove Street
[20:46:141Job
[20:46:14inputtextLos Santos Vagos name_diplamation[interator_name_band][e_Name]: Varios Los Aztecas
[20:46:141Job
[20:46:14inputtextLos Santos Vagos name_diplamation[interator_name_band][e_Name]: The Rifa
[20:46:141Job 
Codding:
PHP код:
for (new interator_name_bandinterator_name_band sizeof(name_diplamation); interator_name_band++)
{
    
printf("inputtext: %s | name_diplamation[interator_name_band][e_Name]: %s"inputtextname_diplamation[interator_name_band][e_Name]);
    if (
strcmp(inputtextname_diplamation[interator_name_band][e_Name], false) != 0)
    {
        print(
"1) Job");
        continue;
    }
    print(
"2) Job");
    new 
i_gang_id GetGangID(name_diplamation[interator_name_band][e_Value]);
    new 
player_gang_id GetGangID(PlayerInfo[playerid][p_members]);
    
printf("i_gang_id: %d | player_gang_id: %d"i_gang_idplayer_gang_id);
    
// ID другой банды  - в переменной i
    
new shift_val i_gang_id i_gang_id;
    
printf("1) shift_val: %d"shift_val);
    
gang_relationships[player_gang_id] &= GANG_REL_MASK << shift_val;
    
printf("1) gang_relationships[player_gang_id]: %d \n GANG_REL_MASK: %d \n shift_val: %d"gang_relationships[player_gang_id], GANG_REL_MASKshift_val);
    
gang_relationships[player_gang_id] |= GANG_REL_POSITIVE << shift_val;
    
printf("2) gang_relationships[player_gang_id]: %d \n GANG_REL_MASK: %d \n shift_val: %d"gang_relationships[player_gang_id], GANG_REL_MASKshift_val);
    
shift_val player_gang_id player_gang_id;
    
printf("2) shift_val: %d"shift_val);
    
gang_relationships[i_gang_id] &= GANG_REL_MASK << shift_val;
    
printf("1) gang_relationships[i_gang_id]: %d \n GANG_REL_MASK: %d \n shift_val: %d"gang_relationships[i_gang_id], GANG_REL_MASKshift_val);
    
gang_relationships[i_gang_id] |= GANG_REL_POSITIVE << shift_val// Apparently the error in this line
    
printf("2) gang_relationships[i_gang_id]: %d \n GANG_REL_MASK: %d \n shift_val: %d"gang_relationships[i_gang_id], GANG_REL_MASKshift_val);
    print(
"3) Job");
    
SPD(playerid22201DIALOG_STYLE_INPUT"   ""Введите в поле ID Лидера Банды""Ок""Отмена");
    
format(string_band_unionsizeof(string_band_union), "Вы предложили союз банде %s"name_diplamation[interator_name_band][e_Name]);
    
SendClientMessage(playeridCOLOR_NEWSstring_band_union); 
Sorry for my English! I am Russian!
Thanks in advance
Reply
#2

Well, I have no idea why you need to hold relationships in that way.
You can't have >16 gangs at a time, the second enum (with shifts) is not necessary since you can use first with << 2 and, in general, it's a bad implementation of gang relation system.
I've read your code twice and can suggest next:
1. Make some stock function like "GetGangRelToGang(gangOne, gangTwo)" which you can perfectly debug and use in other places without bitwise operations and thinking how your system was made
2. Or rewrite this system. I have no idea why you should hold data in that way - if you make it with 2-dimentional array you should loose a few bytes of memory but save processor time (consumed on bitwise operations) and have more clear code.
Reply
#3

Quote:
Originally Posted by prineside
Посмотреть сообщение
Well, I have no idea why you need to hold relationships in that way.
You can't have >16 gangs at a time, the second enum (with shifts) is not necessary since you can use first with << 2 and, in general, it's a bad implementation of gang relation system.
I've read your code twice and can suggest next:
1. Make some stock function like "GetGangRelToGang(gangOne, gangTwo)" which you can perfectly debug and use in other places without bitwise operations and thinking how your system was made
2. Or rewrite this system. I have no idea why you should hold data in that way - if you make it with 2-dimentional array you should loose a few bytes of memory but save processor time (consumed on bitwise operations) and have more clear code.
You from Russian?
Reply
#4

UP's
Reply
#5

UP's
Reply
#6

UP's
Reply
#7

UP'S
Reply
#8

The problem is the left shift, it wont work with your current mask, change it to that
PHP код:
const GANG_REL_MASK 0b11;
gang_relationships[player_gang_id] &= ~(GANG_REL_MASK << shift_val); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)