void Tournament::spawn_object(GSpawnObject *so) { try { Object *obj = resources.get_object(so->object_name); spawn_object(obj, so->id, static_cast<int>(so->x), static_cast<int>(so->y), so->flags); } catch (const Exception& e) { subsystem << e.what() << std::endl; } }
/** * @brief Spawn a monster - e.g. make a copy of a monster definition and make that copy ready to be deployed. * HP for the monster will be slightly and randomly adjusted, to provide less predictability/more randomness. * * @param n Number of the monsterdef to use * @param head Pointer to the head of the list of monsters which this monster is to be inserted into. * @param maxlevel Maximum level of the monster to be created. */ void spawn_monster(int n, monster_t *head, int maxlevel) { monster_t *tmp; int hpadj, x; char string[50]; obj_t *o; tmp = head->next; head->next = gtmalloc(sizeof(monster_t)); *head->next = get_monsterdef(n); hpadj = head->next->level * 2; head->next->maxhp += ri((-(hpadj/2)), hpadj); head->next->hp = head->next->maxhp; head->next->next = tmp; head->next->prev = head; head->next->head = head; setbit(head->next->flags, MF_SLEEPING); head->next->viewradius = 12; if(head->next->inventory) { if(head->next->inventory->object[0]) { strcpy(string, head->next->inventory->object[0]->basename); unspawn_object(head->next->inventory->object[0]); x = get_objdef_by_name(string); o = spawn_object(x, 0); head->next->inventory->object[0] = o; head->next->weapon = o; } if(head->next->inventory->gold) head->next->inventory->gold = ri(1, 1 + head->next->inventory->gold); } //gtprintf("spawned monster %s\n", head->next->name); mid_counter++; head->next->mid = mid_counter; }
void Tournament::spawn_frog() { size_t sz = frog_spawn_points.size(); if (sz) { /* if a frog is already in map, leave */ for (GameObjects::iterator it = game_objects.begin(); it != game_objects.end(); it++) { GameObject *gobj = *it; if (gobj->object->get_type() == Object::ObjectTypeFrog) { return; } } /* spawn object */ try { Object *obj = resources.get_object("frog"); int index = rand() % sz; GameObject *gobj = frog_spawn_points[index]; identifier_t id = get_free_object_id(); spawn_object(obj, id, gobj->origin_x, gobj->origin_y, 0); GSpawnObject *spwn = new GSpawnObject; memset(spwn, 0, sizeof(GSpawnObject)); spwn->flags = PlaceObjectWithAnimation | PlaceObjectWithSpawnSound; spwn->id = id; strncpy(spwn->object_name, obj->get_name().c_str(), NameLength - 1); spwn->x = static_cast<pos_t>(gobj->origin_x); spwn->y = static_cast<pos_t>(gobj->origin_y); spwn->to_net(); add_state_response(GPCSpawnObject, GSpawnObjectLen, spwn); } catch (const Exception& e) { subsystem << e.what() << std::endl; } } }
int parse_monsters() { config_setting_t *cfg_monsters; int i, j, boolval, tmp, id; char sname[100]; const char *value; char string[50]; cfg_monsters = config_lookup(cf, "monsters"); i = config_setting_length(cfg_monsters); game->monsterdefs = i; printf("Parsing monster file... We have %d monsters", i); /* * main monster parsing loop * goes through each possible setting, looks it up in the cfg file * and adds it to a monster structure which is then placed in the * linked list monsterdefs. */ for(j=0;j<i;j++) { monster_t *m; m = (monster_t *) gtmalloc(sizeof(monster_t)); id = j+1; sprintf(sname, "monsters.[%d].name", j); config_lookup_string(cf, sname, &value); strcpy(m->name, value); sprintf(sname, "monsters.[%d].str", j); config_lookup_int(cf, sname, &(m->attr.str)); sprintf(sname, "monsters.[%d].phy", j); config_lookup_int(cf, sname, &(m->attr.phy)); sprintf(sname, "monsters.[%d].intl", j); config_lookup_int(cf, sname, &(m->attr.intl)); sprintf(sname, "monsters.[%d].wis", j); config_lookup_int(cf, sname, &(m->attr.wis)); sprintf(sname, "monsters.[%d].dex", j); config_lookup_int(cf, sname, &(m->attr.dex)); sprintf(sname, "monsters.[%d].cha", j); config_lookup_int(cf, sname, &(m->attr.cha)); sprintf(sname, "monsters.[%d].appearance", j); config_lookup_string(cf, sname, &value); m->c = (char) *value; sprintf(sname, "monsters.[%d].level", j); config_lookup_int(cf, sname, &(m->level)); sprintf(sname, "monsters.[%d].hp", j); config_lookup_int(cf, sname, &(m->hp)); m->maxhp = m->hp; sprintf(sname, "monsters.[%d].speed", j); config_lookup_int(cf, sname, &(m->speed)); sprintf(sname, "monsters.[%d].havegold", j); if(config_lookup_bool(cf, sname, &boolval)) if(boolval) setbit(m->flags, MF_CANHAVEGOLD); sprintf(sname, "monsters.[%d].useweapon", j); if(config_lookup_bool(cf, sname, &boolval)) if(boolval) setbit(m->flags, MF_CANUSEWEAPON); sprintf(sname, "monsters.[%d].usearmor", j); if(config_lookup_bool(cf, sname, &boolval)) if(boolval) setbit(m->flags, MF_CANUSEARMOR); sprintf(sname, "monsters.[%d].aitype", j); config_lookup_int(cf, sname, &tmp); m->ai = aitable[tmp]; m->mid = tmp; // for monsterdefs, mid holds aitableindex m->id = id; m->viewradius = 12; // temporary solution?! // Let's give the monster a weapon! if(hasbit(m->flags, MF_CANUSEWEAPON)) { int x; obj_t *o; sprintf(sname, "monsters.[%d].weapon", j); config_lookup_string(cf, sname, &value); strcpy(string, value); x = get_objdef_by_name(string); m->inventory = init_inventory(); o = spawn_object(x, 0); m->inventory->object[0] = o; m->weapon = o; } if(hasbit(m->flags, MF_CANHAVEGOLD)) { if(!m->inventory) m->inventory = init_inventory(); m->inventory->gold += ri(0, 15*m->level); } //if(m->weapon) //fprintf(stderr, "DEBUG: %s:%d - %s has the weapon called a %s\n", __FILE__, __LINE__, m->name, m->weapon->basename); /* * the following was written in one go, it's beautiful and seems totally bugfree!! */ m->head = monsterdefs->head; monsterdefs->next = m; m->next = NULL; m->prev = monsterdefs; monsterdefs = m; printf("."); // "progress bar" } printf(" OK\n"); monsterdefs->head->x = i; // store number of monsters in x of head. return 0; }