1 (edited by Roanoke 2008-06-08 05:50:17)

Topic: Grenade spread

Hi, I am trying to get a grenade spread like in the streetwars servers where one click = 3 shots. Here is my current grenade code:

case WEAPON_GRENADE:
        {
            if(!grenade_shotspread)
            grenade_shotspread = 1;

            grenade_shotspread = 3;
            msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
            msg_pack_int(grenade_shotspread);
            for(int i = grenade_shotspread; i <= grenade_shotspread; i++)
            {
                
                float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
                latest_input.target_x= latest_input.target_x+spreading[i+12];
                latest_input.target_y= latest_input.target_y+spreading[i+12];
                vec2 new_dir = normalize(vec2(latest_input.target_x, latest_input.target_y));
                float a = get_angle(direction);
                a += spreading[i+2];
                float v = 1-(abs(i)/(float)grenade_shotspread);
                float speed = mix((float)tuning.grenade_speed, 1.0f, v);
                projectile *proj = new projectile(WEAPON_GRENADE,
                    client_id,
                    projectile_startpos,
                    new_dir,
                    (int)(server_tickspeed()*tuning.grenade_lifetime),
                    this,
                    1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
                    
                // pack the projectile and send it to the client directly
                NETOBJ_PROJECTILE p;
                proj->fill_info(&p);
                
                for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
                    msg_pack_int(((int *)&p)[i]);
            }

            msg_pack_end();
            server_send_msg(client_id);                    
            
            create_sound(pos, SOUND_GRENADE_FIRE);
        }

I tried to model the shotgun code, but it didn't work for some reason. Could someone help me with this? For the record, here is the original code:

case WEAPON_GRENADE:
        {
            projectile *proj = new projectile(WEAPON_GRENADE,
                client_id,
                projectile_startpos,
                direction,
                (int)(server_tickspeed()*tuning.grenade_lifetime),
                this,
                1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);

            // pack the projectile and send it to the client directly
            NETOBJ_PROJECTILE p;
            proj->fill_info(&p);
            
            msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
            msg_pack_int(1);
            for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
                msg_pack_int(((int *)&p)[i]);
            msg_pack_end();
            server_send_msg(client_id);

            create_sound(pos, SOUND_GRENADE_FIRE);
        } break;

I would appreciate any input on this.

if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);

2

Re: Grenade spread

case WEAPON_GRENADE:
        {
            int shotspread = 2;

            msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
            msg_pack_int(shotspread*2+1);
            
            for(int i = -shotspread; i <= shotspread; i++)
            {
                float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
                float a = get_angle(direction);
                a += spreading[i+2];
                float v = 1-(abs(i)/(float)shotspread);
                float speed = mix((float)tuning.shotgun_speeddiff, 1.0f, v);
                projectile *proj = new projectile(WEAPON_GRENADE,
                    client_id,
                    projectile_startpos,
                    vec2(cosf(a), sinf(a))*speed,
                    (int)(server_tickspeed()*tuning.grenade_lifetime),
                    this,
                    1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);

                // pack the projectile and send it to the client directly
                NETOBJ_PROJECTILE p;
                proj->fill_info(&p);
            
                msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
                msg_pack_int(1);
                for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
                    msg_pack_int(((int *)&p)[i]);
            }
            msg_pack_end();
            server_send_msg(client_id);

            create_sound(pos, SOUND_GRENADE_FIRE);
        } break;

just change int shotspread = 2;
to int shotspread = 1;

and float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
to float spreading[] = {-0.070f, 0, 0.070f};

if you want 3 and not 5 grenades.

3

Re: Grenade spread

any *.patch files ?

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

4

Re: Grenade spread

Dani wrote:

any *.patch files ?

