Server Help

ASSS Custom Projects - damage (binaries only)

Smong - Tue Sep 26, 2006 12:29 pm
Post subject: damage (binaries only)
I have decided to release binaries of my damage module so others can experiment with it.

You can track damage on bots (like in my Pirates! zone) and you can also track damage on tiles (I'm planning to release my BF2142 project which has code examples for the tile damage).

It tracks, bullets, bombs, mines and thors. Although double barrel bullets aren't implemented. Bouncing stuff is implemented.

Here is the interface:
Code: Show/Hide
/** called when a tracked player is killed */
typedef void (*KilledFunc)(Player *p, Player *killer, void *clos);

/** user module must set new x and y coords for this players position. */
typedef void (*RespawnFunc)(Player *p, void *clos);

/** called when a tile in a tracked region takes damage. x and y are the tile
* damage is the amount of damage taken, freq is the owner of the weapon,
* wtype is the type of the weapon that did the damage, see packets/ppk.h for
* weapon types. */
typedef void (*TileDamageFunc)(Arena *arena, int x, int y, int damage,
      int freq, int wtype, void *clos);

/** the interface id for damage */
#define I_DAMAGE "damage-2"

/** the damage interface struct */
typedef struct Idamage
{
   INTERFACE_HEAD_DECL

   /** pos will get modified if this player is effected by a weapon,
    * killfunc will get called when this player dies. currently
    * killfunc is optional but respawnfunc is required. */
   void (*AddFake)(Player *p, struct C2SPosition *pos,
         KilledFunc killfunc, RespawnFunc respawnfunc, void *clos);
   void (*RemoveFake)(Player *p);

   /** call this when the fake player enters a safe zone or fires a weapon */
   void (*FakePosition)(Player *p, struct C2SPosition *pos, int len);

   void (*AddRegion)(Arena *arena, Region *rgn, TileDamageFunc tilefunc,
         void *clos);
   void (*RemoveRegion)(Arena *arena, Region *rgn);
} Idamage;


When tracking bot damage you are supposed to provide a pointer to the bot's "struct C2SPosition *pos". As in both your module and the damage module will be using the same piece of mem.

Tile damage works per region. You should paint your region on and adjacent to the tiles you are interested in for good measure.
Bak - Tue Sep 26, 2006 1:16 pm
Post subject:
Quote:
this module is closed source due to the amount of effort I put into it.


icon_sad.gif
Smong - Sat Oct 14, 2006 7:10 am
Post subject:
Example of tracking damage on fake players:
http://forums.minegoboom.com/viewtopic.php?p=66152#66152
Smong - Thu May 17, 2007 3:33 pm
Post subject:
Update
Kill callback is now asynchronous so you can safely call Add/RemoveFake inside it without a deadlock occuring.
Also added more checks if a tracked player is moved to spec.

The interface hasn't changed so it shouldn't be necessary to recompile any modules that use the damage module.
Smong - Sun Jun 10, 2007 8:02 am
Post subject:
Update
Fixed bots not reloading settings when spawning out of spec.
Made the tile damage callback asynchronous for the same reasons as before.
Fixed possible crash when running on windows and an arena is destroyed.
Smong - Wed Jul 04, 2007 6:05 pm
Post subject:
Update
Added arena setting: Damage:IgnoreTeamDamage (default: 0).
Added support for some of the special tiles.
JoWie - Wed Jul 04, 2007 6:25 pm
Post subject:
Smong wrote:
Update
Added arena setting: Damage:IgnoreTeamDamage (default: 0).
Added support for some of the special tiles.


thank you
JoWie - Sat Sep 15, 2007 6:42 am
Post subject:
Could you recompile this for 1.4.4?
Smong - Sat Sep 15, 2007 9:34 am
Post subject:
Ok.
Anonymous - Wed Mar 05, 2008 9:37 pm
Post subject: Smong, can you add a CB to your damage module?
The reason I ask is because I want to make all bombs do exactly 1000 damage to bots regardless of where they hit, and this isn't possible (to my knowledge) using regular ss settings. I could use a watchdamage callback (I think?) to do this, but it seems kind of redundant to have 2 damage watches on each bot, not to mention performance-draining and ugly coding.
-JP
Smong - Thu Mar 06, 2008 12:55 pm
Post subject:
Sorry is there a question in there? Were you asking for a modification to this module? Watchdamage only works on the contiuum client.
Anonymous - Thu Mar 06, 2008 4:24 pm
Post subject:
Er, I wrote the first part in the subject line which is barely noticeable.
It should read:
Smong, can you add a CB to your damage module?
The reason I ask is because I want to make all bombs do exactly 1000 damage to bots regardless of where they hit, and this isn't possible (to my knowledge) using regular ss settings. I could use a watchdamage callback (I think?) to do this, but it seems kind of redundant to have 2 damage watches on each bot, not to mention performance-draining and ugly coding.
-JP
Smong - Fri Mar 07, 2008 2:04 pm
Post subject:
Ok I might look into adding a callback for bot damage this weekend. The main reason I didn't do it in the first place is some weapon settings could cause it to spam callbacks causing a performance hit on the server.
Goldeye - Wed May 20, 2009 7:25 am
Post subject:
Any chance of getting the source for this, Smong? icon_smile.gif
JoWie - Sun Jul 26, 2009 5:45 pm
Post subject:
Update

(everything else in this module is made by smong)

Contact me, not smong for any issues with this release.
Bak - Sun Jul 26, 2009 7:36 pm
Post subject:
How did you get the source?
Initrd.gz - Sun Jul 26, 2009 9:37 pm
Post subject:
Bak wrote:
How did you get the source?

Its a trojan dont download! </sarcasm>

Really how did you?
JoWie - Mon Jul 27, 2009 5:57 am
Post subject:
I asked smong... But he asked me not to release the source.

We needed the source for Command & Conquer because we will most likely move to a different server which requires a recompile in a few weeks. There are also some issues that need to be resolved. (for example, i want to track energy myself, so I am going to add a callback for fake players in the same way as in TileDamageFunc).
So because smong kinda left subspace he gave us the source

Also, for those interested, the following things are not (yet) implemented in damage:


Currently, on my todo list is the callback I mentioned above, bricks, multifire and double barrel
JoWie - Wed Jul 29, 2009 9:23 am
Post subject:
Update



The interface has changed! So you will need to modify and recompile any modules that uses damage
Dr Brain - Wed Jul 29, 2009 6:18 pm
Post subject:
I don't think anyone else uses this, because it's so limited and can't be extended (because of the closed source). I know at least HS and HZ can't use it, because it isn't compiled against our cores. Add to the fact that it's author has left the game, and I doubt you'll get many takers.
JoWie - Thu Jul 30, 2009 6:23 am
Post subject:
Above changes is what I needed myself. All I did extra is upload it here.

I will be willing to help others compile. But it still creates a dependency on a 3rd party (me/smong). Which is one of the reasons I wanted the source myself.

I would have put up the source if smong hadn't asked not to do so.
Chambahs - Sat Aug 29, 2009 3:14 pm
Post subject:
id sell the source to the highest bidder, ive got a copy, no lies.
JoWie - Sun Feb 21, 2010 4:33 pm
Post subject:


I have tested a bunch of radius' and they match up to continuum.
Modified so that it makes sense out of context:
Code: Show/Hide

offset2 = shipradius * 0.7;
if (shipradius == 14) // special case, probably for VIE compatability
   offset1 = offset2;
else
   offset1 = offset2 + 1;

sin(i * PI / 20)
// double barrel 1(left one with rot = 0)
barrel1->x += round(offset1 * ( sin(((pos->rotation + 30) % 40) * PI / 20) ));
barrel1->y -= round(offset1 * ( sin(pos->rotation) * PI / 20 ));

// double barrel 2 (right one with rot = 0)
barrel2->x -= round(offset2 * ( sin(((pos->rotation + 30) % 40) * PI / 20) ));
barrel2->y += round(offset2 * ( sin(pos->rotation) * PI / 20 ));

When one of the barrels hits a player, both are removed, only one counts for damage.


Will compile windows version if needed
Cheese - Mon Feb 22, 2010 12:29 am
Post subject:
im curious, because a bunch of my 1.4.4 modules do not work with 1.5, what did you change to make it work?


also:
1 radius + 1 radius = 2 radii
:)
JoWie - Mon May 24, 2010 12:10 pm
Post subject:


