Example #1
0
void npc::pick_name()
{
 std::stringstream ss;
 ss << random_first_name(male) << " " << random_last_name();
 name = ss.str();
}
Example #2
0
int creature_init(struct t_creature* o_entity, struct t_creature_generate_rules* genrules) {

    memset(o_entity,0,sizeof(struct t_creature));

    if ((genrules == NULL) || (genrules->gender = EG_RANDOM) || !vrange(&genrules->age)) {
	random_gender_and_age(&o_entity->age, &o_entity->gender_id); }
    else {
	if ((genrules) || vrange(&genrules->age)) {
	    o_entity->age = randrange(&genrules->age); } else o_entity->age = 18 + randval(40);


	enum entity_gender g_gender = genrules ? genrules->gender : EG_RANDOM;

	switch (g_gender) {
	    case EG_MALE: o_entity->gender_id = EG_MALE; break;
	    case EG_FEMALE: o_entity->gender_id = EG_FEMALE; break;
	    case EG_WMPATRIARCH: o_entity->gender_id = EG_WMPATRIARCH; break; //will be replaced with male after the name is generated.
	    case EG_NEUTRAL:
				 o_entity->gender_id = EG_NEUTRAL; o_entity->gender_bio = randbetween(EG_MALE,EG_FEMALE); break;
	    case EG_MBIAS:
				 o_entity->gender_id = (randval(100) < 75) ? EG_MALE : EG_FEMALE; break;
	    case EG_FBIAS:
				 o_entity->gender_id = (randval(100) < 75) ? EG_MALE : EG_FEMALE; break;
	    case EG_RANDOM:
	    default:
				 o_entity->gender_id = (randval(100) < 52) ? EG_FEMALE : EG_MALE; break; //52% females according to U.S. Census data
	}
    }

    if ((randval(100) < 1) && (o_entity->gender_bio == EG_RANDOM))
	o_entity->gender_bio = randbetween(EG_NEUTRAL,EG_FEMALE); else o_entity->gender_bio = o_entity->gender_id; //will result in mismatches for 0.67% of cases.

    o_entity->birthday_month = randval(12) + 1;

    switch(o_entity->birthday_month)
    {
	case 4:
	case 6:
	case 9:
	case 11:
	    o_entity->birthday_day=randval(30)+1;
	    break;
	case 2:
	    o_entity->birthday_day=randval(28)+1;
	    break;
	default:
	    o_entity->birthday_day=randval(31)+1;
	    break;
    }

    o_entity->id=curcreatureid++;

    for(int w=0;w<EB_COUNT;w++)o_entity->wound[w]=0;

    for(int a=0;a<EA_COUNT;a++)o_entity->attributes[a]=1;

    int attnum=32;

    if (genrules) {

	o_entity->type = genrules->type;

	for (int i=0; i < RANDATTRS; i++)
	    if (vrange(&genrules->attrlim[i])) o_entity->attributes[genrules->attrs[i]] = randrange(&genrules->attrlim[i]);
	for (int i=0; i < RANDSKILLS; i++)
	    if (vrange(&genrules->skilllim[i])) o_entity->skills[genrules->skill[i]] = randrange(&genrules->skilllim[i]);

	enum Alignment align = genrules->align;

	if (genrules->random_align) align += randbetween(-2,2);

	if (align < ALIGN_ARCHCONSERVATIVE) align = ALIGN_ARCHCONSERVATIVE;
	if (align > ALIGN_ELITELIBERAL) align = ALIGN_ELITELIBERAL;

	o_entity->align = align;
	o_entity->orig_align = align;

	if (vrange(&genrules->juice)) o_entity->juice = randrange(&genrules->juice);
	if (vrange(&genrules->money)) o_entity->money = randrange(&genrules->money);

	for (int i=0; i < RANDATTRS; i++)
	    if (vrange(&genrules->attrlim[i])) o_entity->attributes[genrules->attrs[i]] = randrange(&genrules->attrlim[i]);
	for (int i=0; i < RANDSKILLS; i++)
	    if (vrange(&genrules->skilllim[i])) o_entity->skills[genrules->skill[i]] = randrange(&genrules->skilllim[i]);
	if (vrange(&genrules->attrpts)) attnum = randrange(&genrules->attrpts); 

    }

    while(attnum>0)
    {
	int a=randval(EA_COUNT);
	if(o_entity->attributes[a]<10)
	{
	    o_entity->attributes[a]++;
	    attnum--;
	}
    }

    //at this point, both the entity's alignment and gender are fixed.
    //let's generate a name.

    random_first_name(o_entity->firstname,o_entity->gender_id);
    random_last_name(o_entity->lastname,o_entity->align == ALIGN_ARCHCONSERVATIVE,o_entity->gender_id);

    int wi=0; int wn=0;

    while ((wi < RANDWEAPONS) && (genrules->weapons[wi])) {
	wn++; wi++; }

    if (wn) {
    
    wi = randval(wn);

    struct t_item new_weapon = {.type = IT_WEAPON, .itemtypeid = genrules->weapons[wi], .ammo = 200};
    
    struct t_item clips = {.type = IT_CLIP, .itemtypeid = weapontypes[genrules->weapons[wi]].attacks[0].ammotype, .ammo = cliptypes[weapontypes[genrules->weapons[wi]].attacks[0].ammotype].ammo };


    struct t_item* added_weapon = inv_add(o_entity->inventory, &new_weapon);
    o_entity->weapon = added_weapon;

    }

    o_entity->special[ESW_TEETH]=TOOTHNUM;
    o_entity->special[ESW_RIGHTEYE]=1;
    o_entity->special[ESW_LEFTEYE]=1;
    o_entity->special[ESW_NOSE]=1;
    o_entity->special[ESW_TONGUE]=1;
    o_entity->special[ESW_RIGHTLUNG]=1;
    o_entity->special[ESW_LEFTLUNG]=1;
    o_entity->special[ESW_HEART]=1;
    o_entity->special[ESW_LIVER]=1;
    o_entity->special[ESW_STOMACH]=1;
    o_entity->special[ESW_RIGHTKIDNEY]=1;
    o_entity->special[ESW_LEFTKIDNEY]=1;
    o_entity->special[ESW_SPLEEN]=1;
    o_entity->special[ESW_RIBS]=RIBNUM;
    o_entity->special[ESW_NECK]=1;
    o_entity->special[ESW_UPPERSPINE]=1;
    o_entity->special[ESW_LOWERSPINE]=1;

    o_entity->blood = 100;
    o_entity->alive = true;
    o_entity->exists = true;

    return 0;
}

