/*not telepathic, smart*/ gamestate_t nt_s(npc *monster, cell_t *cell_arr, path_node_t *c_path, character *player) { int n_x, n_y, dam; gamestate_t result; cell_t *c_cell, *n_cell; character *temp; std::stringstream mes; result = normal; c_cell = cell_arr + (MAP_WIDTH * monster->y_pos) + monster->x_pos; /*if it sees player, moves same as telpathic smart*/ if(update_sight(player, monster, cell_arr)) { return t_s(monster, cell_arr, c_path, player); } /*If monster is where last seen*/ if(monster->x_pos == monster->seen_x && monster->y_pos == monster->seen_y) { monster->seen_x = 150; } /*if it does not know where the player is, guess*/ if(monster->seen_x > 100) { monster->seen_x = random_number(1, MAP_WIDTH - 2); monster->seen_y = random_number(1, MAP_HEIGHT - 2); } n_x = monster->seen_x - monster->x_pos; n_y = monster->seen_y - monster->y_pos; if(n_x < 0) { n_x = -1; } else if(n_x > 0) { n_x = 1; } if(n_y < 0) { n_y = -1; } else if(n_y > 0) { n_y = 1; } n_x += monster->x_pos; n_y += monster->y_pos; n_cell = cell_arr + (MAP_WIDTH * n_y) + n_x; //if pass do not worry about this part of code if(!(monster->traits & IS_PASS)) { if(monster->traits & IS_TUNNELING) { if(n_cell->cell_type == stone) { n_cell->hardness -= 85; if(n_cell->hardness > 0) { update_tunn_map(c_path, cell_arr); return normal; } else { n_cell->hardness = 0; n_cell->cell_type = corridor; update_tunn_map(c_path, cell_arr); result = update_nt_map; } } } else if(n_cell->cell_type == stone) { n_cell = cell_arr + (MAP_WIDTH * monster->y_pos) + n_x; if(n_cell->cell_type == stone) { n_x = monster->x_pos; } n_cell = cell_arr + (MAP_WIDTH * n_y) + monster->x_pos; if(n_cell->cell_type == stone) { n_y = monster->y_pos; } /*if cant continue on path, guess again*/ if(n_y == monster->y_pos && n_x == monster->x_pos) { monster->seen_x = random_number(1, MAP_WIDTH - 2); monster->seen_y = random_number(1, MAP_HEIGHT - 2); } } } n_cell = cell_arr + (MAP_WIDTH * n_y) + n_x; if(n_cell->character != NULL) { if(((character *)(n_cell->character))->print() == '@') { dam = monster->damage->roll(); dam = ((pc *)(n_cell->character))->attack(dam); mes << "Attacked by " << *monster->name; mes << " for " << dam << " hitpoints"; add_message(mes.str()); if(n_cell->character->hitpoints <= 0) { result = player_died; n_cell->character = NULL; } } else { temp = n_cell->character; temp->x_pos = monster->x_pos; temp->y_pos = monster->y_pos; c_cell->character = temp; monster->y_pos = n_y; monster->x_pos = n_x; n_cell->character = monster; } return result; } monster->y_pos = n_y; monster->x_pos = n_x; c_cell->character = NULL; n_cell->character = monster; return result; }
void tutorial_game::per_turn() { // note that add_message does nothing if the message was already shown add_message( LESSON_INTRO ); add_message( LESSON_MOVE ); add_message( LESSON_LOOK ); if( g->light_level( g->u.posz() ) == 1 ) { if( g->u.has_amount( "flashlight", 1 ) ) { add_message( LESSON_DARK ); } else { add_message( LESSON_DARK_NO_FLASH ); } } if( g->u.get_pain() > 0 ) { add_message( LESSON_PAIN ); } if( g->u.recoil >= MAX_RECOIL ) { add_message( LESSON_RECOIL ); } if( !tutorials_seen[LESSON_BUTCHER] ) { for( size_t i = 0; i < g->m.i_at( g->u.posx(), g->u.posy() ).size(); i++ ) { if( g->m.i_at( g->u.posx(), g->u.posy() )[i].is_corpse() ) { add_message( LESSON_BUTCHER ); i = g->m.i_at( g->u.posx(), g->u.posy() ).size(); } } } bool showed_message = false; for( int x = g->u.posx() - 1; x <= g->u.posx() + 1 && !showed_message; x++ ) { for( int y = g->u.posy() - 1; y <= g->u.posy() + 1 && !showed_message; y++ ) { if( g->m.ter( x, y ) == t_door_o ) { add_message( LESSON_OPEN ); showed_message = true; } else if( g->m.ter( x, y ) == t_door_c ) { add_message( LESSON_CLOSE ); showed_message = true; } else if( g->m.ter( x, y ) == t_window ) { add_message( LESSON_SMASH ); showed_message = true; } else if( g->m.furn( x, y ) == f_rack && !g->m.i_at( x, y ).empty() ) { add_message( LESSON_EXAMINE ); showed_message = true; } else if( g->m.ter( x, y ) == t_stairs_down ) { add_message( LESSON_STAIRS ); showed_message = true; } else if( g->m.ter( x, y ) == t_water_sh ) { add_message( LESSON_PICKUP_WATER ); showed_message = true; } } } if( !g->m.i_at( g->u.posx(), g->u.posy() ).empty() ) { add_message( LESSON_PICKUP ); } }
void tutorial_game::per_turn() { if (g->turn == HOURS(12)) { add_message(LESSON_INTRO); add_message(LESSON_INTRO); } else if (g->turn == HOURS(12) + 3) add_message(LESSON_INTRO); if (g->light_level() == 1) { if (g->u.has_amount("flashlight", 1)) add_message(LESSON_DARK); else add_message(LESSON_DARK_NO_FLASH); } if (g->u.pain > 0) add_message(LESSON_PAIN); if (g->u.recoil >= 5) add_message(LESSON_RECOIL); if (!tutorials_seen[LESSON_BUTCHER]) { for (int i = 0; i < g->m.i_at(g->u.posx, g->u.posy).size(); i++) { if (g->m.i_at(g->u.posx, g->u.posy)[i].type->id == "corpse") { add_message(LESSON_BUTCHER); i = g->m.i_at(g->u.posx, g->u.posy).size(); } } } bool showed_message = false; for (int x = g->u.posx - 1; x <= g->u.posx + 1 && !showed_message; x++) { for (int y = g->u.posy - 1; y <= g->u.posy + 1 && !showed_message; y++) { if (g->m.ter(x, y) == t_door_o) { add_message(LESSON_OPEN); showed_message = true; } else if (g->m.ter(x, y) == t_door_c) { add_message(LESSON_CLOSE); showed_message = true; } else if (g->m.ter(x, y) == t_window) { add_message(LESSON_SMASH); showed_message = true; } else if (g->m.furn(x, y) == f_rack && !g->m.i_at(x, y).empty()) { add_message(LESSON_EXAMINE); showed_message = true; } else if (g->m.ter(x, y) == t_stairs_down) { add_message(LESSON_STAIRS); showed_message = true; } else if (g->m.ter(x, y) == t_water_sh) { add_message(LESSON_PICKUP_WATER); showed_message = true; } } } if (!g->m.i_at(g->u.posx, g->u.posy).empty()) add_message(LESSON_PICKUP); }
/* In a->data.ca[1] steht der Prozentsatz mit dem sich die Einheit * auflöst, in a->data.ca[0] kann angegeben werden, wohin die Personen * verschwinden. Passiert bereits in der ersten Runde! */ static void dissolve_units(void) { region *r; unit *u; int n; int i; for (r = regions; r; r = r->next) { for (u = r->units; u; u = u->next) { attrib *a = a_find(u->attribs, &at_unitdissolve); if (a) { message *msg; if (u->age == 0 && a->data.ca[1] < 100) continue; /* TODO: Durch einzelne Berechnung ersetzen */ if (a->data.ca[1] == 100) { n = u->number; } else { n = 0; for (i = 0; i < u->number; i++) { if (rng_int() % 100 < a->data.ca[1]) n++; } } /* wenn keiner verschwindet, auch keine Meldung */ if (n == 0) { continue; } scale_number(u, u->number - n); switch (a->data.ca[0]) { case 1: rsetpeasants(r, rpeasants(r) + n); msg = msg_message("dissolve_units_1", "unit region number race", u, r, n, u_race(u)); break; case 2: if (r->land && !fval(r, RF_MALLORN)) { rsettrees(r, 2, rtrees(r, 2) + n); msg = msg_message("dissolve_units_2", "unit region number race", u, r, n, u_race(u)); } else { msg = msg_message("dissolve_units_3", "unit region number race", u, r, n, u_race(u)); } break; default: if (u_race(u) == get_race(RC_STONEGOLEM) || u_race(u) == get_race(RC_IRONGOLEM)) { msg = msg_message("dissolve_units_4", "unit region number race", u, r, n, u_race(u)); } else { msg = msg_message("dissolve_units_5", "unit region number race", u, r, n, u_race(u)); } break; } add_message(&u->faction->msgs, msg); msg_release(msg); } } } remove_empty_units(); }
bool ScillsResultUpdater::run( MP mp ) { // add_message( mp, ET_Info, "Test info msg" ); int nb_parts_ = mp[ "nb_parts" ]; qDebug() << nb_parts_; double id_model = mp[ "id_model" ]; if ( id_model == -1 ) { add_message( mp, ET_Error, "Model is not available" ); //return false; } double id_calcul = mp[ "id_calcul" ]; if ( id_calcul <= -2 ) { add_message( mp, ET_Error, "Data are not available" ); } else if( id_calcul == -1 and nb_parts_ == 0) { add_message( mp, ET_Info, "You choose to visualize the base mesh" ); // using namespace Metil; // using namespace LMT; // version 1------------------------------------------------------------------ Sc2String str_id_model; str_id_model << id_model; Sc2String str_id_calcul; str_id_calcul << id_calcul; GeometryUser geometry_user; /// structure de stockage des informations du fichier HDF5 geometry_user.initialisation(str_id_model, str_id_calcul); geometry_user.read_hdf5(false,true,"test"); /// true si on lit les info micro, true si on lit toutes les infos MP opc = mp[ "_children[ 0 ]" ]; // output Part collection MP oic = mp[ "_children[ 1 ]" ]; // output Interface collection MP oec = mp[ "_children[ 2 ]" ]; // output Edge collection //qDebug() << oec[ "_edge_profile" ]; int nb_parts = 0; int nb_interfaces = 0; int nb_edges = 0; int dimention; if(geometry_user.group_elements[0].pattern_id == 0 or geometry_user.group_elements[0].pattern_id == 1) { dimention = 2; } else { dimention = 3; } for (int i_group=0; i_group<geometry_user.group_elements.size(); i_group++) { MP part_profile = oic[ "_part_profile" ]; MP part = MP::new_obj( "ScillsPartItem" ); new_scills_obg(part, part_profile, geometry_user.group_elements[i_group].id, "Part"); //création du sous maillage de part ------ part[ "_mesh" ] = MP::new_obj( "Mesh" ); MP om = part[ "_mesh" ]; new_mesh(om); part[ "visualization" ] = om[ "visualization" ]; part[ "id" ] = geometry_user.group_elements[i_group].id; if(dimention == 2) { //liste des points du maillage------------ new_list_points_mesh_2D(om, geometry_user.group_elements[i_group]); //liste des éléments du maillage---------- new_list_elements_mesh_2D(om, geometry_user.group_elements[i_group]); } else if(dimention == 3) { new_mesh_part_3D(om, geometry_user, i_group); } nb_parts += 1; opc[ "_children" ] << part; } for (int i_group=0; i_group<geometry_user.group_interfaces.size(); i_group++) { if(geometry_user.group_interfaces[i_group].type == 2) { //création de l'interface------------------------- MP interface_profile = oic[ "_interface_profile" ]; MP interface = MP::new_obj( "ScillsInterfaceItem" ); new_scills_obg(interface, interface_profile, geometry_user.group_interfaces[i_group].id, "Interface"); //création du sous maillage de interface ------ interface[ "_mesh" ] = MP::new_obj( "Mesh" ); MP om = interface[ "_mesh" ]; new_mesh(om); interface[ "visualization" ] = om[ "visualization" ]; interface[ "id" ] = geometry_user.group_interfaces[i_group].id; if(dimention == 2) { //liste des points du maillage------------ new_list_points_mesh_2D(om, geometry_user.group_interfaces[i_group]); //liste des éléments du maillage---------- new_list_elements_mesh_2D(om, geometry_user.group_interfaces[i_group]); } else if(dimention == 3) { //liste des points du maillage------------ new_list_points_mesh_3D(om, geometry_user.group_interfaces[i_group]); //liste des éléments du maillage---------- new_list_elements_mesh_3D(om, geometry_user.group_interfaces[i_group]); } //ajout de l'interface à l'assemblage------------ nb_interfaces += 1; oic[ "_children" ] << interface; } else if(geometry_user.group_interfaces[i_group].type == 0) { //création du edge------------------------- MP edge_profile = oec[ "_edge_profile" ]; MP edge = MP::new_obj( "ScillsEdgeItem" ); new_scills_obg(edge, edge_profile, geometry_user.group_interfaces[i_group].id, "Edge"); //création du sous maillage de edge ------ edge[ "_mesh" ] = MP::new_obj( "Mesh" ); MP om = edge[ "_mesh" ]; new_mesh(om); edge[ "visualization" ] = om[ "visualization" ]; edge[ "id" ] = geometry_user.group_interfaces[i_group].id; if(dimention == 2) { //liste des points du maillage------------ new_list_points_mesh_2D(om, geometry_user.group_interfaces[i_group]); //liste des éléments du maillage---------- new_list_elements_mesh_2D(om, geometry_user.group_interfaces[i_group]); } else if(dimention == 3) { //liste des points du maillage------------ new_list_points_mesh_3D(om, geometry_user.group_interfaces[i_group]); //liste des éléments du maillage---------- new_list_elements_mesh_3D(om, geometry_user.group_interfaces[i_group]); } //ajout du edge à l'assemblage------------ nb_edges += 1; oec[ "_children" ] << edge; } } mp[ "nb_parts" ] = nb_parts; mp[ "nb_interfaces" ] = nb_interfaces; mp[ "nb_edges" ] = nb_edges; mp.flush(); } else { add_message( mp, ET_Info, "You choose to visualize a result" ); } add_message( mp, ET_Info, "ScillsResult just finish" ); }
static void torrent_complete(const torrent_info *torrent) { char message[1024]; sprintf(message, "Download complete: %s", torrent->name); add_message(message); }
int main (int argc, char **argv){ add_message(0); add_message(1); return 0; }
static int update_op(struct update_context *uc) { fs_rid_vector *vec[4]; switch (uc->op->type) { case RASQAL_UPDATE_TYPE_UNKNOWN: add_message(uc, "Unknown update operation", 0); return 1; case RASQAL_UPDATE_TYPE_CLEAR: fs_clear(uc, graph_arg(uc->op->graph_uri)); return 0; case RASQAL_UPDATE_TYPE_CREATE: return 0; case RASQAL_UPDATE_TYPE_DROP: fs_clear(uc, graph_arg(uc->op->graph_uri)); return 0; case RASQAL_UPDATE_TYPE_LOAD: fs_load(uc, graph_arg(uc->op->document_uri), graph_arg(uc->op->graph_uri)); return 0; #if RASQAL_VERSION >= 924 case RASQAL_UPDATE_TYPE_ADD: fs_add(uc, graph_arg(uc->op->graph_uri), graph_arg(uc->op->document_uri)); return 0; case RASQAL_UPDATE_TYPE_MOVE: fs_move(uc, graph_arg(uc->op->graph_uri), graph_arg(uc->op->document_uri)); return 0; case RASQAL_UPDATE_TYPE_COPY: fs_copy(uc, graph_arg(uc->op->graph_uri), graph_arg(uc->op->document_uri)); return 0; #endif case RASQAL_UPDATE_TYPE_UPDATE: break; } fs_hash_freshen(); raptor_sequence *todel = NULL; raptor_sequence *toins = NULL; if (uc->op->delete_templates && !uc->op->where) { int where = 0; /* check to see if it's a DELETE WHERE { } */ for (int t=0; t<raptor_sequence_size(uc->op->delete_templates); t++) { rasqal_triple *tr = raptor_sequence_get_at(uc->op->delete_templates, t); if (any_vars(tr)) { where = 1; break; } } if (where) { fs_error(LOG_ERR, "DELETE WHERE { x } not yet supported"); add_message(uc, "DELETE WHERE { x } not yet supported, use DELETE { x } WHERE { x }", 0); return 1; } } #if RASQAL_VERSION >= 923 if (uc->op->where) { todel = raptor_new_sequence(NULL, NULL); toins = raptor_new_sequence(NULL, NULL); raptor_sequence *todel_p = raptor_new_sequence(NULL, NULL); raptor_sequence *toins_p = raptor_new_sequence(NULL, NULL); raptor_sequence *vars = raptor_new_sequence(NULL, NULL); fs_query *q = calloc(1, sizeof(fs_query)); uc->q = q; q->qs = uc->qs; q->rq = uc->rq; q->flags = FS_BIND_DISTINCT; #ifdef DEBUG_MERGE q->flags |= FS_QUERY_CONSOLE_OUTPUT; #endif q->boolean = 1; q->opt_level = 3; q->soft_limit = -1; q->segments = fsp_link_segments(uc->link); q->link = uc->link; q->bb[0] = fs_binding_new(); q->bt = q->bb[0]; /* hashtable to hold runtime created resources */ q->tmp_resources = g_hash_table_new_full(fs_rid_hash, fs_rid_equal, g_free, fs_free_cached_resource); /* add column to denote join ordering */ fs_binding_create(q->bb[0], "_ord", FS_RID_NULL, 0); if (uc->op->delete_templates) { for (int t=0; t<raptor_sequence_size(uc->op->delete_templates); t++) { rasqal_triple *tr = raptor_sequence_get_at(uc->op->delete_templates, t); if (any_vars(tr)) { fs_check_cons_slot(q, vars, tr->subject); fs_check_cons_slot(q, vars, tr->predicate); fs_check_cons_slot(q, vars, tr->object); raptor_sequence_push(todel_p, tr); } else { raptor_sequence_push(todel, tr); } } } if (uc->op->insert_templates) { for (int t=0; t<raptor_sequence_size(uc->op->insert_templates); t++) { rasqal_triple *tr = raptor_sequence_get_at(uc->op->insert_templates, t); if (any_vars(tr)) { fs_check_cons_slot(q, vars, tr->subject); fs_check_cons_slot(q, vars, tr->predicate); fs_check_cons_slot(q, vars, tr->object); raptor_sequence_push(toins_p, tr); } else { raptor_sequence_push(toins, tr); } } } q->num_vars = raptor_sequence_size(vars); for (int i=0; i < q->num_vars; i++) { rasqal_variable *v = raptor_sequence_get_at(vars, i); fs_binding_add(q->bb[0], v, FS_RID_NULL, 1); } /* perform the WHERE match */ fs_query_process_pattern(q, uc->op->where, vars); q->length = fs_binding_length(q->bb[0]); for (int s=0; s<4; s++) { vec[s] = fs_rid_vector_new(0); } for (int t=0; t<raptor_sequence_size(todel_p); t++) { rasqal_triple *triple = raptor_sequence_get_at(todel_p, t); for (int row=0; row < q->length; row++) { delete_rasqal_triple(uc, vec, triple, row); } if (fs_rid_vector_length(vec[0]) > 1000) { fsp_delete_quads_all(uc->link, vec); } } if (fs_rid_vector_length(vec[0]) > 0) { fsp_delete_quads_all(uc->link, vec); } for (int s=0; s<4; s++) { //fs_rid_vector_print(vec[s], 0, stdout); fs_rid_vector_free(vec[s]); vec[s] = NULL; } for (int t=0; t<raptor_sequence_size(toins_p); t++) { rasqal_triple *triple = raptor_sequence_get_at(toins_p, t); for (int row=0; row < q->length; row++) { insert_rasqal_triple(uc, triple, row); } } /* must not free the rasqal_query */ q->rq = NULL; fs_query_free(q); uc->q = NULL; } else { todel = uc->op->delete_templates; toins = uc->op->insert_templates; } #else if (uc->op->where) { fs_error(LOG_ERR, "DELETE/INSERT WHERE requires Rasqal 0.9.23 or newer"); add_message(uc, "DELETE/INSERT WHERE requires Rasqal 0.9.23 or newer", 0); } #endif /* delete constant triples */ if (todel) { for (int s=0; s<4; s++) { vec[s] = fs_rid_vector_new(0); } for (int t=0; t<raptor_sequence_size(todel); t++) { rasqal_triple *triple = raptor_sequence_get_at(todel, t); if (any_vars(triple)) { continue; } delete_rasqal_triple(uc, vec, triple, 0); } if (fs_rid_vector_length(vec[0]) > 0) { fsp_delete_quads_all(uc->link, vec); } for (int s=0; s<4; s++) { fs_rid_vector_free(vec[s]); vec[s] = NULL; } } /* insert constant triples */ if (toins) { for (int t=0; t<raptor_sequence_size(toins); t++) { rasqal_triple *triple = raptor_sequence_get_at(toins, t); if (any_vars(triple)) { continue; } insert_rasqal_triple(uc, triple, 0); } } fs_hash_freshen(); return 0; }
int fs_add(struct update_context *uc, char *from, char *to) { fs_rid_vector *mvec = fs_rid_vector_new(0); fs_rid_vector *empty = fs_rid_vector_new(0); fs_rid fromrid, torid; if (from) { fromrid = fs_hash_uri(from); } else { from = FS_DEFAULT_GRAPH; fromrid = fs_c.default_graph; } if (to) { torid = fs_hash_uri(to); } else { to = FS_DEFAULT_GRAPH; torid = fs_c.default_graph; } if (fromrid == torid) { /*don't need to do anything */ add_message(uc, g_strdup_printf("Added <%s> to <%s>", from, to), 1); add_message(uc, "0 triples added, 0 removed", 0); return 0; } fs_rid_vector_append(mvec, fromrid); int errors = 0; /* search for all the triples in from */ fs_rid_vector **results; fs_rid_vector *slot[4] = { mvec, empty, empty, empty }; fs_bind_cache_wrapper(uc->qs, NULL, 1, FS_BIND_BY_SUBJECT | FS_BIND_SUBJECT | FS_BIND_PREDICATE | FS_BIND_OBJECT, slot, &results, -1, -1); fs_rid_vector_free(mvec); fs_rid_vector_free(empty); if (!results || results[0]->length == 0) { /* there's nothing to add */ if (results) { for (int i=0; i<3; i++) { fs_rid_vector_free(results[i]); } free(results); } add_message(uc, g_strdup_printf("Added <%s> to <%s>", from, to), 1); add_message(uc, "0 triples added, 0 removed", 0); return 0; } map_bnodes(uc, results[0]); map_bnodes(uc, results[1]); map_bnodes(uc, results[2]); fs_resource tores; tores.lex = to; tores.attr= FS_RID_NULL; tores.rid = torid; fsp_res_import(uc->link, FS_RID_SEGMENT(torid, uc->segments), 1, &tores); insert_triples(uc, torid, results[0], results[1], results[2]); add_message(uc, g_strdup_printf("Added <%s> to <%s>", from, to), 1); add_message(uc, g_strdup_printf("%d triples added, 0 removed", results[0]->length), 1); for (int i=0; i<3; i++) { fs_rid_vector_free(results[i]); } free(results); return errors; }
void slice_torus (struct msscene *ms, struct surface *current_surface, double fine_pixel, double probe_radius, struct face *fac) { int k, j, i, nfocus, near1, naif; double anginc, bigrad; double focus[3], vect1[3], vect2[3], vect[3], qvect[3]; double dtq, tcv[3]; double *foci = (double *) NULL; char message[MAXLINE]; struct leaf *lf; struct circle *cir1, *cir2, *cir3; struct circle *lfcir, *torcir; struct variety *vty, *atm1, *atm2; struct arc *a, *nxta; struct arc *torarc; struct vertex *torvtx[2]; struct vertex *qvtx; struct vertex *conevtx; struct cycle *cyc; struct edge *edg; struct cept *ex; vty = fac -> vty; if (vty -> type != TORUS) { ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_long (ex, "variety type", (long) vty -> type); return; } if (vty -> tube) { slice_elbow (ms, current_surface, fine_pixel, fac); return; } if (debug >= 2) { sprintf (message,"render saddle face for atoms %5d %5d", vty -> atmnum[0], vty -> atmnum[1]); inform(message); } /* get pointers to atom varieties */ atm1 = *(current_surface -> variety_handles + fac -> vty -> atmnum[0] - 1); atm2 = *(current_surface -> variety_handles + fac -> vty -> atmnum[1] - 1); /* check versus window */ bigrad = distance (atm1 -> center, atm2 -> center) + atm1 -> radii[0] + atm2 -> radii[0]; for (k = 0; k < 3; k++) { if (vty -> center[k] + bigrad < ms -> window[0][k]) return; if (vty -> center[k] - bigrad > ms -> window[1][k]) return; } /* leaf circle */ lfcir = allocate_circle (); if (error()) { add_object (tail_cept, CIRCLE, "leaf circle"); add_function (tail_cept, "slice_torus"); return; } /* leaf */ lf = allocate_leaf (); if (error()) { add_object (tail_cept, LEAF, "leaf"); add_function (tail_cept, "slice_sphere"); return; } /* torus circle radius, center, axis */ torcir = new_circle (vty -> center, vty -> radii[0], vty -> axis); if (torcir == NULL) { add_object (tail_cept, CIRCLE, "torus circle"); add_function (tail_cept, "slice_circle"); return; } /* torus arc */ torarc = allocate_arc (); if (error()) { add_object (tail_cept, ARC, "torus arc"); add_function (tail_cept, "slice_torus"); add_source (tail_cept, "msrender.c"); return; } for (j = 0; j < 2; j++) { torvtx[j] = allocate_vertex (); if (error()) { add_object (tail_cept, VERTEX, "torus vertex"); add_function (tail_cept, "slice_torus"); add_source (tail_cept, "msrender.c"); return; } } torarc -> cir = torcir; /* copy atom numbers from variety to leaf */ for (k = 0; k < MAXPA; k++) lf -> atmnum[k] = fac -> vty -> atmnum[k]; /* set up leaf fields */ lf -> cir = lfcir; lf -> shape = fac -> shape; lf -> type = fac -> vty -> type; lf -> fac = fac; lf -> cep = 0; lf -> clip_ep = 0; lf -> side = OUTSIDE; lf -> comp = fac -> comp; lf -> input_hue = fac -> input_hue; /* both endpoints of saddle face leaf are always accessible */ for (j = 0; j < 2; j++) lf -> where[j] = ACCESSIBLE; /* angular increment for rotation of leaf about torus axis */ anginc = fine_pixel / (vty -> radii[0]); /* next we need endpoints for torus arc */ /* get them from concave arcs bounding saddle face */ /* intialization */ cir1 = NULL; cir2 = NULL; cir3 = NULL; qvtx = NULL; conevtx = NULL; near1 = 0; /* look for concave arcs */ naif = 0; for (cyc = fac -> first_cycle; cyc != NULL; cyc = cyc -> next) for (edg = cyc -> first_edge; edg != NULL; edg = edg -> next) { naif++; a = edg -> arcptr; if (a -> shape == CONVEX) { cir3 = a -> cir; continue; } if (edg -> next == NULL) nxta = cyc -> first_edge -> arcptr; else nxta = edg -> next -> arcptr; if (along (edg, vty -> axis)) cir2 = a -> cir; else cir1 = a -> cir; /* check for cusp vertex */ if (a -> shape == CONCAVE && nxta -> shape == CONCAVE) { /* cusp point joints two concave arcs */ qvtx = a -> vtx[1-edg->orn]; } } dtq = probe_radius * probe_radius - vty -> radii[0] * vty -> radii[0]; /* later: note: check PI in bubbles */ if (naif == 1) { if (dtq <= 0.0) { ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_message(ex, "toroidal face with only one arc, but not cone"); return; } if (cir3 == NULL) { ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_message(ex, "toroidal face with only one arc, but no contact circle"); return; } /* cone */ qvtx = allocate_vertex (); if (error()) { add_object (tail_cept, VERTEX, "CUSP VERTEX"); add_function (tail_cept, "slice_torus"); add_source (tail_cept, "msrender.c"); return; } conevtx = qvtx; dtq = sqrt (dtq); for (k = 0; k < 3; k++) tcv[k] = cir3 -> center[k] - torcir -> center[k]; normalize (tcv); for (k = 0; k < 3; k++) qvtx -> center[k] = torcir -> center[k] + dtq * tcv[k]; /* hope this is enough */ } if (cir1 == NULL) informd2 ("cir1 null"); if (cir2 == NULL) informd2 ("cir2 null"); if (qvtx != NULL) informd2 ("cusp present"); /* check for cusp vertex */ if (qvtx != NULL) { for (k = 0; k < 3; k++) qvect[k] = qvtx -> center[k] - vty -> center[k]; near1 = (dot_product (qvect, vty -> axis) < 0.0); } /* check for hoop saddle face */ if (cir1 == NULL || cir2 == NULL) { for (j = 0; j < 2; j++) torarc -> vtx[j] = NULL; informd2 ("complete toroidal hoop"); } else { /* concave arc circle centers are endpoints of sphere rolling */ for (k = 0; k < 3; k++) { torvtx[0] -> center[k] = cir1 -> center[k]; torvtx[1] -> center[k] = cir2 -> center[k]; } for (j = 0; j < 2; j++) torarc -> vtx[j] = torvtx[j]; sprintf (message, "saddle rendering (from): %8.3f %8.3f %8.3f", cir1 -> center[0], cir1 -> center[1], cir1 -> center[2]); informd2 (message); sprintf (message, "saddle rendering (to) : %8.3f %8.3f %8.3f", cir2 -> center[0], cir2 -> center[1], cir2 -> center[2]); informd2 (message); } /* the probe sphere centers are the foci of the leaves */ nfocus = render_sub_arc (torarc, &foci, anginc); if (nfocus < 2) { ex = new_cept (LOGIC_ERROR, MSUNDERFLOW, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_long (ex, "number of foci", (long) nfocus); return; } sprintf (message, "nfocus = %d", nfocus); informd2 (message); /* create leaves */ for (i = 0; i < nfocus; i++) { for (k = 0; k < 3; k++) { focus[k] = (*(foci + 3 * i + k)); lfcir -> center[k] = focus[k]; lf -> focus[k] = focus[k]; } /* unit vectors from focus toward atoms */ for (k = 0; k < 3; k++) { vect1[k] = atm1 -> center[k] - focus[k]; vect2[k] = atm2 -> center[k] - focus[k]; } /* correct for cusp vertex */ if (qvtx != NULL) { if (near1) for (k = 0; k < 3; k++) vect2[k] = qvtx -> center[k] - focus[k]; else for (k = 0; k < 3; k++) vect1[k] = qvtx -> center[k] - focus[k]; } /* normalize vectors to unit length */ normalize (vect1); normalize (vect2); /* leaf circle radius is probe radius */ lfcir -> radius = probe_radius; /* set up endpoints of leaf */ for (k = 0; k < 3; k++) { lf -> ends[0][k] = focus[k] + lfcir -> radius * vect1[k]; lf -> ends[1][k] = focus[k] + lfcir -> radius * vect2[k]; } /* compute leaf circle axis */ for (k = 0; k < 3; k++) vect[k] = focus[k] - vty -> center[k]; cross (vty -> axis, vect, lfcir -> axis); normalize (lfcir -> axis); /* clip and render leaf */ clip_leaf (ms, current_surface, fine_pixel, lf); if (error()) return; } /* return temporary memory */ if (!free_doubles (foci, 0, VERTS)) { ex = new_cept (MEMORY_ERROR, FREEING, FATAL_SEVERITY); add_variable (ex, VERTS, "foci"); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); return; } free_leaf (lf); free_arc (torarc); free_circle (torcir); free_circle (lfcir); for (j = 0; j < 2; j++) free_vertex (torvtx[j]); if (conevtx != NULL) free_vertex (conevtx); return; }
void render_polyhedron (struct msscene *ms, struct surface *phn, double fine_pixel, long interpolate) { int j, k, check, comp, hue, f, atm; int orn0, orn1, orn2; long t; long n_back, n_clipped, n_rendered; int vclipped[3], vback; double tcen[3]; double trad; double tvertices[3][3]; double tnormals[4][3]; double tvalues[3]; char message[MAXLINE]; struct phnedg *edg0, *edg1, *edg2; struct phntri *tri; struct phnvtx *vtx, *vtxs[3]; struct cept *ex; n_back = 0; n_clipped = 0; n_rendered = 0; f = (phn -> function[0]); if (phn -> phntri_handles == NULL) return; for (t = 0; t < phn -> n_phntri; t++) { tri = num2phntri (phn, t+1); if (tri == NULL) { ex = new_cept (POINTER_ERROR, NULL_POINTER, FATAL_SEVERITY); add_object (ex, PHNTRI, "tri"); add_function (ex, "render_polyhedron"); add_source (ex, "msrender.c"); return; } for (k = 0; k < 3; k++) tcen[k] = tri -> center[k]; trad = tri -> radius; edg0 = tri -> edg[0]; edg1 = tri -> edg[1]; edg2 = tri -> edg[2]; orn0 = tri -> orn[0]; orn1 = tri -> orn[1]; orn2 = tri -> orn[2]; vtxs[0] = edg0 -> pvt[orn0]; vtxs[1] = edg1 -> pvt[orn1]; vtxs[2] = edg2 -> pvt[orn2]; for (k = 0; k < 3; k++) tnormals[3][k] = tri -> axis[k]; for (j = 0; j < 3; j++) { vtx = vtxs[j]; if (f == 'x') tvalues[j] = vtx -> center[0]; else if (f == 'y') tvalues[j] = vtx -> center[1]; else if (f == 'z') tvalues[j] = vtx -> center[2]; else if (f == 'u') tvalues[j] = vtx -> values[0]; else if (f == 'v') tvalues[j] = vtx -> values[1]; else if (f == 'w') tvalues[j] = vtx -> values[2]; else tvalues[j] = vtx -> center[2]; /* default */ for (k = 0; k < 3; k++) { tvertices[j][k] = vtx -> center[k]; tnormals[j][k] = vtx -> outward[k]; } /* check back-facing for triangle vertex normal */ /* check clipping for triangle vertex */ vclipped[j] = ms -> clipping && phn -> clipping && clipped (ms, tvertices[j]); } vback = (tnormals[3][2] < 0.0); if (ms -> clipping && phn -> clipping) { /* if all three vertices are clipped, triangle is clipped */ check = (vclipped[0] || vclipped[1] || vclipped[2]); if (vclipped[0] && vclipped[1] && vclipped[2]) { n_clipped++; continue; } } else { check = 0; /* no need to check triangle for being partially clipped */ /* if back-facing, skip triangle */ if (vback) { n_back++; continue; } } comp = tri -> comp; atm = tri -> atm; if (atm <= 0) { ex = new_cept (LOGIC_ERROR, BOUNDS, FATAL_SEVERITY); add_function (ex, "render_polyhedron"); add_source (ex, "msrender.c"); add_long (ex, "atm", (long) atm); add_message(ex, "invalid atom number for triangle"); return; } hue = tri -> hue; render_triangle (ms, phn, fine_pixel, interpolate, tcen, trad, tvertices, tnormals, tvalues, check, comp, hue, atm); if (error()) return; n_rendered++; } if (ms -> clipping && phn -> clipping) sprintf (message,"%8ld triangles rendered, %6ld clipped", n_rendered, n_clipped); else sprintf (message,"%8ld triangles rendered, %6ld back-facing", n_rendered, n_back); inform(message); }
void player_act() { switch(get_last_action()) { case ACTION_TILL: till(x, y, current_map); break; case ACTION_PICKUP: { item* it = get_item(items_at(x, y, current_map), item_count_at(x, y, current_map), PURPOSE_PICKUP, true); if(!it) break; printf_message(COLOR_DEFAULT, "Picked up %d %s", it->count, it->name); callback("picked_up", it->script_state); take_item(x, y, it, current_map); add_item(it); } break; case ACTION_DROP: { item* it = get_item(inventory, item_count, PURPOSE_DROP, false); if(!it) break; if(it->can_equip && equipment[it->slot] == it) { equipment[it->slot] = 0; printf_message(COLOR_DEFAULT, "You unequip the %s, and drop it on the ground.", it->name); callback("removed", it->script_state); } item* clone = clone_item(it); callback("dropped", clone->script_state); place_item(x, y, clone, current_map); remove_item(it, -1); } break; case ACTION_APPLY: { item* it = get_item(inventory, item_count, PURPOSE_APPLY, false); if(!it) break; callback("apply", it->script_state); remove_item(it, 1); } break; case ACTION_EQUIP: { item* it = get_item(inventory, item_count, PURPOSE_EQUIP, false); if(!it || it->slot == SLOT_INVALID) break; callback("equip", it->script_state); printf_message(COLOR_DEFAULT, "You equip the %s.", it->name); equipment[it->slot] = it; break; } case ACTION_REMOVE: { item* it = get_item(equipment, 3, PURPOSE_REMOVE, false); if(!it) break; callback("remove", it->script_state); equipment[it->slot] = 0; printf_message(COLOR_DEFAULT, "You unequip the %s.", it->name); break; } case ACTION_PLANT: { if(!can_plant(x, y, current_map, true)) break; item* it = get_item(inventory, item_count, PURPOSE_PLANT, false); if(!it) break; if(spawn_plant(x, y, it->plant_id, current_map)) { printf_message(COLOR_DEFAULT, "You plant the %s in the tilled soil.", it->name); remove_item(it, 1); } break; } case ACTION_HARVEST: { add_item(harvest_plant(x, y, current_map)); break; } case ACTION_HELP: show_controls(); break; case ACTION_INVENTORY: get_item(inventory, item_count, PURPOSE_NONE, false); break; case ACTION_WATER: water_tile(x, y, current_map); break; case ACTION_EXAMINE: { int mx, my; get_last_mouse_position(&mx, &my); int xdiff = mx - pres_x; int ydiff = my - pres_y; if(mx < 1 || my < 1 || mx > 78 || my > 78) break; examine(x + xdiff, y +ydiff, current_map); } break; } if(ep_current <= 0) add_message(COLOR_EP_CRIT, "Out of energy, you fall to the ground."); }
void player_move(int direction) { int dx = 0; int dy = 0; switch(direction) { case DIRECTION_NORTH: dy = -1; break; case DIRECTION_SOUTH: dy = 1; break; case DIRECTION_EAST: dx = 1; break; case DIRECTION_WEST: dx = -1; break; case DIRECTION_NORTHEAST: dx = 1; dy = -1; break; case DIRECTION_NORTHWEST: dx = -1; dy = -1; break; case DIRECTION_SOUTHEAST: dx = 1; dy = 1; break; case DIRECTION_SOUTHWEST: dx = -1; dy = 1; break; case DIRECTION_UP: if(z > 0 && is_up_stairs(x, y, current_map)) z--; return; case DIRECTION_DOWN: if(z < LEVEL_COUNT - 1 && is_down_stairs(x, y, current_map)) z++; return; } int res = can_move(x + dx, y + dy, current_map); if(res == 1) { x += dx; y += dy; int cost = 1 + get_cost(x, y, current_map); if(dx != 0 && dy != 0) cost *= 1.5; ep_current -= cost; if(ep_current <= 0) add_message(COLOR_EP_CRIT, "Out of energy, you fall to the ground."); else describe_ground(x, y, current_map); } else if(res == 2) { actor* act = get_actor_at(x + dx, y + dy, current_map); int astr = str; for(int i = 0; i < SLOT_COUNT; ++i) if(equipment[i]) astr += equipment[i]->str; int dmg = damage_actor(act, astr); char* damage_text = 0; if(dmg > 0) { int len = snprintf(0, 0, "You hit the %s for %d damage", act->name, dmg); damage_text = calloc(len + 1, sizeof(char)); snprintf(damage_text, len + 1, "You hit the %s for %d damage", act->name, dmg); } else { int len = snprintf(0, 0, "You miss the %s", act->name); damage_text = calloc(len + 1, sizeof(char)); snprintf(damage_text, len + 1, "You miss the %s", act->name); } if(act->hp <= 0) { printf_message(COLOR_DEFAULT, "You kill the %s!", act->name); add_xp(act->xp); } else add_message(COLOR_DEFAULT, damage_text); free(damage_text); } }
static gamestate_t move_eratic(npc *monster, cell_t *cell_arr, path_node_t *c_path) { int legal_move, n_x, n_y, dam; character *temp; gamestate_t result; cell_t *c_cell, *n_cell; std::stringstream mes; c_cell = cell_arr + (MAP_WIDTH * monster->y_pos) + monster->x_pos; legal_move = 0; result = normal; do{ n_x = random_number(1, 3) - 2; n_y = random_number(1, 3) - 2; n_x = monster->x_pos + n_x; n_y = monster->y_pos + n_y; /*Do not let monster leave the map*/ if(n_y >= MAP_HEIGHT - 1 || n_y < 1) { continue; } if(n_x >= MAP_WIDTH - 1 || n_x < 1) { continue; } n_cell = cell_arr + (MAP_WIDTH * n_y) + n_x; if(n_x == monster->x_pos && n_y == monster->y_pos) { continue; } else if(monster->traits & IS_TUNNELING || monster->traits & IS_PASS) { legal_move = 1; } else if(n_cell->cell_type != stone) { legal_move = 1; } } while(!legal_move); //if it is pass dont worry about tunneling if(!(monster->traits & IS_PASS)) { if(n_cell->cell_type == stone) { if(monster->traits & IS_TUNNELING) { n_cell->hardness -= 85; if(n_cell->hardness > 0) { update_tunn_map(c_path, cell_arr); return normal; } else { n_cell->hardness = 0; n_cell->cell_type = corridor; update_tunn_map(c_path, cell_arr); result = update_nt_map; } } else { return normal; } } } n_cell = cell_arr + (MAP_WIDTH * n_y) + n_x; if(n_cell->character != NULL) { if(((character *)(n_cell->character))->print() == '@') { dam = monster->damage->roll(); dam = ((pc *)(n_cell->character))->attack(dam); mes << "Attacked by " << *monster->name; mes << " for " << dam << " hitpoints"; add_message(mes.str()); if(n_cell->character->hitpoints <= 0) { result = player_died; n_cell->character = NULL; } } else { temp = n_cell->character; temp->x_pos = monster->x_pos; temp->y_pos = monster->y_pos; c_cell->character = temp; monster->y_pos = n_y; monster->x_pos = n_x; n_cell->character = monster; } return result; } monster->y_pos = n_y; monster->x_pos = n_x; c_cell->character = NULL; n_cell->character = monster; return result; }
/* * The start_boot() in master.c is supposed to return an array of files to load. * The array returned by apply() will be freed at next call of apply(), * which means that the ref count has to be incremented to protect against * deallocation. * * The master object is asked to do the actual loading. */ void preload_objects(int eflag) { struct gdexception exception_frame; struct vector *prefiles; struct svalue *ret = NULL; volatile int ix; set_current_time(); if (setjmp(exception_frame.e_context)) { clear_state(); (void)add_message("Error in start_boot() in master_ob.\n"); exception = NULL; return; } else { exception_frame.e_exception = NULL; exception_frame.e_catch = 0; exception = &exception_frame; push_number(eflag); ret = apply_master_ob(M_START_BOOT, 1); } if ((ret == 0) || (ret->type != T_POINTER)) return; else prefiles = ret->u.vec; if ((prefiles == 0) || (prefiles->size < 1)) return; INCREF(prefiles->ref); /* Otherwise it will be freed next sapply */ ix = -1; if (setjmp(exception_frame.e_context)) { clear_state(); (void)add_message("Anomaly in the fabric of world space.\n"); } while (++ix < prefiles->size) { set_current_time(); if (s_flag) reset_mudstatus(); eval_cost = 0; push_svalue(&(prefiles->item[ix])); (void)apply_master_ob(M_PRELOAD_BOOT, 1); if (s_flag) print_mudstatus(prefiles->item[ix].u.string, eval_cost, get_millitime(), get_processtime()); tmpclean(); } free_vector(prefiles); exception = NULL; set_current_time(); }
int fs_copy(struct update_context *uc, char *from, char *to) { fs_rid_vector *mvec = fs_rid_vector_new(0); fs_rid_vector *empty = fs_rid_vector_new(0); fs_rid fromrid, torid; if (from) { fromrid = fs_hash_uri(from); } else { from = FS_DEFAULT_GRAPH; fromrid = fs_c.default_graph; } if (to) { torid = fs_hash_uri(to); } else { to = FS_DEFAULT_GRAPH; torid = fs_c.default_graph; } if (fromrid == torid) { /*don't need to do anything */ fs_rid_vector_free(mvec); fs_rid_vector_free(empty); add_message(uc, g_strdup_printf("Copied <%s> to <%s>", from, to), 1); add_message(uc, "0 triples added, 0 removed", 0); return 0; } fs_rid_vector_append(mvec, fromrid); /* search for all the triples in from */ fs_rid_vector **results; fs_rid_vector *slot[4] = { mvec, empty, empty, empty }; /* see if there's any data in <from> */ fs_bind_cache_wrapper(uc->qs, NULL, 1, FS_BIND_BY_SUBJECT | FS_BIND_SUBJECT, slot, &results, -1, 1); if (!results || results[0]->length == 0) { if (results) { fs_rid_vector_free(results[0]); free(results); } fs_rid_vector_free(mvec); fs_rid_vector_free(empty); add_message(uc, g_strdup_printf("<%s> is empty, not copying", from), 1); return 1; } fs_rid_vector_free(results[0]); free(results); /* get the contents of <from> */ fs_bind_cache_wrapper(uc->qs, NULL, 1, FS_BIND_BY_SUBJECT | FS_BIND_SUBJECT | FS_BIND_PREDICATE | FS_BIND_OBJECT, slot, &results, -1, -1); /* map old bnodes to new ones */ map_bnodes(uc, results[0]); map_bnodes(uc, results[1]); map_bnodes(uc, results[2]); /* delete <to> */ mvec->data[0] = torid; if (fsp_delete_model_all(uc->link, mvec)) { fs_rid_vector_free(mvec); fs_rid_vector_free(empty); add_message(uc, g_strdup_printf("Error while trying to delete %s", to), 1); return 1; } fs_rid_vector_free(mvec); fs_rid_vector_free(empty); /* insert <to> */ fs_resource tores; tores.lex = to; tores.attr= FS_RID_NULL; tores.rid = torid; fsp_res_import(uc->link, FS_RID_SEGMENT(torid, uc->segments), 1, &tores); insert_triples(uc, torid, results[0], results[1], results[2]); add_message(uc, g_strdup_printf("Copied <%s> to <%s>", from, to), 1); add_message(uc, g_strdup_printf("%d triples added, ?? removed", results[0]->length), 1); for (int i=0; i<3; i++) { fs_rid_vector_free(results[i]); } free(results); return 0; }
static void torrent_added(const torrent_info *torrent) { char message[1024]; sprintf(message, "Torrent added: %s", torrent->name); add_message(message); }
Exception::Exception(const char* class_name, const char* method_name, int source_line): exception() { add_message(class_name, method_name, source_line); }
int main(int argc, char **argv) { extern int game_is_being_shut_down; char *p; int i = 0; struct svalue *ret; extern struct svalue catch_value; extern void init_cfuns(void); struct gdexception exception_frame; (void)setlinebuf(stdout); parse_args(argc, argv); const0.type = T_NUMBER; const0.u.number = 0; const1.type = T_NUMBER; const1.u.number = 1; constempty.type = T_FUNCTION; constempty.u.func = &funcempty; funcempty.funtype = FUN_EMPTY; catch_value = const0; /* * Check that the definition of EXTRACT_UCHAR() is correct. */ p = (char *)&i; *p = -10; if (EXTRACT_UCHAR(p) != 0x100 - 10) { (void)fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in config.h.\n"); exit(1); } set_current_time(); #ifdef PROFILE_LPC set_profile_timebase(60.0); /* One minute */ #endif #if RESERVED_SIZE > 0 reserved_area = malloc(RESERVED_SIZE); #endif init_random(); init_tasks(); query_load_av(); init_num_args(); init_machine(); init_cfuns(); init_hash(); /* * Set up the signal handling. */ init_signals(); if (chdir(mudlib_path) == -1) { (void)fprintf(stderr, "Bad mudlib directory: %s\n", MUD_LIB); exit(1); } if (setjmp(exception_frame.e_context)) { clear_state(); add_message("Anomaly in the fabric of world space.\n"); } else { exception_frame.e_exception = NULL; exception_frame.e_catch = 0; exception = &exception_frame; auto_ob = 0; master_ob = 0; if ((auto_ob = load_object("secure/auto", 1, 0, 0)) != NULL) { add_ref(auto_ob, "main"); auto_ob->prog->flags |= PRAGMA_RESIDENT; } get_simul_efun(); master_ob = load_object("secure/master", 1, 0, 0); if (master_ob) { /* * Make sure master_ob is never made a dangling pointer. * Look at apply_master_ob() for more details. */ add_ref(master_ob, "main"); master_ob->prog->flags |= PRAGMA_RESIDENT; resolve_master_fkntab(); create_object(master_ob); load_parse_information(); clear_state(); } } exception = NULL; if (auto_ob == 0) { (void)fprintf(stderr, "The file secure/auto must be loadable.\n"); exit(1); } if (master_ob == 0) { (void)fprintf(stderr, "The file secure/master must be loadable.\n"); exit(1); } set_inc_list(apply_master_ob(M_DEFINE_INCLUDE_DIRS, 0)); { struct svalue* ret1; ret1 = apply_master_ob(M_PREDEF_DEFINES, 0); if (ret1 && ret1->type == T_POINTER) { int ii; for (ii = 0; ii < ret1->u.vec->size; ii++) if (ret1->u.vec->item[ii].type == T_STRING) { add_pre_define(ret1->u.vec->item[ii].u.string); } } } if (flag != NULL) { printf("Applying driver flag: %s\n", flag); push_string(flag, STRING_MSTRING); (void)apply_master_ob(M_FLAG, 1); if (game_is_being_shut_down) { (void)fprintf(stderr, "Shutdown by master object.\n"); exit(0); } } /* * See to it that the mud name is always defined in compiled files */ ret = apply_master_ob(M_GET_MUD_NAME, 0); if (ret && ret->type == T_STRING) { struct lpc_predef_s *tmp; tmp = (struct lpc_predef_s *) xalloc(sizeof(struct lpc_predef_s)); if (!tmp) fatal("xalloc failed\n"); tmp->flag = string_copy(ret->u.string); tmp->next = lpc_predefs; lpc_predefs = tmp; } ret = apply_master_ob(M_GET_VBFC_OBJECT, 0); if (ret && ret->type == T_OBJECT) { vbfc_object = ret->u.ob; INCREF(vbfc_object->ref); } else vbfc_object = 0; if (game_is_being_shut_down) exit(1); init_call_out(); preload_objects(e_flag); (void)apply_master_ob(M_FINAL_BOOT, 0); mainloop(); return 0; }
void check_psionic_talents (CHAR_DATA *ch) { ACCOUNT_DATA *account; int chance = 0, roll = 0; int cur_talents = 0, i = 0, j = 1; int talents [8] = { SKILL_CLAIRVOYANCE, SKILL_DANGER_SENSE, SKILL_EMPATHIC_HEAL, SKILL_HEX, SKILL_MENTAL_BOLT, SKILL_PRESCIENCE, SKILL_SENSITIVITY, SKILL_TELEPATHY }; bool check = TRUE, again = TRUE, awarded = FALSE, block = FALSE; char buf [MAX_STRING_LENGTH] = {'\0'}; char *date = NULL; if ( is_newbie (ch) || ch->aur <= 15 ) return; if ( ch->pc && ch->pc->account ) { if ( !(account = load_account (ch->pc->account)) ) return; if ( IS_SET (account->flags, ACCOUNT_NOPSI) ) block = TRUE; if ( account->roleplay_points < 2 ) block = TRUE; free_account (account); } else return; if ( block ) return; if ( ch->aur < 16 ) return; else if ( ch->aur == 16 ) chance = 5; else if ( ch->aur == 17 ) chance = 10; else if ( ch->aur == 18 ) chance = 20; else if ( ch->aur == 19 ) chance = 30; else if ( ch->aur == 20 ) chance = 45; else if ( ch->aur == 21 ) chance = 50; else if ( ch->aur == 22 ) chance = 60; else if ( ch->aur == 23 ) chance = 70; else if ( ch->aur == 24 ) chance = 80; else chance = 95; chance += number(1,10); chance = MIN(chance, 95); for ( i = 0; i <= 7; i++ ) if ( ch->skills[talents[i]] ) cur_talents++; while ( check && cur_talents <= 4 ) { if ( number(1,100) <= chance ) { again = TRUE; while ( again ) { roll = talents[number(0,7)]; if ( !ch->skills [roll] ) { ch->skills [roll] = 1; cur_talents++; again = FALSE; awarded = TRUE; } chance /= 2; } if ( cur_talents >= 4 ) check = FALSE; } else check = FALSE; } if ( !awarded ) return; snprintf (buf, MAX_STRING_LENGTH, "This character rolled positive for the following talents:\n\n"); for ( i = 0; i <= 7; i++ ) if ( ch->skills [talents[i]] ) snprintf (buf + strlen(buf), MAX_STRING_LENGTH, " %d. %s\n", j++, skill_data[talents[i]].skill_name); date = timestr(date); add_message ("Psi_talents", 2, "Server", date, ch->tname, "", buf, 0); add_message (ch->tname, 3, "Server", date, "Psionic Talents.", "", buf, 0); mem_free (date); }
static void Read_message() { static char mess[SPREAD_MESS_LEN]; char sender[MAX_GROUP_NAME]; char target_groups[MAX_MEMBERS][MAX_GROUP_NAME]; membership_info memb_info; vs_set_info vssets[MAX_VSSETS]; unsigned int my_vsset_index; int num_vs_sets; char members[MAX_MEMBERS][MAX_GROUP_NAME]; int num_groups; int service_type; int16 mess_type; int endian_mismatch; int i,j; int ret; service_type = 0; ret = SP_receive( Mbox, &service_type, sender, 100, &num_groups, target_groups, &mess_type, &endian_mismatch, sizeof(mess), mess ); if( ret < 0 ) { if ( (ret == GROUPS_TOO_SHORT) || (ret == BUFFER_TOO_SHORT) ) { service_type = DROP_RECV; printf("\n========Buffers or Groups too Short=======\n"); ret = SP_receive( Mbox, &service_type, sender, MAX_MEMBERS, &num_groups, target_groups, &mess_type, &endian_mismatch, sizeof(mess), mess ); } } if (ret < 0 ) { if( ! To_exit ) { SP_error( ret ); printf("\n============================\n"); printf("\nBye.\n"); } exit( 0 ); } if( Is_regular_mess( service_type ) ) { //printf("message from %s, of type %d, (endian %d) to %d groups \n(%d bytes): %s\n", sender, mess_type, endian_mismatch, num_groups, ret, mess ); typecheck* type = (typecheck*)mess; if (type->type == TYPE_JOIN_CHATROOM) { join_chatroom* dat = (join_chatroom*)mess; ret = add_user(dat->u_id,dat->sp_id,dat->chatroom); } else if (type->type == TYPE_LEAVE_CHATROOM) { leave_chatroom* dat = (leave_chatroom*)mess; rm_user(dat->sp_id); } else if (type->type == TYPE_SEND_MSG) { message* dat = (message*)mess; if (strlen(chatroom) == 0) add_room(chatroom); lamport* ts = malloc(sizeof(lamport)); ts->server_id = dat->timestamp.server_id; ts->index = dat->timestamp.index; printf("[%d,%d]\n",ts->server_id,ts->index); add_message(ts, dat->u_id, dat->chatroom, dat->mess); } else if (type->type == TYPE_LIKE_MSG) { like* dat = (like*)mess; lamport* lts = malloc(sizeof(lamport)); lamport* mts = malloc(sizeof(lamport)); lts->server_id = dat->timestamp.server_id; lts->index = dat->timestamp.index; mts->server_id = dat->timestamp.server_id; mts->index = dat->timestamp.index; ret = add_like(dat->like_state, lts, dat->u_id, chatroom, mts); printf("~~~~~~~~ %d:[%d,%d | %d,%d] %d %s %s \n",ret, lts->server_id,lts->index,mts->server_id,mts->index,dat->like_state,dat->u_id,chatroom); } master_print(); }else if( Is_membership_mess( service_type ) ) { ret = SP_get_memb_info( mess, service_type, &memb_info ); if (ret < 0) { printf("BUG: membership message does not have valid body\n"); SP_error( ret ); exit( 1 ); } if ( Is_reg_memb_mess( service_type ) ) { printf("Received REGULAR membership for group %s with %d members, where I am member %d:\n", sender, num_groups, mess_type ); for( i=0; i < num_groups; i++ ) printf("\t%s\n", &target_groups[i][0] ); printf("grp id is %d %d %d\n",memb_info.gid.id[0], memb_info.gid.id[1], memb_info.gid.id[2] ); if( Is_caused_join_mess( service_type ) ) { printf("Due to the JOIN of %s\n", memb_info.changed_member ); }else if( Is_caused_leave_mess( service_type ) ){ printf("Due to the LEAVE of %s\n", memb_info.changed_member ); }else if( Is_caused_disconnect_mess( service_type ) ){ printf("Due to the DISCONNECT of %s\n", memb_info.changed_member ); }else if( Is_caused_network_mess( service_type ) ){ printf("Due to NETWORK change with %u VS sets\n", memb_info.num_vs_sets); num_vs_sets = SP_get_vs_sets_info( mess, &vssets[0], MAX_VSSETS, &my_vsset_index ); if (num_vs_sets < 0) { printf("BUG: membership message has more then %d vs sets. Recompile with larger MAX_VSSETS\n", MAX_VSSETS); SP_error( num_vs_sets ); exit( 1 ); } for( i = 0; i < num_vs_sets; i++ ) { printf("%s VS set %d has %u members:\n", (i == my_vsset_index) ? ("LOCAL") : ("OTHER"), i, vssets[i].num_members ); ret = SP_get_vs_set_members(mess, &vssets[i], members, MAX_MEMBERS); if (ret < 0) { printf("VS Set has more then %d members. Recompile with larger MAX_MEMBERS\n", MAX_MEMBERS); SP_error( ret ); exit( 1 ); } for( j = 0; j < vssets[i].num_members; j++ ) printf("\t%s\n", members[j] ); } } }else if( Is_transition_mess( service_type ) ) { printf("received TRANSITIONAL membership for group %s\n", sender ); }else if( Is_caused_leave_mess( service_type ) ){ printf("received membership message that left group %s\n", sender ); }else printf("received incorrecty membership message of type 0x%x\n", service_type ); } else if ( Is_reject_mess( service_type ) ) { printf("REJECTED message from %s, of servicetype 0x%x messtype %d, (endian %d) to %d groups \n(%d bytes): %s\n", sender, service_type, mess_type, endian_mismatch, num_groups, ret, mess ); }else printf("received message of unknown message type 0x%x with ret %d\n", service_type, ret); printf("\n"); fflush(stdout); }
int __send_local(long ticket, unsigned short type, int slot, long value, unsigned short flags) { message *msg = create_message(my_id(), my_id(), ticket, type, slot, value, flags); log_message("send_local", msg); add_message(msg); return 1; }
void tutorial_game::post_action(action_id act) { switch (act) { case ACTION_RELOAD: if (g->u.weapon.is_gun() && !tutorials_seen[LESSON_GUN_FIRE]) { g->summon_mon("mon_zombie", tripoint(g->u.posx(), g->u.posy() - 6, g->u.posz())); g->summon_mon("mon_zombie", tripoint(g->u.posx() + 2, g->u.posy() - 5, g->u.posz())); g->summon_mon("mon_zombie", tripoint(g->u.posx() - 2, g->u.posy() - 5, g->u.posz())); add_message(LESSON_GUN_FIRE); } break; case ACTION_OPEN: add_message(LESSON_CLOSE); break; case ACTION_CLOSE: add_message(LESSON_SMASH); break; case ACTION_USE: if (g->u.has_amount("grenade_act", 1)) add_message(LESSON_ACT_GRENADE); for (int x = g->u.posx() - 1; x <= g->u.posx() + 1; x++) { for (int y = g->u.posy() - 1; y <= g->u.posy() + 1; y++) { if (g->m.tr_at({x, y, g->u.posz()}).id == trap_str_id( "tr_bubblewrap" )) add_message(LESSON_ACT_BUBBLEWRAP); } } break; case ACTION_EAT: if (g->u.last_item == "codeine") add_message(LESSON_TOOK_PAINKILLER); else if (g->u.last_item == "cig") add_message(LESSON_TOOK_CIG); else if (g->u.last_item == "water") add_message(LESSON_DRANK_WATER); break; case ACTION_WEAR: { item it( g->u.last_item, 0 ); if (it.is_armor()) { if (it.get_coverage() >= 2 || it.get_thickness() >= 2) add_message(LESSON_WORE_ARMOR); if (it.get_storage() >= 20) add_message(LESSON_WORE_STORAGE); if (it.get_env_resist() >= 2) add_message(LESSON_WORE_MASK); } } break; case ACTION_WIELD: if (g->u.weapon.is_gun()) add_message(LESSON_GUN_LOAD); break; case ACTION_EXAMINE: add_message(LESSON_INTERACT); // Fall through to... case ACTION_PICKUP: { item it( g->u.last_item, 0 ); if (it.is_armor()) add_message(LESSON_GOT_ARMOR); else if (it.is_gun()) add_message(LESSON_GOT_GUN); else if (it.is_ammo()) add_message(LESSON_GOT_AMMO); else if (it.is_tool()) add_message(LESSON_GOT_TOOL); else if (it.is_food()) add_message(LESSON_GOT_FOOD); else if (it.is_weap()) add_message(LESSON_GOT_WEAPON); } break; default: //TODO: add more actions here break; } }
int handle_B_input() { char buf[3] = {0}; size_t l = 0; while (l < 1) l = receive_until( buf, '\n', 2); if (buf[0] == '7') { // LOGOUT printf("Logging out of user @s\n", current_user->name); logout(); return 2; } else if (buf[0] == '8') { // EXIT printf("The end.\n"); _terminate(0); } else if (buf[0] == '2') { // SEND MESSAGE from drafts list if (get_draft_count(current_user->name) == 0) { printf("Must create draft first.\n"); return 0; } // list all drafts with number in front // user enters valid number // that message is changed from drafts 1->0 print_draft_for_send(current_user->name); } else if (buf[0] == '1') { // ADD A MESSAGE TO DRAFTS if (msg_count_login >= MAX_MESSAGES_LOGIN) { printf("Reached maximum messages for this session.\n"); return 0; } printf("To:\n"); char dest[MAX_NAME_LEN]; size_t len = receive_until( dest, '\n', MAX_NAME_LEN - 1); dest[len++] = 0; printf("Message:\n"); char msg_buf[MAX_MSG_LEN]; len = receive_until( msg_buf, '\n', MAX_MSG_LEN - 1); msg_buf[len++] = 0; if (add_message(dest, current_user->name, msg_buf, 1) != 1) printf("add_message failed\n"); } else if (buf[0] == '3') { // LIST MESSAGES // list all messages in summary if (get_total_count() == 0) { printf("No messages.\n"); return 0; } list_all_messages(); } else if (buf[0] == '4') { // LIST DRAFTS list_drafts(current_user->name); } else if (buf[0] == '5') { // LIST INCOMING MSGS list_inbox(current_user->name); } else if (buf[0] == '6') { // DELETE MESSAGE from drafts list if (get_draft_count(current_user->name) == 0) { printf("Must create draft first.\n"); return 0; } print_draft_for_del(current_user->name); } else printf("unknown input: @c @c", buf[0], buf[1]); return 0; }
void tutorial_game::post_action( action_id act ) { switch( act ) { case ACTION_RELOAD: if( g->u.weapon.is_gun() && !tutorials_seen[LESSON_GUN_FIRE] ) { g->summon_mon( mon_zombie, tripoint( g->u.posx(), g->u.posy() - 6, g->u.posz() ) ); g->summon_mon( mon_zombie, tripoint( g->u.posx() + 2, g->u.posy() - 5, g->u.posz() ) ); g->summon_mon( mon_zombie, tripoint( g->u.posx() - 2, g->u.posy() - 5, g->u.posz() ) ); add_message( LESSON_GUN_FIRE ); } break; case ACTION_OPEN: add_message( LESSON_CLOSE ); break; case ACTION_CLOSE: add_message( LESSON_SMASH ); break; case ACTION_USE: if( g->u.has_amount( "grenade_act", 1 ) ) { add_message( LESSON_ACT_GRENADE ); } for( const tripoint &dest : g->m.points_in_radius( g->u.pos(), 1 ) ) { if( g->m.tr_at( dest ).id == trap_str_id( "tr_bubblewrap" ) ) { add_message( LESSON_ACT_BUBBLEWRAP ); } } break; case ACTION_EAT: if( g->u.last_item == "codeine" ) { add_message( LESSON_TOOK_PAINKILLER ); } else if( g->u.last_item == "cig" ) { add_message( LESSON_TOOK_CIG ); } else if( g->u.last_item == "water" ) { add_message( LESSON_DRANK_WATER ); } break; case ACTION_WEAR: { item it( g->u.last_item, 0 ); if( it.is_armor() ) { if( it.get_coverage() >= 2 || it.get_thickness() >= 2 ) { add_message( LESSON_WORE_ARMOR ); } if( it.get_storage() >= units::from_liter( 5 ) ) { add_message( LESSON_WORE_STORAGE ); } if( it.get_env_resist() >= 2 ) { add_message( LESSON_WORE_MASK ); } } } break; case ACTION_WIELD: if( g->u.weapon.is_gun() ) { add_message( LESSON_GUN_LOAD ); } break; case ACTION_EXAMINE: add_message( LESSON_INTERACT ); /* fallthrough */ case ACTION_PICKUP: { item it( g->u.last_item, 0 ); if( it.is_armor() ) { add_message( LESSON_GOT_ARMOR ); } else if( it.is_gun() ) { add_message( LESSON_GOT_GUN ); } else if( it.is_ammo() ) { add_message( LESSON_GOT_AMMO ); } else if( it.is_tool() ) { add_message( LESSON_GOT_TOOL ); } else if( it.is_food() ) { add_message( LESSON_GOT_FOOD ); } else if( it.is_melee() ) { add_message( LESSON_GOT_WEAPON ); } } break; default: //TODO: add more actions here break; } }
void load_messages(const char *filename) /* I - Message file */ { FILE *fp; /* Message file */ message_t *temp; /* Current message */ char s[4096], /* String buffer */ *ptr; /* Pointer into buffer */ int line; /* Current line */ int length; /* Length of combined strings */ if ((fp = fopen(filename, "r")) == NULL) return; printf("espmsg: Loading \"%s\"...", filename); fflush(stdout); temp = NULL; line = 0; while (fgets(s, sizeof(s), fp) != NULL) { line ++; /* * Skip comment lines... */ if (s[0] == '#') continue; /* * Strip trailing newline and quote... */ for (ptr = s + strlen(s) - 1; ptr >= s && isspace(*ptr); *ptr-- = '\0'); if (ptr < s) continue; if (*ptr != '\"') { printf("espmsg: Expected quoted string on line %d!\n", line); continue; } *ptr = '\0'; /* * Find start of value... */ if ((ptr = strchr(s, '\"')) == NULL) { printf("espmsg: Expected quoted string on line %d!\n", line); continue; } ptr ++; if (!strncmp(s, "msgid", 5)) temp = add_message(ptr); else if (s[0] != '\"' && strncmp(s, "msgstr", 6)) { printf("espmsg: Unexpected text on line %d!\n", line); continue; } else if (!temp) { printf("espmsg: Need a msgid line before any translation strings " "on line %d!\n", line); continue; } else if (temp->str) { /* * Append the string... */ length = strlen(temp->str) + strlen(ptr) + 1; temp->str = realloc(temp->str, length); strcat(temp->str, ptr); } else { /* * Set the string... */ temp->str = strdup(ptr); } } fclose(fp); printf(" %d messages loaded.\n", num_messages); }
void tutorial_game::post_action(action_id act) { switch (act) { case ACTION_RELOAD: if (g->u.weapon.is_gun() && !tutorials_seen[LESSON_GUN_FIRE]) { monster tmp(GetMType("mon_zombie"), g->u.posx, g->u.posy - 6); g->add_zombie(tmp); tmp.spawn(g->u.posx + 2, g->u.posy - 5); g->add_zombie(tmp); tmp.spawn(g->u.posx - 2, g->u.posy - 5); g->add_zombie(tmp); add_message(LESSON_GUN_FIRE); } break; case ACTION_OPEN: add_message(LESSON_CLOSE); break; case ACTION_CLOSE: add_message(LESSON_SMASH); break; case ACTION_USE: if (g->u.has_amount("grenade_act", 1)) add_message(LESSON_ACT_GRENADE); for (int x = g->u.posx - 1; x <= g->u.posx + 1; x++) { for (int y = g->u.posy - 1; y <= g->u.posy + 1; y++) { if (g->m.tr_at(x, y) == tr_bubblewrap) add_message(LESSON_ACT_BUBBLEWRAP); } } break; case ACTION_EAT: if (g->u.last_item == "codeine") add_message(LESSON_TOOK_PAINKILLER); else if (g->u.last_item == "cig") add_message(LESSON_TOOK_CIG); else if (g->u.last_item == "water") add_message(LESSON_DRANK_WATER); break; case ACTION_WEAR: { itype *it = itypes[ g->u.last_item]; if (it->is_armor()) { it_armor *armor = dynamic_cast<it_armor*>(it); if (armor->coverage >= 2 || armor->thickness >= 2) add_message(LESSON_WORE_ARMOR); if (armor->storage >= 20) add_message(LESSON_WORE_STORAGE); if (armor->env_resist >= 2) add_message(LESSON_WORE_MASK); } } break; case ACTION_WIELD: if (g->u.weapon.is_gun()) add_message(LESSON_GUN_LOAD); break; case ACTION_EXAMINE: add_message(LESSON_INTERACT); // Fall through to... case ACTION_PICKUP: { itype *it = itypes[ g->u.last_item ]; if (it->is_armor()) add_message(LESSON_GOT_ARMOR); else if (it->is_gun()) add_message(LESSON_GOT_GUN); else if (it->is_ammo()) add_message(LESSON_GOT_AMMO); else if (it->is_tool()) add_message(LESSON_GOT_TOOL); else if (it->is_food()) add_message(LESSON_GOT_FOOD); else if (it->melee_dam > 7 || it->melee_cut > 5) add_message(LESSON_GOT_WEAPON); if (g->u.volume_carried() > g->u.volume_capacity() - 2) add_message(LESSON_OVERLOADED); } break; default: //TODO: add more actions here break; } }
void scan_file(const char *filename) /* I - File to scan */ { FILE *fp; /* File */ int ch, lastch; /* Current and previous characters */ char s[4096], /* String buffer */ *ptr; /* Pointer into buffer */ int count, /* Number of messages */ orig_messages; /* Original number of messages */ message_t *temp; /* Current message */ if ((fp = fopen(filename, "r")) == NULL) { perror(filename); return; } printf("Scanning \"%s\"...", filename); fflush(stdout); lastch = 0; count = 0; orig_messages = num_messages; while ((ch = getc(fp)) != EOF) { switch (ch) { case '/' : if (lastch == '/') { while ((ch = getc(fp)) != EOF) if (ch == '\n') break; } break; case '*' : if (lastch == '/') { lastch = ch; while ((ch = getc(fp)) != EOF) { if (ch == '/' && lastch == '*') break; lastch = ch; } } break; case '(' : if (lastch == '_') { if ((ch = getc(fp)) == '\"') { ptr = s; do { while ((ch = getc(fp)) != EOF) { if (ch == '\"') break; else if (ch == '\\') { lastch = ch; ch = getc(fp); if (ch == '\n') continue; if (ptr < (s + sizeof(s) - 1)) *ptr++ = lastch; } if (ptr < (s + sizeof(s) - 1)) { if (ch == '\n') { if (lastch != '\\') *ptr++ = '\\'; *ptr++ = 'n'; } else *ptr++ = ch; } lastch = ch; } /* * Handle merged strings ("string" "string")... */ if (ch == '\"') while ((ch = getc(fp)) != EOF) if (!isspace(ch)) break; } while (ch == '\"'); *ptr = '\0'; /* * Skip symbol labels... */ if (s[0] == '@') break; /* * Only localize strings with letters - numbers almost * never need to be localized... */ for (ptr = s; *ptr; ptr ++) if (isalpha(*ptr)) break; if (*ptr) if ((temp = add_message(s)) != NULL) { /* * Added the message successfully... */ temp->ref_count ++; count ++; } } else { ungetc(ch, fp); ch = '('; } } break; } lastch = ch; } fclose(fp); printf(" %d messages (%d new).\n", count, num_messages - orig_messages); }
EditorLog::EditorLog() { VBoxContainer *vb = memnew( VBoxContainer); add_child(vb); vb->set_v_size_flags(SIZE_EXPAND_FILL); HBoxContainer *hb = memnew( HBoxContainer ); vb->add_child(hb); title = memnew( Label ); title->set_text(" Output:"); title->set_h_size_flags(SIZE_EXPAND_FILL); hb->add_child(title); button = memnew( ToolButton ); button->set_text_align(Button::ALIGN_LEFT); button->connect("pressed",this,"_flip_request"); button->set_focus_mode(FOCUS_NONE); button->set_clip_text(true); button->set_tooltip("Open/Close output panel."); //pd = memnew( PaneDrag ); //hb->add_child(pd); //pd->connect("dragged",this,"_dragged"); //pd->set_default_cursor_shape(Control::CURSOR_MOVE); tb = memnew( TextureButton ); hb->add_child(tb); tb->connect("pressed",this,"_close_request"); ec = memnew( Control); vb->add_child(ec); ec->set_custom_minimum_size(Size2(0,100)); ec->set_v_size_flags(SIZE_EXPAND_FILL); PanelContainer *pc = memnew( PanelContainer ); pc->add_style_override("panel",get_stylebox("normal","TextEdit")); ec->add_child(pc); pc->set_area_as_parent_rect(); log = memnew( RichTextLabel ); log->set_scroll_follow(true); log->set_selection_enabled(true); log->set_focus_mode(FOCUS_CLICK); pc->add_child(log); add_message(VERSION_FULL_NAME" (c) 2008-2014 Juan Linietsky, Ariel Manzur."); //log->add_text("Initialization Complete.\n"); //because it looks cool. add_style_override("panel",get_stylebox("panelf","Panel")); eh.errfunc=_error_handler; eh.userdata=this; add_error_handler(&eh); current=Thread::get_caller_ID(); EditorNode::get_undo_redo()->set_commit_notify_callback(_undo_redo_cbk,this); hide(); }
/*telepathic, smart*/ gamestate_t t_s(npc *monster, cell_t *cell_arr, path_node_t *c_path, character *player) { int n_x, n_y, i, j, min, dam; gamestate_t result; double dist_a, dist_b; cell_t *c_cell, *n_cell; path_node_t *path; character *temp; std::stringstream mes; result = normal; c_cell = cell_arr + (MAP_WIDTH * monster->y_pos) + monster->x_pos; min = 10000; for(i = monster->y_pos - 1; i < monster->y_pos + 2; i++) { for(j = monster->x_pos - 1; j < monster->x_pos + 2; j++) { if(i == monster->y_pos && j == monster->x_pos) { continue; } path = c_path + (MAP_WIDTH * i) + j; n_cell = cell_arr + (MAP_WIDTH * i) + j; if(path->distance < min) { min = path->distance; n_y = i; n_x = j; } else if(path->distance == min && n_cell->cell_type == c_cell->cell_type) { dist_a = pow(player->x_pos - n_x, 2); dist_a += pow(player->y_pos - n_y, 2); dist_a = sqrt(dist_a); dist_b = pow(player->x_pos - j, 2); dist_b += pow(player->y_pos - i, 2); dist_b = sqrt(dist_b); if(dist_b < dist_a) { min = path->distance; n_y = i; n_x = j; } } } } n_cell = cell_arr + (MAP_WIDTH * n_y) + n_x; //if pass do not worry about tunneling if(!(monster->traits & IS_PASS)) { if(n_cell->cell_type == stone) { n_cell->hardness -= 85; if(n_cell->hardness > 0) { update_tunn_map(c_path, cell_arr); return normal; } else { n_cell->hardness = 0; n_cell->cell_type = corridor; update_tunn_map(c_path, cell_arr); result = update_nt_map; } } } n_cell = cell_arr + (MAP_WIDTH * n_y) + n_x; if(n_cell->character != NULL) { if(((character *)(n_cell->character))->print() == '@') { dam = monster->damage->roll(); dam = ((pc *)(n_cell->character))->attack(dam); mes << "Attacked by " << *monster->name; mes << " for " << dam << " hitpoints"; add_message(mes.str()); if(n_cell->character->hitpoints <= 0) { result = player_died; n_cell->character = NULL; } } else { temp = n_cell->character; temp->x_pos = monster->x_pos; temp->y_pos = monster->y_pos; c_cell->character = temp; monster->y_pos = n_y; monster->x_pos = n_x; n_cell->character = monster; } return result; } monster->y_pos = n_y; monster->x_pos = n_x; c_cell->character = NULL; n_cell->character = monster; return result; }