Linux version is compiled against trunk 1137. Windows version is compiled against the ASSS 1.5.0rc2 release.

Example:
Code: Show/Hide

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include "asss.h"
#include "damage.h"

static Imodman      *mm;
static Iarenaman    *aman;
static Iplayerdata   *pd;
static Idamage      *damage;
static Ilogman      *lm;

static int arenaKey  = -1;
static int playerKey = -1;

struct ArenaData
{

};

#define PlayerData PlayerData_
struct PlayerData
{
   Arena *arena;
};


static struct ArenaData* GetArenaData(Arena *arena)
{

        struct ArenaData *adata = P_ARENA_DATA(arena, arenaKey);



        return adata;
}

static struct PlayerData* GetPlayerData(Player *p)
{
        struct PlayerData *pdata = PPDATA(p, playerKey);


        if (p->arena && p->arena != pdata->arena)
        {
                pdata->arena = p->arena;
           //...
        }
        return pdata;
}

static void newWeaponCB(Arena *arena, DamageWeapon *wpn)
{
   lm->LogP(L_INFO, "damagetest", wpn->p, "Added a weapon (%p) at %d, %d", wpn, wpn->x / 1000, wpn->y / 1000);
}

static void removeWeaponCB(Arena *arena, DamageWeapon *wpn, u8 removereason)
{
   const char *reason;
   switch (removereason)
   {
      case DAMAGE_REMOVEWPN_HIT:
         reason = "Hit a tile";
      break;
      case DAMAGE_REMOVEWPN_HITPLAYER:
         reason = "Hit a player";
      break;
      case DAMAGE_REMOVEWPN_OTHERBARRELHIT:
         reason = "Other barrel hit a player";
      break;
      case DAMAGE_REMOVEWPN_SHIPFREQCHANGE:
         reason = "Firer changed ship / freq";
      break;
      case DAMAGE_REMOVEWPN_LEAVEARENA:
         reason = "Firer left the arena";
      break;
      case DAMAGE_REMOVEWPN_EXPIRED:
         reason = "Weapon expired";
      break;
      case DAMAGE_REMOVEWPN_SAFEZONE:
         reason = "Firer entered a safe zone";
      break;
      default:
         reason = "UNKNOWN";
      break;
   }

   lm->LogP(L_INFO, "damagetest", wpn->p, "Removed a weapon(%p) at %d, %d. Because: %s", wpn, wpn->x / 1000, wpn->y / 1000, reason);
}

