void controlObject(struct Creature *go) { controlled = go; action_create(&move_act, ACT_MOVE); struct ActionObject* user; action_obj_create(&user, ACT_OBJ_CREATURE); user->creature = controlled; action_add(move_act, user, ACT_ROLE_USER); struct ActionObject* mag; action_obj_create(&mag, ACT_OBJ_FLOAT); mag->fvalue = 5.0f; action_add(move_act, mag, ACT_ROLE_MAGNITUDE); action_obj_create(&move_angle, ACT_OBJ_FLOAT); move_angle->fvalue = 0.0f; action_add(move_act, move_angle, ACT_ROLE_ANGLE); // make sure it's disabled at the start action_add_subtype(move_act, SACT_DISABLED); game_add_action(&(mainGame->acts), move_act); }
Action Action::create( MemoryManager memory_manager, const char* name, action_generator_t generator ) { return create<void>( memory_manager, name, action_create(generator), action_destroy, action_execute ); }
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; } };
int main(int argc, char* argv[]) { toolcontext ctx; char fname[512]; int c; u32 ncchoffset = ~0; char keysetfname[512] = "keys.xml"; keyset tmpkeys; unsigned int checkkeysetfile = 0; memset(&ctx, 0, sizeof(toolcontext)); ctx.actions = InfoFlag | ExtractFlag | ParseFlag; ctx.filetype = FILETYPE_UNKNOWN; settings_init(&ctx.usersettings); keyset_init(&ctx.usersettings.keys); keyset_init(&tmpkeys); while (1) { int option_index; static struct option long_options[] = { {"create", 0, NULL, 'c'}, {"extract", 0, NULL, 'x'}, {"plain", 0, NULL, 'p'}, {"info", 0, NULL, 'i'}, {"exefs", 1, NULL, 0}, {"romfs", 1, NULL, 1}, {"exheader", 1, NULL, 2}, {"certs", 1, NULL, 3}, {"tik", 1, NULL, 4}, {"tmd", 1, NULL, 5}, {"contents", 1, NULL, 6}, {"meta", 1, NULL, 7}, {"exefsdir", 1, NULL, 8}, {"keyset", 1, NULL, 'k'}, {"ncch", 1, NULL, 'n'}, {"verbose", 0, NULL, 'v'}, {"verify", 0, NULL, 'y'}, {"raw", 0, NULL, 'r'}, {"unitsize", 1, NULL, 9}, {"showkeys", 0, NULL, 10}, {"commonkey", 1, NULL, 11}, {"ncchkey", 1, NULL, 12}, {"intype", 1, NULL, 't'}, {"lzssout", 1, NULL, 13}, {"firmdir", 1, NULL, 14}, {"ncchsyskey", 1, NULL, 15}, {"wav", 1, NULL, 16}, {"romfsdir", 1, NULL, 17}, {"listromfs", 0, NULL, 18}, {"wavloops", 1, NULL, 19}, {"section0file", 1, NULL, SECTION_FILE_ARG_BASE+0}, {"section1file", 1, NULL, SECTION_FILE_ARG_BASE+1}, {"section2file", 1, NULL, SECTION_FILE_ARG_BASE+2}, {"section3file", 1, NULL, SECTION_FILE_ARG_BASE+3}, {"section4file", 1, NULL, SECTION_FILE_ARG_BASE+4}, {"section5file", 1, NULL, SECTION_FILE_ARG_BASE+5}, {"section6file", 1, NULL, SECTION_FILE_ARG_BASE+6}, {"section7file", 1, NULL, SECTION_FILE_ARG_BASE+7}, {"section0name", 1, NULL, SECTION_NAME_ARG_BASE+0}, {"section1name", 1, NULL, SECTION_NAME_ARG_BASE+1}, {"section2name", 1, NULL, SECTION_NAME_ARG_BASE+2}, {"section3name", 1, NULL, SECTION_NAME_ARG_BASE+3}, {"section4name", 1, NULL, SECTION_NAME_ARG_BASE+4}, {"section5name", 1, NULL, SECTION_NAME_ARG_BASE+5}, {"section6name", 1, NULL, SECTION_NAME_ARG_BASE+6}, {"section7name", 1, NULL, SECTION_NAME_ARG_BASE+7}, {"compresscode", 0, NULL, 40}, {NULL}, }; c = getopt_long(argc, argv, "ryxcivpk:n:t:", long_options, &option_index); if (c == -1) break; switch (c) { case 'c': ctx.actions |= CreateFlag; ctx.actions &= ~ParseFlag; break; case 'x': ctx.actions |= ExtractFlag; break; case 'v': ctx.actions |= VerboseFlag; break; case 'y': ctx.actions |= VerifyFlag; break; case 'p': ctx.actions |= PlainFlag; break; case 'r': ctx.actions |= RawFlag; break; case 'i': ctx.actions |= InfoFlag; break; case 'n': ncchoffset = strtoul(optarg, 0, 0); break; case 'k': strncpy(keysetfname, optarg, sizeof(keysetfname)); checkkeysetfile = 1; break; case 't': if (!strcmp(optarg, "exheader")) ctx.filetype = FILETYPE_EXHEADER; else if (!strcmp(optarg, "ncch")) ctx.filetype = FILETYPE_CXI; else if (!strcmp(optarg, "ncsd")) ctx.filetype = FILETYPE_CCI; else if (!strcmp(optarg, "cia")) ctx.filetype = FILETYPE_CIA; else if (!strcmp(optarg, "tmd")) ctx.filetype = FILETYPE_TMD; else if (!strcmp(optarg, "lzss")) ctx.filetype = FILETYPE_LZSS; else if (!strcmp(optarg, "firm")) ctx.filetype = FILETYPE_FIRM; else if (!strcmp(optarg, "cwav")) ctx.filetype = FILETYPE_CWAV; else if (!strcmp(optarg, "exefs")) ctx.filetype = FILETYPE_EXEFS; else if (!strcmp(optarg, "romfs")) ctx.filetype = FILETYPE_ROMFS; break; case 0: settings_set_exefs_path(&ctx.usersettings, optarg); break; case 1: settings_set_romfs_path(&ctx.usersettings, optarg); break; case 2: settings_set_exheader_path(&ctx.usersettings, optarg); break; case 3: settings_set_certs_path(&ctx.usersettings, optarg); break; case 4: settings_set_tik_path(&ctx.usersettings, optarg); break; case 5: settings_set_tmd_path(&ctx.usersettings, optarg); break; case 6: settings_set_content_path(&ctx.usersettings, optarg); break; case 7: settings_set_content_path(&ctx.usersettings, optarg); break; case 8: settings_set_exefs_dir_path(&ctx.usersettings, optarg); break; case 9: settings_set_mediaunit_size(&ctx.usersettings, strtoul(optarg, 0, 0)); break; case 10: ctx.actions |= ShowKeysFlag; break; case 11: keyset_parse_commonkey(&tmpkeys, optarg, strlen(optarg)); break; case 12: keyset_parse_ncchkey(&tmpkeys, optarg, strlen(optarg)); break; case 13: settings_set_lzss_path(&ctx.usersettings, optarg); break; case 14: settings_set_firm_dir_path(&ctx.usersettings, optarg); break; case 15: keyset_parse_ncchfixedsystemkey(&tmpkeys, optarg, strlen(optarg)); break; case 16: settings_set_wav_path(&ctx.usersettings, optarg); break; case 17: settings_set_romfs_dir_path(&ctx.usersettings, optarg); break; case 18: settings_set_list_romfs_files(&ctx.usersettings, 1); break; case 19: settings_set_cwav_loopcount(&ctx.usersettings, strtoul(optarg, 0, 0)); break; case 40: ctx.actions |= CompressCodeFlag; break; case SECTION_FILE_ARG_BASE+0: case SECTION_FILE_ARG_BASE+1: case SECTION_FILE_ARG_BASE+2: case SECTION_FILE_ARG_BASE+3: case SECTION_FILE_ARG_BASE+4: case SECTION_FILE_ARG_BASE+5: case SECTION_FILE_ARG_BASE+6: case SECTION_FILE_ARG_BASE+7: settings_set_exefs_section_path(&ctx.usersettings, c-SECTION_FILE_ARG_BASE, optarg); break; case SECTION_NAME_ARG_BASE+0: case SECTION_NAME_ARG_BASE+1: case SECTION_NAME_ARG_BASE+2: case SECTION_NAME_ARG_BASE+3: case SECTION_NAME_ARG_BASE+4: case SECTION_NAME_ARG_BASE+5: case SECTION_NAME_ARG_BASE+6: case SECTION_NAME_ARG_BASE+7: settings_set_exefs_section_name(&ctx.usersettings, c-SECTION_NAME_ARG_BASE, optarg); break; default: usage(argv[0]); } } if (optind == argc - 1) { // Exactly one extra argument - an input file strncpy(fname, argv[optind], sizeof(fname)); } else if ( (optind < argc) || (argc == 1) ) { // Too many extra args usage(argv[0]); } keyset_load(&ctx.usersettings.keys, keysetfname, (ctx.actions & VerboseFlag) | checkkeysetfile); keyset_merge(&ctx.usersettings.keys, &tmpkeys); if (ctx.actions & ShowKeysFlag) keyset_dump(&ctx.usersettings.keys); if(ctx.actions & ParseFlag)return action_parse(&ctx, fname); else if(ctx.actions & CreateFlag)return action_create(&ctx, fname); return -1; //shouldn't happen ffs }