/* copyright (c) 2007 magnus auvinen */ /* copyright (c) 2009 Florent Le Coz, see README for more info */ #include #include #include #include #include #include "rambo.hpp" #include "ctf.hpp" GAMECONTROLLER_RAMBO::GAMECONTROLLER_RAMBO() { // Exchange this to a string that identifies your game mode. // DM, TDM and CTF are reserved for teeworlds original modes. gametype = "RAM"; flag = 0; tuning.laser_damage = 20; // game_flags = GAMEFLAG_TEAMS; // GAMEFLAG_TEAMS makes it a two-team gamemode } bool GAMECONTROLLER_RAMBO::on_entity(int index, vec2 pos) { if (GAMECONTROLLER::on_entity(index, pos)) return true; int team = -1; if (index == ENTITY_FLAGSTAND_RED) team = 0; if (index == ENTITY_FLAGSTAND_BLUE) return false; if (team == -1) return false; FLAG *f = new FLAG(team); f->stand_pos = pos; f->pos = pos; flag = f; return true; } int GAMECONTROLLER_RAMBO::on_character_death(class CHARACTER *victim, class PLAYER *killer, int weaponid) { int had_flag = 0; // drop flags FLAG *f = flag; if (f && killer && f->carrying_character == killer->get_character()) had_flag |= 2; if (f && f->carrying_character == victim) { game.create_sound_global(SOUND_CTF_DROP); f->drop_tick = server_tick(); f->carrying_character = 0; f->vel = vec2(0,0); had_flag |= 1; } // only the flag holder gains point when killing if (killer && killer->get_character() == f->carrying_character) killer->score += 5; return had_flag; } void GAMECONTROLLER_RAMBO::tick() { // this is the main part of the gamemode, this function is run every tick do_player_score_wincheck(); // checks for winners, no teams version FLAG *f = flag; // flag hits death-tile, reset it if(col_get((int)f->pos.x, (int)f->pos.y)&COLFLAG_DEATH) { game.create_sound_global(SOUND_CTF_RETURN); f->reset(); } // if (f->carrying_character) { // update flag position f->pos = f->carrying_character->pos; // make RAMBO have only rifle f->carrying_character->weapons[WEAPON_RIFLE].got = 1; f->carrying_character->weapons[WEAPON_SHOTGUN].got = 0; f->carrying_character->weapons[WEAPON_GUN].got = 0; f->carrying_character->weapons[WEAPON_HAMMER].got = 0; f->carrying_character->weapons[WEAPON_NINJA].got = 0; f->carrying_character->weapons[WEAPON_GRENADE].got = 0; f->carrying_character->weapons[WEAPON_RIFLE].ammo = -1; f->carrying_character->active_weapon = WEAPON_RIFLE; f->carrying_character->last_weapon = WEAPON_RIFLE; // give a point to flag holder each n seconds if ((server_tick() - f->grab_tick) % 42 == 0) { f->carrying_character->player->score += 1; if (f->carrying_character->health < 10) f->carrying_character->health += 1; } } else { CHARACTER *close_characters[MAX_CLIENTS]; int num = game.world.find_entities(f->pos, 32.0f, (ENTITY**)close_characters, MAX_CLIENTS, NETOBJTYPE_CHARACTER); for(int i = 0; i < num; i++) { if(!close_characters[i]->alive || close_characters[i]->player->team == -1 || col_intersect_line(f->pos, close_characters[i]->pos, NULL, NULL)) continue; // take the flag if(f->at_stand) { // teamscore[fi^1]++; f->grab_tick = server_tick(); } f->at_stand = 0; f->carrying_character = close_characters[i]; f->carrying_character->player->score += 1; char buf[512]; str_format(buf, sizeof(buf), "%s is the new Rambo !", server_clientname(f->carrying_character->player->client_id)); game.send_chat(-1, -2, buf); dbg_msg("game", "flag_grab player='%d:%s'", f->carrying_character->player->client_id, server_clientname(f->carrying_character->player->client_id)); } if(!f->carrying_character && !f->at_stand) { if(server_tick() > f->drop_tick + server_tickspeed()*30) { game.create_sound_global(SOUND_CTF_RETURN); f->reset(); } else { f->vel.y += game.world.core.tuning.gravity; move_box(&f->pos, &f->vel, vec2(f->phys_size, f->phys_size), 0.5f); } } } GAMECONTROLLER::tick(); }