static void weaponsUpdatedCB(Arena *arena, ticks_t now)
{
   static DamageWeapon* lastFound = NULL;
   DamageWeapon *wpn;
   Link *link;

   damage->WeaponLock(arena);
   FOR_EACH_DAMAGEWEAPON(wpn, arena)
   {
      if (wpn->wpn.type == W_THOR)
      {
         if (wpn != lastFound)
         {
            lm->LogA(L_INFO, "damagetest", arena, "Found a thor while looping over all the current weapons! (only displayed once)");
            lastFound = wpn;
         }

         break;
      }
   }
   damage->WeaponUnlock(arena);
}


EXPORT const char info_template[] = "DamageTest";
static void ReleaseInterfaces()
{
        mm->ReleaseInterface(aman   );
        mm->ReleaseInterface(pd     );
        mm->ReleaseInterface(damage );
        mm->ReleaseInterface(lm     );

}

EXPORT int MM_damagetest(int action, Imodman *mm_, Arena *arena)
{
        if (action == MM_LOAD)
        {
                mm      = mm_;
                aman    = mm->GetInterface(I_ARENAMAN        , ALLARENAS);
                pd      = mm->GetInterface(I_PLAYERDATA      , ALLARENAS);
                damage  = mm->GetInterface(I_DAMAGE        , ALLARENAS);
                lm      = mm->GetInterface(I_LOGMAN        , ALLARENAS);


                if (!aman || !pd || !damage || !lm)
                {
                        ReleaseInterfaces();
                        printf("<damagetest> Missing interfaces");
                        return MM_FAIL;
                }

                arenaKey = aman->AllocateArenaData(sizeof(struct ArenaData));
                playerKey = pd->AllocatePlayerData(sizeof(struct PlayerData));

                if (arenaKey == -1 || playerKey == -1) // check if we ran out of memory
                {
                        if (arenaKey  != -1) // free data if it was allocated
                                aman->FreeArenaData(arenaKey);

                        if (playerKey != -1) // free data if it was allocated
                                pd->FreePlayerData (playerKey);

                        ReleaseInterfaces();

                        return MM_FAIL;
                }

                return MM_OK;

        }
        else if (action == MM_UNLOAD)
        {


                aman->FreeArenaData(arenaKey);
                pd->FreePlayerData(playerKey);

                ReleaseInterfaces();

                return MM_OK;
        }
        else if (action == MM_ATTACH)
        {
      damage->AddWeaponCallback(arena, newWeaponCB, removeWeaponCB, weaponsUpdatedCB);

                return MM_OK;
        }
        else if (action == MM_DETACH)
        {
      damage->RemoveWeaponCallback(arena, newWeaponCB, removeWeaponCB, weaponsUpdatedCB);

                return MM_OK;
        }

        return MM_FAIL;
}