int entity_name(struct t_creature* who) {
    random_first_name(who->firstname,who->gender_id);
    random_last_name(who->lastname,who->align == ALIGN_ARCHCONSERVATIVE,who->gender_id);
    return 0;
}

char* entityattrstr[EA_COUNT] = {
    "STR",
    "INT",
    "WIS",
    "AGI",
    "CON",
    "CHA",
    "HRT"
};

const char* safe_name(const char* nameptr) {
    if ((nameptr == NULL) || (strlen(nameptr) == 0)) return "???";
    return nameptr;
}

int describe_entity(struct t_creature* me, char* const restrict o_name, size_t strsize) {
    if (me != NULL) {
	if (strlen(me->nickname) != 0) {
	    strncpy(o_name,me->nickname,strsize);
	    return 0;}

	if (((strlen(me->firstname) != 0) || (strlen(me->firstname) != 0)) && (me->name_known)) {
	    char fullname[66];
	    strncpy(fullname,safe_name(me->firstname),32);
	    strncat(fullname," ",1);
	    strncat(fullname,safe_name(me->lastname),32);
	    strncpy(o_name,fullname,strsize);
	    return 0; }

	const char* td = type_description(me);

	if (td) { strncpy(o_name,type_description(me),strsize); return 0; }

    }
    strncpy(o_name, "*",32);
    return 0;
}

char temp_name[16][128];
int temp_name_i = 0;

const char* describe_entity_static(struct t_creature* me) {
    int r = describe_entity(me,temp_name[temp_name_i],128);
    const char* ret = (r == 0 ? temp_name[temp_name_i] : NULL);
    temp_name_i = (temp_name_i+1) % 16;
    return ret;
}