Code: Show/Hide //11/4/03 #include "asss.h" typedef struct { int x,y; int w,h; Player in[32]; //ToDo: Might want to make this bigger } mapArea; //Interfaces local Imodman *mm; //Optional local Ilogman *lm; //Log console/file local Iplayerdata *pd; //FOR_EACH_PLAYER(p) macro local Imainloop *mainloop; //Periodic callbacks //My globals //ToDo: Add your own areas here local mapArea AmmoArea; //Prototypes local void makeArea(mapArea *are, int x, int y, int w, int h); local void insArea(mapArea *area, Player *p); local void rmArea(mapArea *area, Player *p); local int bInArea(mapArea *area, Player *p); local void lsArea(mapArea *area); //Must be called to setup the struct local void makeArea(mapArea *area, int x, int y, int w, int h) { int i; area->x = x; area->y = y; area->w = w; area->h = h; for(i=0; i<32; i++) { area->in[i].pid = -1; } } //Add player. Can call if no more space local void insArea(mapArea *area, Player *p) { int i; rmArea(area, p); //No duplicates wanted for(i=0; i<32; i++) { if (area->in[i].pid == -1) { area->in[i] = *p; return; } } } //Remove player. Can call if player doesn't exist local void rmArea(mapArea *area, Player *p) { int i; for(i=0; i<32; i++) { if (area->in[i].pid == p->pid) { area->in[i].pid = -1; return; } } } //bool/boolean/Boolean is screwed in Dev-C++ local int bInArea(mapArea *area, Player *p) { int tx, ty; if (p->p_ship == 8) return 0; //In spec tx = p->position.x / 16; ty = p->position.y / 16; if (tx < area->x) return 0; if (tx > area->x + area->w) return 0; if (ty < area->y) return 0; if (ty > area->y + area->h) return 0; return 1; } //Dumps to log local void lsArea(mapArea *area) { int i; if (!lm) return; //Safety for(i=0; i<32; i++) { if (area->in[i].pid == -1) continue; //ToDo: Put your own module name here lm->Log(L_INFO, "<hioctane> lsArea: %s", area->in[i].name); } } //You might want a timer for each area and stagger them or you // could put all your areas into one timer (could get slow?) local int checkHotspot() { local Link *link; //used by macro Player *p; if (!pd) return 1; //Safety pd->Lock(); FOR_EACH_PLAYER(p){ if (bInArea(&AmmoArea, p)) { insArea(&AmmoArea, p); //ToDo: make your own sendPrize // or PM for it (if your desperate) sendPrize(p, PRIZE_SUPER); sendPrize(p, PRIZE_FULLCHARGE); } else rmArea(&AmmoArea, p); } pd->Unlock(); return 1; } //This is what Asss can see and calls //ToDo: Put your own module name here (MM_ prefix of course) EXPORT int MM_hioctane(int action, Imodman *mm_, Arena *arena) { int result = MM_OK; //FAIL; //Act on the action flags switch(action) { case MM_LOAD: //Save Imodman pointer (optional) mm = mm_; //Get interfaces (access to functions in other modules) lm = mm->GetInterface(I_LOGMAN, ALLARENAS); pd = mm->GetInterface(I_PLAYERDATA, HOMEARENA); mainloop = mm->GetInterface(I_MAINLOOP, HOMEARENA); //ToDo: Check interface validity //ToDo: Add your own areas here //533,428 to 544,435 makeArea(&AmmoArea, 533,428, 11,7); mainloop->SetTimer(checkHotspot, 800, 175, NULL, HOMEARENA); result = MM_OK; break; //ToDo: Other cases here (like MM_UNLOAD) default: result = MM_OK; break; } return result; } |
Grelminar wrote: |
6. "local Link *link" is very bad: local is #defined to be static (I picked up that bit from zlib). It should be used only for functions, indicating that they're local to a particular .c file. Blame C for giving 4 different meanings to the keyword "static", but still use it correctly. |
Grelminar wrote: |
8. you don't clean up after yourself in MM_UNLOAD. |
Grelminar wrote: |
9. this duplicates a lot of work that I did a while ago and already exists in asss: look at the region stuff in mapdata.c. |