row 1238 to 1260 in src/game/server/gs_server.cpp ( http://trac.teeworlds.com/trac/browser/ … .cpp#L1238 )

5

Re: Grenade spread

That doesn't actually do anything. Here is my current code:

case WEAPON_GRENADE:
        {
            if(!grenade_shotspread)
            grenade_shotspread = 1;

            grenade_shotspread = 3;
            msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
            msg_pack_int(grenade_shotspread);
            for(int i = grenade_shotspread; i <= grenade_shotspread; i++)
            {
                
                float spreading[] = {-0.070f, 0, 0.070f};
                latest_input.target_x= latest_input.target_x+spreading[i+12];
                latest_input.target_y= latest_input.target_y+spreading[i+12];
                vec2 new_dir = normalize(vec2(latest_input.target_x, latest_input.target_y));
                float a = get_angle(direction);
                a += spreading[i+2];
                float v = 1-(abs(i)/(float)grenade_shotspread);
                float speed = mix((float)tuning.grenade_speed, 1.0f, v);
                projectile *proj = new projectile(WEAPON_GRENADE,
                    client_id,
                    projectile_startpos,
                    new_dir,
                    (int)(server_tickspeed()*tuning.grenade_lifetime),
                    this,
                    1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
                    
                // pack the projectile and send it to the client directly
                NETOBJ_PROJECTILE p;
                proj->fill_info(&p);
                
                for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
                    msg_pack_int(((int *)&p)[i]);
            }

            msg_pack_end();
            server_send_msg(client_id);                    
            
            create_sound(pos, SOUND_GRENADE_FIRE);
        }
         break;

It only sends out one grenade. I thought this was because the shotspread was equal to 1, so I changed it to three with no luck.

if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);

6

Re: Grenade spread

Roanoke wrote:

That doesn't actually do anything. Here is my current code:

...

It only sends out one grenade. I thought this was because the shotspread was equal to 1, so I changed it to three with no luck.

o_o when i compiled and runned the code i posted, it shot 5 grenades when i fired.

7

Re: Grenade spread

Could you post your whole grenade code?

if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);

8

Re: Grenade spread

Roanoke wrote:

Could you post your whole grenade code?

that was the whole one o_o

http://filebin.ca/jokdtx/gs_server.cpp

9

Re: Grenade spread

Thanks, this worked for me. Here is the diff between the files:

--- desktop/gs_server.cpp    2008-06-09 15:41:10.000000000 -0700
+++ desktop/grenade2.cpp    2008-06-09 15:44:55.000000000 -0700
@@ -1,42 +1,36 @@
-        case WEAPON_GRENADE:
-        {
             if(!grenade_shotspread)
+            grenade_shotspread = 3;
+            msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
+            msg_pack_int(grenade_shotspread);
+            for(int i = grenade_shotspread; i <= grenade_shotspread; i++)
             {
-                int grenade_shotspread = 1;
-                msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
-                msg_pack_int(grenade_shotspread);
-            }
-            else
-            {
-                msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
-                msg_pack_int(grenade_shotspread*2+1);
-            }
-    
-            for(int i = -grenade_shotspread; i <= grenade_shotspread; i++)
-            {
-                float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
+                
+                float spreading[] = {-0.070f, 0, 0.070f};
+                latest_input.target_x= latest_input.target_x+spreading[i+12];
+                latest_input.target_y= latest_input.target_y+spreading[i+12];
+                vec2 new_dir = normalize(vec2(latest_input.target_x, latest_input.target_y));
                 float a = get_angle(direction);
                 a += spreading[i+2];
                 float v = 1-(abs(i)/(float)grenade_shotspread);
-                float speed = mix((float)tuning.shotgun_speeddiff, 1.0f, v);
+                float speed = mix((float)tuning.grenade_speed, 1.0f, v);
                 projectile *proj = new projectile(WEAPON_GRENADE,
                     client_id,
                     projectile_startpos,
-                    vec2(cosf(a), sinf(a))*speed,
+                    new_dir,
                     (int)(server_tickspeed()*tuning.grenade_lifetime),
                     this,
                     1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
-
+                    
                 // pack the projectile and send it to the client directly
                 NETOBJ_PROJECTILE p;
                 proj->fill_info(&p);
-
-                msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
-                msg_pack_int(1);
+                
                 for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
                     msg_pack_int(((int *)&p)[i]);
             }
+
             msg_pack_end();
-            server_send_msg(client_id);
+            server_send_msg(client_id);                    
+            
             create_sound(pos, SOUND_GRENADE_FIRE);
         } break;
if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);