void LuaInstance::OnCreatureDeath(Creature* pVictim, Unit* pKiller) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[INSTANCE_EVENT_ON_CREATURE_DEATH]); push_int(m_instanceId); push_unit(pVictim); push_unit(pKiller); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaInstance::OnCreaturePushToWorld(Creature* pCreature) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[INSTANCE_EVENT_ON_CREATURE_PUSH]); push_int(m_instanceId); push_unit(pCreature); lua_engine::ExecuteLuaFunction(2); RELEASE_LOCK }
void LuaInstance::OnPlayerEnter(Player* pPlayer) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[INSTANCE_EVENT_ON_PLAYER_ENTER]); push_int(m_instanceId); push_unit(pPlayer); lua_engine::ExecuteLuaFunction(2); RELEASE_LOCK }
void LuaInstance::OnGameObjectActivate(GameObject* pGameObject, Player* pPlayer) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[INSTANCE_EVENT_ON_GO_ACTIVATE]); push_int(m_instanceId); push_go(pGameObject); push_unit(pPlayer); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaInstance::OnAreaTrigger(Player* pPlayer, uint32 uAreaId) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[INSTANCE_EVENT_ON_AREA_TRIGGER]); push_int(m_instanceId); push_unit(pPlayer); push_int(uAreaId); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaInstance::OnZoneChange(Player* pPlayer, uint32 uNewZone, uint32 uOldZone) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[INSTANCE_EVENT_ON_ZONE_CHANGE]); push_int(m_instanceId); push_unit(pPlayer); push_int(uNewZone); push_int(uOldZone); lua_engine::ExecuteLuaFunction(4); RELEASE_LOCK }
void LuaCreature::OnDodged(Unit* mTarget) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_DODGED]); push_creature(_unit); push_int(CREATURE_EVENT_ON_DODGED); push_unit(mTarget); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaCreature::OnCombatStart(Unit* mTarget) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_ENTER_COMBAT]); push_creature(_unit); push_int(CREATURE_EVENT_ON_ENTER_COMBAT); push_unit(mTarget); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaCreature::OnDamageTaken(Unit* mAttacker, uint32 fAmount) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_DAMAGE_TAKEN]); push_creature(_unit); push_int(CREATURE_EVENT_ON_DAMAGE_TAKEN); push_unit(mAttacker); push_int(fAmount); lua_engine::ExecuteLuaFunction(4); RELEASE_LOCK }
void LuaCreature::OnFlee(Unit* mFlee) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_FLEE]); push_creature(_unit); push_int(CREATURE_EVENT_ON_FLEE); push_unit(mFlee); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaCreature::OnCritHit(Unit* mTarget, int32 fAmount) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_CRIT_HIT]); push_creature(_unit); push_int(CREATURE_EVENT_ON_CRIT_HIT); push_unit(mTarget); push_int(fAmount); lua_engine::ExecuteLuaFunction(4); RELEASE_LOCK }
void LuaCreature::OnBlocked(Unit* mTarget, int32 iAmount) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_BLOCKED]); push_creature(_unit); push_int(CREATURE_EVENT_ON_BLOCKED); push_unit(mTarget); push_int(iAmount); lua_engine::ExecuteLuaFunction(4); RELEASE_LOCK }
void LuaCreature::OnFear(Unit* mFeared, uint32 iSpellId) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_FEAR]); push_creature(_unit); push_int(CREATURE_EVENT_ON_FEAR); push_unit(mFeared); push_int(iSpellId); lua_engine::ExecuteLuaFunction(4); RELEASE_LOCK }
void LuaCreature::OnAssistTargetDied(Unit* mAssistTarget) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_ASSIST_TARGET_DIED]); push_creature(_unit); push_int(CREATURE_EVENT_ON_ASSIST_TARGET_DIED); push_unit(mAssistTarget); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
int main(int argc, char *argv[]) { /* the program's name, d'oh */ progname = argv[0]; /* the whole file's name */ char *fname; /* here the file's extension will be stored */ char fext[FEXT_MAX_SIZE + 1] = { 0 }; /* the unit's description (it's color, etc) */ struct unit_desc desc = {{ 0 }}; /* the user's unit */ struct unit *unit = nmalloc(sizeof(struct unit)); /* make sure there is at least one argument supplied */ if (argc < 2){ fprintf(stderr, "usage: %s <file>\n", progname); return 1; } fname = argv[1]; /* fetch the extension, and store it in `fext' */ { /* {{{ */ int i = strlen(fname) - 1; /* minus one to not start at the '\0' */ /* search for the first dot, starting from the end of the string */ int j = 0; /* puts the characters into the `fext' array */ /* set `i' to the last dot's position */ for (; fname[i] != '.' && i >= 0; i--) ; if (fname[i] == '.'){ /* we found a dot, let's see if it would fit into `fext' */ /* `i + 1' because `i' points at the dot, not at the very first character * after it */ if (strlen(fname) - (i + 1) > FEXT_MAX_SIZE){ fprintf(stderr, "%s: file extension too long (max. %u chars)\n", progname, FEXT_MAX_SIZE); return 1; } /* see if there is anything after the dot (like, if it's not something * like `filename.') */ if (fname[i + 1] == '\0'){ fprintf(stderr, "%s: file extension empty\n", progname); return 1; } } else { /* we haven't seen any dots, that's a bummer */ fprintf(stderr, "%s: file extension not found\n", progname); return 1; } /* here, everything should be all set and ready to roll */ for (i++ /* skip over the dot */; j < FEXT_MAX_SIZE; j++, i++) fext[j] = fname[i]; /* }}} */ } /* call the function that will handle the file, based on it's extension */ { /* {{{ */ struct file_handlers *p = file_handlers; int found = 0; for (; p->fext != NULL && p->handler != NULL; p++){ if (!strcmp(p->fext, fext)){ found = 1; break; } } if (found){ /* we know the extension, and can handle it */ if (p->handler(unit, &desc, fname) == NULL){ return 1; } } else { /* oops! */ fprintf(stderr, "%s: file extension `%s' not supported\n", progname, fext); return 1; } /* }}} */ } /* TODO: safety checks for the `desc' values */ unit->desc = desc; /* set the defaults */ unit->hp = UNIT_MAX_HP / 2; /* give the unit an id */ unit->id = calcid(unit); /* push the unit onto the `unit_list' */ push_unit(unit); /* call the `fetch' function to give the user his unit's id */ unit->fun.fetch(unit->id); /* initialize the SDL */ SDL_Init(SDL_INIT_EVERYTHING); /* set the title */ SDL_WM_SetCaption("Poligon", NULL); /* create the window */ SDL_Surface *screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); SDL_Event event; int running = 1; /* put the unit in the middle of the screen */ unit->x = screen->w / 2; unit->y = screen->h / 2; while (running){ /* fill the background */ SDL_FillRect(screen, NULL, 0x111111); if (SDL_PollEvent(&event)){ switch (event.type){ case SDL_QUIT: running = 0; break; } } draw_unit(screen, unit); unit->hp += sge_Random(-3, 3); /*unit->rot--;*/ /* update the screen */ SDL_UpdateRect(screen, 0, 0, 0, 0); } /* clean up after SDL */ SDL_Quit(); /* clean up after ourselves */ free_unit_list(); return 0; }