11 #define ENTITY_MAX_ENTITIES (MAX_ROBOT_TYPES + MAX_POWERUP_TYPES)
13 hashtable entity_hash;
14 entity *entity_list[ENTITY_MAX_ENTITIES];
18 void entity_add(ubyte object_type, int object_id, char object_name[16])
24 strcpy(entity_name, Object_type_names[object_type]);
25 p = strchr(entity_name, ' ');
27 p = strchr(entity_name, '\0');
30 strcpy(p, object_name);
33 MALLOC(ent, entity, 1);
34 ent->name = d_strdup(entity_name);
35 ent->object_type = object_type;
36 ent->object_number = object_id;
38 hashtable_insert(&entity_hash, ent->name, Num_entities);
39 con_printf(CON_DEBUG, "entity_add: added %s\n", ent->name);
41 entity_list[Num_entities++] = ent;
45 static void entity_add_object_type(ubyte object_type, char typenames[][16], int num)
49 for (i = 0; i < num; i++)
51 if (!typenames[i] || !typenames[i][0])
54 entity_add(object_type, i, typenames[i]);
59 entity *entity_find(const char *entity_name)
63 i = hashtable_search( &entity_hash, entity_name );
68 return entity_list[i];
72 void entity_cmd_report_entities(int argc, char **argv)
79 for (i = 0; i < Num_entities; i++)
80 con_printf(CON_NORMAL, " %s\n", entity_list[i]->name);
87 void entity_cmd_create(int argc, char **argv)
92 vms_vector new_velocity, new_pos;
94 ubyte ctype = 0, mtype = 0, rtype = 0;
99 ent = entity_find(argv[1]);
104 vm_vec_scale_add(&new_velocity, &ConsoleObject->mtype.phys_info.velocity, &ConsoleObject->orient.fvec, i2f(SPIT_SPEED));
107 if (Game_mode & GM_MULTI)
109 if (Net_create_loc >= MAX_NET_CREATE_OBJECTS)
111 con_printf(CON_NORMAL, "ent_create: Not enough slots\n");
117 switch (ent->object_type) {
119 objsize = Powerup_info[ent->object_number].size;
125 objsize = Polygon_models[Robot_info[ent->object_number].model_num].rad;
135 // there's a piece of code which lets the player pick up a powerup if
136 // the distance between him and the powerup is less than 2 time their
137 // combined radii. So we need to create powerups pretty far out from
139 vm_vec_scale_add(&new_pos, &ConsoleObject->pos, &ConsoleObject->orient.fvec, ConsoleObject->size + objsize);
141 objnum = obj_create( ent->object_type, ent->object_number, ConsoleObject->segnum, &new_pos, &vmd_identity_matrix, objsize, ctype, mtype, rtype);
144 con_printf(CON_NORMAL, "ent_create: cannot create. Aborting.\n");
149 obj = &Objects[objnum];
151 switch (ent->object_type) {
153 obj->mtype.phys_info.velocity = new_velocity;
154 obj->mtype.phys_info.drag = 512;
155 obj->mtype.phys_info.mass = F1_0;
157 obj->mtype.phys_info.flags = PF_BOUNCE;
159 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
160 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
161 obj->rtype.vclip_info.framenum = 0;
163 obj->ctype.powerup_info.flags |= PF_SPAT_BY_PLAYER;
166 obj->mtype.phys_info.velocity = new_velocity;
167 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
168 obj->rtype.pobj_info.subobj_flags = 0;
170 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
171 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
173 obj->mtype.phys_info.flags |= (PF_LEVELLING);
175 obj->shields = Robot_info[obj->id].strength;
184 static void entity_free(void)
186 while (Num_entities--) {
187 d_free(entity_list[Num_entities]->name);
188 d_free(entity_list[Num_entities]);
191 hashtable_free(&entity_hash);
195 void entity_init(void)
197 hashtable_init(&entity_hash, ENTITY_MAX_ENTITIES);
199 entity_add_object_type(OBJ_ROBOT, Robot_names, N_robot_types);
200 entity_add_object_type(OBJ_POWERUP, Powerup_names, N_powerup_types);
202 cmd_addcommand("report_entities", entity_cmd_report_entities, "");
203 cmd_addcommand("ent_create", entity_cmd_create, "");