Cheese - Thu Jun 10, 2010 3:24 am
Post subject:
does AddFake() make a new fake player, or does it have to exist already?
because #2 is better
JoWie - Thu Jun 10, 2010 4:27 am
Post subject:
It has to exist already... This is why the first argument is "Player *"
Cheese - Thu Jun 10, 2010 1:54 pm
Post subject:
whats the "void *clos" thingy for in each function?

also, how is damage->KillFake() different from game->FakeKill(), and why should i use it instead?
JoWie - Thu Jun 10, 2010 3:24 pm
Post subject:
void *clos is used the same way as in the rest of ASSS. In AddFake and AddRegion you can pass it anything you want. When the callback is called, it is passed back to you.


game->FakeKill() simply notifies players the fake has died. There are no callbacks or any other logic behind it, it only sends a packet.

damage->KillFake fires CB_KILL and CB_KILL_POST_NOTIFY, sends the packet, stops the bot from tracking damage (aka being in the way), resets some internal states (so it can respawn).
Cheese - Thu Jun 10, 2010 4:31 pm
Post subject:
also, since this is closed source, theres no indication anywhere about what i type after ?insmod...
i believe spidernl had this issue as well.

and why does AddFake need a position struct parameter if it has the player pointer, which has it already?
Cheese - Fri Jun 11, 2010 11:31 pm
Post subject:
does this calculate ship radius from settings, or is it hardcoded to the default 14px?

also, why does it load normally from modules.conf, but crashes almost immediately after loading successfully using ?insmod?


and it doesnt seem to take damage from bursts, why is that?
couldnt you just look at the number of shrap, then use circle-math to get their direction, then use the bounce bullet math?
JoWie - Sat Jun 12, 2010 6:19 pm
Post subject:
Cheese wrote:
does this calculate ship radius from settings, or is it hardcoded to the default 14px?

also, why does it load normally from modules.conf, but crashes almost immediately after loading successfully using ?insmod?


and it doesnt seem to take damage from bursts, why is that?
couldnt you just look at the number of shrap, then use circle-math to get their direction, then use the bounce bullet math?


It reads the ship radius from settings.
I have only seen that ?insmod crash on windows, and since I absolutely hate debugging on windows it's still there.

I posted a list of stuff that is not implemented yet, burst is one of them. Implementing burst takes more time then you think, I have to make absolutely sure the calculations are exactly the same as on continuum.
Cheese - Tue Jun 22, 2010 12:35 pm
Post subject:
i really would like to have a look at the source to see why it crashes in some places and not in others...
more confusing is that it runs on some windows machines and crashes immediately on others...
JoWie - Tue Jun 22, 2010 1:39 pm
Post subject:
This version probably solves the ?insmod crash.
Also lets you see where a weapon hit a tile.
Cheese - Tue Jun 22, 2010 2:18 pm
Post subject:
it would also be cool if there was a paramater in addfake that would let you control the respawn time, or 0 for default
JoWie - Tue Jun 22, 2010 4:55 pm
Post subject:
If you do not want it to respawn, spec it. However adding a respawn time is on the todo.

Did the crashing with insmod stop?
Cheese - Mon Aug 30, 2010 2:51 pm
Post subject:
i would like to integrate this into a bigger fake management system, all of which would modify only specific sections of a position packet.

the damage module can be seperated into two parts:
damage
energy management

additional stuff i have created:
weapons/turrets
movement/ai

something possible:
position packet + weapon sender


these five parts on top of the ASSS fake creation and messaging system together, once perfected, would allow anyone to control any aspect of a fake player that would be able to interact with players.

it would be important that the five systems would have zero overlap, so that there would be no fighting. ex: the damage module should not touch the energy, and should only inform that damage has been recieved. this also means that there will be no unnecessary overhead in each module.

since they all would use the same position packet, it would only be necessary to register it with the sender module.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group