void move_curitem(int direction) { list_item tmp; if(curitem < 0 || curitem > last_item()) return; tmp = item_create(); item_copy(tmp, db_item_get(curitem)); switch(direction) { case MOVE_ITEM_UP: if( curitem < 1 ) goto out_move; item_copy(db_item_get(curitem), db_item_get(curitem - 1)); item_copy(db_item_get(curitem-1), tmp); scroll_up(); break; case MOVE_ITEM_DOWN: if(curitem >= last_item()) goto out_move; item_copy(db_item_get(curitem), db_item_get(curitem + 1)); item_copy(db_item_get(curitem + 1), tmp); scroll_down(); break; } out_move: item_free(&tmp); }
int parse_database(FILE *in) { char *line = NULL; char *tmp; int sec=0, field; list_item item; item = item_create(); for(;;) { line = getaline(in); if(feof(in)) { if(item[field_id(NAME)] && sec) { add_item2database(item); } else { item_empty(item); } break; } if(!*line || *line == '\n' || *line == '#') { goto next; } else if(*line == '[') { if(item[field_id(NAME)] && sec ) { add_item2database(item); } else { item_empty(item); } sec = 1; memset(item, 0, ITEM_SIZE); if(!(tmp = strchr(line, ']'))) sec = 0; /*incorrect section lines are skipped*/ } else if((tmp = strchr(line, '=') ) && sec) { *tmp++ = '\0'; find_field_number(line, &field); if(field != -1) { item[field] = xstrdup(tmp); goto next; } else if(!strcasecmp(opt_get_str(STR_PRESERVE_FIELDS), "all")){ declare_unknown_field(line); item = xrealloc(item, ITEM_SIZE); item[fields_count - 1] = xstrdup(tmp); goto next; } } next: xfree(line); } xfree(line); item_free(&item); return 0; }
CItem *CItemCreator::CreateItem() { CItem *item = item_create(); if (!item) { RunStateError("创建CItem失败!"); return nullptr; } return item; }
int item_pb(t_list *list, void *data, int size) { t_item *item; item = item_create(data, size); if (list == NULL || item == NULL) return (-1); item->prev = list->tail; if (list->tail != NULL) list->tail->next = item; if (list->head == NULL) list->head = item; list->tail = item; list->len += 1; return (1); }
// 获得道具 int item_getitem( int actor_index, int itemkind, int itemnum, char path ) { if ( actor_index < 0 || actor_index >= g_maxactornum ) return -1; if ( itemkind <= 0 || itemkind >= g_itemkindnum ) return -1; if ( itemnum <= 0 ) return -1; Item * pitem = NULL; int item_offset; char type; short itemtype; ItemOut ItemOut[MAX_ACTOR_ITEMNUM] = { 0 }; int item_count = 0; // 创建道具 item_count = item_create( actor_index, itemkind, itemnum, ItemOut ); if ( item_count <= 0 ) return -1; itemtype = item_gettype( itemkind ); item_offset = ItemOut[0].m_item_offset; type = 1; for ( int tmpi = 0; tmpi < item_count; tmpi++ ) { item_offset = ItemOut[tmpi].m_item_offset; if ( item_offset >= 0 && item_offset < MAX_ACTOR_ITEMNUM ) pitem = &g_actors[actor_index].item[item_offset]; else continue; item_sendget( actor_index, -1, item_offset, ItemOut[tmpi].m_count, path ); // 记录log if ( tmpi == item_count - 1 ) type = 0; wlog( type, LOGOP_ITEMGET, path, itemkind, ItemOut[tmpi].m_count, pitem->m_itemid, g_actors[actor_index].actorid, 0 ); } return 0; }
int add_item2database(list_item item) { /* 'name' field is mandatory */ if((item[field_id(NAME)] == NULL) || ! *item[field_id(NAME)]) { item_empty(item); return 1; } if(++items > list_capacity) adjust_list_capacity(); validate_item(item); selected[LAST_ITEM] = 0; database[LAST_ITEM] = item_create(); item_copy(database[LAST_ITEM], item); return 0; }
int duplicate_item() { list_item item; if(curitem < 0) return 1; item = item_create(); item_duplicate(item, db_item_get(curitem)); if(add_item2database(item)) { item_free(&item); return 1; } item_free(&item); curitem = last_item(); refresh_list(); return 0; }
/* ** insert data at head of list ** return -1 if error, or elements count */ long list_insert(LIST *list, void *data, long len) { long rval = -1L; if ( list ) { pthread_mutex_lock(list->l_lock); if ( data && len > 0 ) { ITEM *pit = item_create(data, len); if ( pit ) { pit->i_next = list->l_head; if ( ! list->l_tail ) /* single item is pointed to by head and tail */ list->l_tail = pit; list->l_head = pit; list->l_count++; /* increment the item count */ rval = list->l_count; } } pthread_mutex_unlock(list->l_lock); } return rval; }
domain domain_create(int nitem, int nclassmax, int clusterflag, double alpha, double alphahyp, int label, int *initclasses) { int i; domain dmn; dmn = (domain) my_malloc(sizeof(struct domain_str)); dmn->nitem = nitem; dmn->nclassmax = nclassmax; dmn->clusterflag= clusterflag; dmn->alpha = alpha; dmn->alphahyp = alphahyp; dmn->ninstances = 0; dmn->instances= (int **) my_malloc(ps.maxdim*ps.maxrel*sizeof(int *)); for (i = 0; i < ps.maxdim*ps.maxrel; i++) { dmn->instances[i] = (int *) my_malloc(2*sizeof(int)); } dmn->classorder = frontlist_create(nclassmax); dmn->classes = (itemclass *) my_malloc(nclassmax*sizeof(itemclass)); for (i = 0; i < nclassmax; i++) { dmn->classes[i] = itemclass_create(nitem); } dmn->items= (item *) my_malloc(nitem*sizeof(item)); fprintf(stderr,"%p TOTAL %d\n",dmn,nitem); for (i = 0; i < nitem; i++) { fprintf(stderr,"%p Creating %d\n",dmn,i); dmn->items[i] = item_create(); } dmn->label = label; dmn->init = (int *) my_malloc(nitem*sizeof(int)); if (initclasses != NULL) { for (i = 0; i < nitem; i++) { dmn->init[i] = initclasses[i]; } } dmn->prior = 0.0; return dmn; }
void generateLevel(struct TileElement** tiles, int num_tiles, struct CreatureElement** creatures, int num_creatures, struct ActionElement** actions) { int curr = 0; srand(time(NULL)); fprintf(stderr, "rnd: %i\n", rand()); fprintf(stderr, "rnd2: %f\n", (float)rand()/(float)RAND_MAX); /* struct Room r1; r1.pos.x = 1; r1.pos.y = 2; r1.dim.x = 5; r1.dim.y = 6; curr += addRoom(tiles, r1, curr); struct Room r2; r2.pos.x = 8; r2.pos.y = 3; r2.dim.x = 4; r2.dim.y = 7; curr += addRoom(tiles, r2, curr); */ //struct Room path; /* while (curr < num_tiles) { struct Tile t; t.pos.x = curr; t.pos.y = curr; tiles[curr] = t; ++curr; }*/ struct CaveRoom cr1; struct CaveRoomGenerator caveGen; gen_cave_gen(&caveGen, 7, 8, 7, 7, 9, 9, 4, 4, 6, 6, 0, M_PI*2); //create_cave_room(&cr1, 0, 0, 7, 2.0f, 3, 2, 4, 5); gen_cave_room(&cr1, caveGen); gen_exits(&cr1); struct CaveRoom cr2; cave_branch(&cr1, &caveGen, &cr2); addCaveRoom(tiles, &cr1, curr); //pos_print(cr2.origin); addCaveRoom(tiles, &cr2, curr); struct Creature *creat = malloc(sizeof(*creat)); creature_create(creat, TYP_GAS_BALL); creat->pos.x = 2; creat->pos.y = 4; creature_add_sub_type(creat, STYP_EXISTS); game_add_creature(creatures, creat); struct Creature *bj = malloc(sizeof(*bj)); creature_create(bj, TYP_BLUE_JELLY); bj->pos.x = 4; bj->pos.y = 4; creature_add_sub_type(bj, STYP_EXISTS); game_add_creature(creatures, bj); bj->items = malloc(sizeof(*bj->items)); bj->items->next = NULL; bj->items->elem = malloc(sizeof(*bj->items->elem)); item_create(bj->items->elem, ITM_BLUE_JELLY); struct Action* follow_act; action_create(&follow_act, ACT_FOLLOW); struct ActionObject* user; action_obj_create(&user, ACT_OBJ_CREATURE); user->creature = mainGame->player; action_add(follow_act, user, ACT_ROLE_USER); struct ActionObject* creatActObj; action_obj_create(&creatActObj, ACT_OBJ_CREATURE); creatActObj->creature = creat; action_add(follow_act, creatActObj, ACT_ROLE_TARGET); struct ActionObject* mag; action_obj_create(&mag, ACT_OBJ_FLOAT); mag->fvalue = 1.0f; action_add(follow_act, mag, ACT_ROLE_MAGNITUDE); // make sure it's disabled at the start //action_add_subtype(follow_act, SACT_DISABLED); game_add_action(actions, follow_act); struct TileElement* currTile = *tiles; while(currTile != NULL) { tile_make_walls(*tiles, currTile->elem); currTile = currTile->next; } };
void world_init(void) { world_jump_vy=2*jump_max_h/jump_semi_t; world_g=world_jump_vy/jump_semi_t; world_walker_v=c_v_slow; struct tms paraeltimes; srand((unsigned int)times(¶eltimes)); world.t=0.0; world.waiting_to_start=True; world.player.is_player=True; world.player.x=0.0; world.player.y=0.0; world.player.vx=c_v_slow*0; // para que empiece parado hasta el go world.player.vy=0.0; world.player.sprite_class=sprite_classes[SPRCLS_ID_PLAYER]; sprite_set_state(&world.player, STID_PLAYER_STOP); // world.player.anim_state=&(sprite_classes[SPRCLS_ID_PLAYER]->animstate[0]); world.player.anim_lastT=world.t; world.player_vida=1.0; world.player_deadline=60.0; world.player_checkpoint=7000.0; world.player_untouchable_time=0.0; world_zero_sprites(); item_zero(&world); // world_create_walker(200,0); // world_create_walker(400,0); // world_create_walker(600,0); // // world_create_walker(700,1); // world_create_walker(1000,1); // // // world_create_walker(900,2); // // world_create_walker(-800,3); // // world.time_next_piligrim=random_exp_time(10.0); // world.time_next_cansado=random_exp_time(5.0); // world.time_next_bici=random_exp_time(10.0); // printf("primer generado en t=%f\n",world.time_next_piligrim); render_clean_bocina(); world.cam_x=-c_cam_offset; world.cam_v=0; // para que el jugador empiece fuera de la pantalla c_cam_init_free=1; world.cam_x+=c_cam_offset+300; // para que empiece dentro y parado esperando al go world.cam_x=-2*c_cam_offset; world.player.x+=world_pos0; world.zone_width=1000; world.zone_level_factor[0]=1.0; world.zone_level_factor[1]=5; world.zone[0].i[0]=-100; world.zone[1].i[0]=-100; world.zone[2].i[0]=-100; generador_init(); t_itemPtr tumba_item=item_create(&world, ITEM_CLS_TUMBA); tumba_item->x=game_last_dead; tumba_item->y=0.0; tumba_item->tumba_owner=-1; int itumba; for (itumba=0; itumba<HIGHSCORE_MAX_TUMBAS; itumba++) { if ( highscore_table[itumba].score > HIGHSCORE_MINX_TUMBAS ) { t_itemPtr tumba_item=item_create(&world, ITEM_CLS_TUMBA); tumba_item->x=100.0*highscore_table[itumba].score+world_pos0; tumba_item->y=0.0; tumba_item->tumba_owner=itumba; } } // t_itemPtr aux_item=item_create(&world, ITEM_CLS_COMIDA_1); // aux_item->x=1030.0; // aux_item->y=150.0; }
void world_update_zone_if_needed(int level, int izone) { int zone_seed=generador_zone_seed; int i_zone_storage=izone%3; if (izone<0) i_zone_storage+=3; if (world.zone[i_zone_storage].i[level]==izone) { // no need to update return; } //printf("generated new zone %d level %d\n",izone, level); world.zone[i_zone_storage].i[level]=izone; t_world_zonePtr thezone; thezone=&(world.zone[i_zone_storage]); if (level==0) { // genera zonas de nivel 0 o de primer plano unsigned int s=izone+zone_seed; thezone->prueba_h=(rand_r(&s)%10)*10.0; // genera numeros aleatorios y los objetos de la zona // 4 arboles al azar con posicion uniformemente distribuida en la zona int i; for (i=0;i<4;i++) { thezone->arbol_present[i]=0; if (rand_r(&s)%100 <25) { thezone->arbol_present[i]=2+(rand_r(&s)%2); thezone->arbol_pos[i]=rand_r(&s)%1000; } } // int hay_caido=(rand_r(&s)%100<25); // posible peregrino sentado //if (hay_caido) world_create_walker(800,2); // int hay_bici=(rand_r(&s)%100<25); // posible bici // if (hay_bici) world_create_walker(-800*2,3); if (izone<0) return; // for (i=0;i<3;i++) { // if (rand_r(&s)%100 <25) { // int walker_type=rand_r(&s)%2; // float walker_pos=world.zone_width+world.zone_width*(rand_r(&s)%100)*1.0/100.0; // world_create_walker(walker_pos, walker_type); // } // } int items_seed=generador_items_seed; s+=items_seed; int hay_comida=(rand_r(&s)%100<105); // posible comida if (hay_comida) { int comida_tipo=rand_r(&s)%6; if (izone%50==49) { comida_tipo=ITEM_CLS_POWERUP_LIFE; } t_itemPtr unitem=item_create(&world, comida_tipo); if (unitem) { // printf("creada comida tipo %d\n", comida_tipo); unitem->x=1000.0-200.0+400.0*(rand_r(&s)%100)/100.0; //unitem->y=1.0*(rand_r(&s)%500); unitem->y=250.0; } } } else if (level==1) { // zonas de nivel 1 segundo plano unsigned int s=izone+zone_seed+1; if (rand_r(&s)%100 <80) { // posible colina 1 thezone->back_colina_pos[0]=20; } else { thezone->back_colina_pos[0]=-1; } if (rand_r(&s)%100 <80) { // posible colina 2 thezone->back_colina_pos[1]=520; } else { thezone->back_colina_pos[1]=-1; } } }