Exemplo n.º 1
0
/**
Funkcja otwierajaca plik z rozszerzeniem dt
@param name nazwa otwieranego pliku
@param name_save nazwa pliku wynikowego
 */
void Reader::open(string name,string name_save){



    size_t found = name.find(".dt");

    if(found==-1)
    {
        name = name + ".dt";
    }

    char *nazwa= new char[name.length()+1];
    strcpy( nazwa, name.c_str() );

    plik.open( nazwa, ios::in|ios::binary);
    if( plik.good() == true )
    {
        // wczytanie width
        plik.seekg( 0,ios::beg );
        int length =24;
        char * buffer = new char [length];
        plik.read(buffer,length);
        string helpReader;
        helpReader =charToString(buffer,length);
        width=bin2dec(helpReader);
        // end of width
        //wczytanie height
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);

        height=bin2dec(helpReader);
        //end of height
        //wczytanie pixelWidth
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);
        pixelWidth=bin2dec(helpReader);
        //end of pixelWidth
        //wczytaniey
        length =16;
        buffer = new char [length];
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);
        dictionaryStart=bin2dec(helpReader);
        // endo of dictionaryStart
        //wczytanie pictureStart
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);
        pictureStart=bin2dec(helpReader);
        ///end of pictureStart

        screen = SDL_SetVideoMode(width, height,32,SDL_RESIZABLE|SDL_DOUBLEBUF);

        readDictionary(name_save);

    }

    plik.close();


}
Exemplo n.º 2
0
std::string Toolbox::stripString(std::string source, int quantity, std::string mode)
{
    std::string output;
    if (mode.compare("fromEnd") == 0)
    {
        for (int i = 0; i < source.length()-quantity; i++)
        {
            output.append(charToString(source.at(i)));
        }
    }
    else if (mode.compare("fromBegin") == 0)
    {
        for (int i = source.length()-quantity; i < source.length(); i++)
        {
            output.append(charToString(source.at(i)));
        }
    }
    else
    {
        fprintf(stderr, "Wrong string stripping mode given, assuming fromEnd\n");
        for (int i = 0; i < source.length() -quantity; i++)
        {
            output.append(charToString(source.at(i)));
        }
    }
    return output;
}
Exemplo n.º 3
0
void avisarAlNivel(t_enemigo * enemigo){
	//TODO ver como consigo el fd del Planificador

	int i;
	ITEM_NIVEL * personaje;

	t_list * listaPersonajesAtacados = obtenerListaDePersonajesAbajoDeEnemigo(enemigo);
	if (list_size(listaPersonajesAtacados) > 0){
		char * simbolosPersonajesAtacados = string_new();
		for(i=0 ; i < list_size(listaPersonajesAtacados) ; i++){
			personaje = list_get(listaPersonajesAtacados,i);
			string_append(&simbolosPersonajesAtacados, charToString(personaje->id));
		}
		//TODO tengo que sacar los personajes de la lista de personajes?
		//while(list_size(listaPersonajesAtacados) > 0){
		//	list_remove(listaPersonajesAtacados,0);
		//}
		//TODO tengo que sacar los personajes de la lista de personajes?
		while(list_size(listaPersonajesAtacados) > 0){
			ITEM_NIVEL * persAtacado = list_get(listaPersonajesAtacados,0);
			int i = 0;
			bool encontrado = false;
			while(i<list_size(items) && !encontrado){
				ITEM_NIVEL * elem = list_get(items,i);
				if (elem->item_type == PERSONAJE_ITEM_TYPE)
					if (strcmp(charToString(persAtacado->id), charToString(elem->id)) == 0){
						encontrado = true;
						pthread_mutex_lock(&mx_lista_items);
						list_remove(items,i);
						//TODO ver si no hay que actulizar el mapa
						pthread_mutex_unlock(&mx_lista_items);
					}
				i++;
			}
			list_remove(listaPersonajesAtacados,0);
		}




		if(IMPRIMIR_INFO_ENEMIGO){
			pthread_mutex_lock(&mutex_log);
			log_info(logger,"El enemigo atacó a los personajes: %s ", simbolosPersonajesAtacados);
			pthread_mutex_unlock(&mutex_log);
		}

		//if (PRUEBA_CON_CONEXION)
		if(true){
			pthread_mutex_lock(&mutex_mensajes);
			enviarMensaje(socketDeEscucha, NIV_enemigosAsesinaron_PLA, simbolosPersonajesAtacados);
			pthread_mutex_unlock(&mutex_mensajes);
		}


		free(simbolosPersonajesAtacados);
	}
	list_clean(listaPersonajesAtacados); //TODO, con esto libero todos los elementos de la lista o tengo q recorrerla e ir liberando?

}
Exemplo n.º 4
0
static std::string addAutograderButton(GWindow& gui, const std::string& text, const std::string& icon) {
    static Set<char> usedMnemonics;

    std::string html = "<html><center>" + stringReplace(text, "\n", "<br>") + "</center></html>";
    GButton* button = new GButton(html);
    STATIC_VARIABLE(AUTOGRADER_BUTTONS).add(button);

    // set mnemonic shortcut
    char mnemonic = '\0';
    for (int i = 0; i < (int) text.length(); i++) {
        if (isalpha(text[i]) && !usedMnemonics.contains(text[i])) {
            mnemonic = text[i];
            break;
        }
    }
    if (mnemonic) {
        usedMnemonics.add(mnemonic);
        button->setMnemonic(mnemonic);
        button->setAccelerator("ctrl " + charToString(mnemonic));
    }

    if (!icon.empty()) {
        button->setIcon(icon);
        button->setTextPosition(SwingConstants::SWING_CENTER, SwingConstants::SWING_BOTTOM);
    }
    gui.addToRegion(button, "SOUTH");
    return html;
}
Exemplo n.º 5
0
/*
 * Recursive Search (Human Word Search)
 *
 * Recursively searches the Boggle board to find if
 * the word can be found the board and returns
 * a boolean accordingly
 */
bool recursiveSearch(int row, int col, string word, Grid<string>& board, Grid<bool>& usedBlocks){
    if(!board.inBounds(row, col)) return false;
    if(word == "") {
        return true;
    }
    BoggleGUI::setHighlighted(row, col, true);

    if(board[row][col] == charToString(word[0])){
        usedBlocks[row][col] = true;
        BoggleGUI::setAnimationDelay(100);

        for(int i = -1; i <= 1; i++){
            for(int j = -1; j <= 1; j++){
                if(!(i == 0 && j == 0)){
                    if(usedBlocks.inBounds(row + i, col + j) && !usedBlocks[row + i][col + j]) {
                        if (recursiveSearch(row + i, col + j, word.substr(1), board, usedBlocks)){
                            return true;
                        }
                    }
                }
                if(usedBlocks.inBounds(row + i, col + j) && word.length() == 1 && board[row + i][col + j] == word) {
                    return true;
                }
            }
        }
    }
    BoggleGUI::setHighlighted(row, col, false);
    return false;
}
Exemplo n.º 6
0
MacroAssemblerCodePtr charAtThunkGenerator(JSGlobalData* globalData, ExecutablePool* pool)
{
    SpecializedThunkJIT jit(1, globalData, pool);
    stringCharLoad(jit);
    charToString(jit, globalData, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
    jit.returnJSCell(SpecializedThunkJIT::regT0);
    return jit.finalize(globalData->jitStubs->ctiNativeCall());
}
Exemplo n.º 7
0
MacroAssemblerCodeRef charAtThunkGenerator(VM* vm)
{
    SpecializedThunkJIT jit(1);
    stringCharLoad(jit, vm);
    charToString(jit, vm, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
    jit.returnJSCell(SpecializedThunkJIT::regT0);
    return jit.finalize(*vm, vm->jitStubs->ctiNativeCall(vm), "charAt");
}
Exemplo n.º 8
0
MacroAssemblerCodeRef charAtThunkGenerator(JSGlobalData* globalData)
{
    SpecializedThunkJIT jit(1);
    stringCharLoad(jit);
    charToString(jit, globalData, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
    jit.returnJSCell(SpecializedThunkJIT::regT0);
    return jit.finalize(*globalData, globalData->jitStubs->ctiNativeCall(), "charAt");
}
Exemplo n.º 9
0
MacroAssemblerCodePtr fromCharCodeThunkGenerator(JSGlobalData* globalData, ExecutablePool* pool)
{
    SpecializedThunkJIT jit(1, globalData, pool);
    // load char code
    jit.loadInt32Argument(0, SpecializedThunkJIT::regT0);
    charToString(jit, globalData, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
    jit.returnJSCell(SpecializedThunkJIT::regT0);
    return jit.finalize(globalData->jitStubs->ctiNativeCall());
}
Exemplo n.º 10
0
MacroAssemblerCodeRef fromCharCodeThunkGenerator(JSGlobalData* globalData)
{
    SpecializedThunkJIT jit(1);
    // load char code
    jit.loadInt32Argument(0, SpecializedThunkJIT::regT0);
    charToString(jit, globalData, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
    jit.returnJSCell(SpecializedThunkJIT::regT0);
    return jit.finalize(*globalData, globalData->jitStubs->ctiNativeCall(), "fromCharCode");
}
Exemplo n.º 11
0
MacroAssemblerCodeRef fromCharCodeThunkGenerator(VM* vm)
{
    SpecializedThunkJIT jit(vm, 1);
    // load char code
    jit.loadInt32Argument(0, SpecializedThunkJIT::regT0);
    charToString(jit, vm, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
    jit.returnJSCell(SpecializedThunkJIT::regT0);
    return jit.finalize(vm->jitStubs->ctiNativeTailCall(vm), "fromCharCode");
}
void toMorse(std::string word, Map<std::string, std::string>& symbolTable) {
	for(unsigned int i = 0; i < word.length(); i++) {
		std::string letter = toUpperCase(charToString(word[i]));

		if(symbolTable.containsKey(letter))
			cout << symbolTable.get(letter) << " / ";
		else
			cout << "N";
	}
	cout << endl;
}
Exemplo n.º 13
0
void sh_hexTable(char* params){
	char str[5];
	int a,b;
	for(a = 0; a < 16; a++){
		for(b = 0; b < 16; b++){
			charToString(a*16+b,str);
			ttprint(str);
			ttprint(" ");
		}
	}
}
Exemplo n.º 14
0
// Reverses a string. For example: banana becomes ananab
std::string Toolbox::reverseString(std::string toReverse)
{
    std::string out = "";
    for (int i = toReverse.length()-1; i >= 0; i--)
    {
        out.append(charToString(toReverse[i]));
    }
    fprintf(stderr, "Reversed a string: \n");
    fprintf(stderr, "%s\n", toReverse.c_str());
    fprintf(stderr, "%s\n", out.c_str());
    return out;
}
Exemplo n.º 15
0
string agregarAMensaje ( int caracterSimple , bool enLetra ){
  string texto;
  char car;
  int sum;
  if ( enLetra ) {
    sum = caracterSimple + 97;
    car = sum;
    texto = charToString( car );
  }else{
    texto = intToString( caracterSimple );
  }
  return texto + " ";
}
Exemplo n.º 16
0
t_list * obtenerListaCajas(){
	t_list * cajas = list_create();
	int i;
	for(i=0 ; i < list_size(items) ; i++){
		ITEM_NIVEL * elemento;
		elemento = list_get(items,i);
		if (elemento->item_type == RECURSO_ITEM_TYPE){
			tRecursosNivel * unaCaja = recurso_create("", charToString(elemento->id),elemento->quantity,elemento->posx,elemento->posy);
			list_add(cajas, unaCaja);
		}
	}

	return cajas;
}
Exemplo n.º 17
0
/** Funkcja dekodująca plik DT alorytmem LZW
@param name_save nazwa pliku DT
 */
void Reader::readIndexesFromPixels(string name_save){
    maxColors = maxColors + 1;
    int length = pixelWidth;
    int dictionaryIndex;
    char * buffer = new char [length];
    string helpReader;
    string characters;
    string word;

    plik.seekg(pictureStart-1,ios::beg);
    plik.read(buffer,length);
    helpReader = charToString(buffer,length);
    int firstIndex = bin2dec(helpReader);
    characters = dictionaryColors[firstIndex];

    while(!plik.fail()){
        plik.read(buffer,length);
        helpReader = charToString(buffer,length);
        dictionaryIndex = bin2dec(helpReader);

        if (dictionaryColors.count(dictionaryIndex)){
          word = dictionaryColors[dictionaryIndex];
        }
        else if (dictionaryIndex == maxColors){
            word = characters + characters.substr(0,24);
        }
        else{
          throw "Decoding problem!";
        }

        binaryPixelToRGB(word);
        dictionaryColors[maxColors++] = characters + word.substr(0,24);
        characters = word;
  }

        drawPicture(name_save);
}
void toAlpha(std::string word, Map<std::string, std::string>& symbolTable) {
	TokenScanner scanner;
	scanner.ignoreWhitespace();

	for(char i = 'A'; i < 'Z'; i++)
		scanner.addWordCharacters(symbolTable.get(charToString(i)));

	scanner.setInput(word);

	while(scanner.hasMoreTokens()) {
		std::string symbol = scanner.nextToken();
		cout << symbolTable.get(symbol);
	}
	cout << endl;
}
Exemplo n.º 19
0
std::string GEvent::keyCodeToString(int keyCode) {
    switch (keyCode) {
    case ALT_KEY: return "Alt";
    case BACKSPACE_KEY: return "Bksp";
    case CAPS_LOCK_KEY: return "CapsLock";
    case CLEAR_KEY: return "Clear";
    case CTRL_KEY: return "Ctrl";
    case DELETE_KEY: return "Del";
    case DOWN_ARROW_KEY: return "Down";
    case END_KEY: return "End";
    case ENTER_KEY: return "Enter";
    case ESCAPE_KEY: return "Esc";
    case F10_KEY: return "F10";
    case F11_KEY: return "F11";
    case F12_KEY: return "F12";
    case F1_KEY: return "F1";
    case F2_KEY: return "F2";
    case F3_KEY: return "F3";
    case F4_KEY: return "F4";
    case F5_KEY: return "F5";
    case F6_KEY: return "F6";
    case F7_KEY: return "F7";
    case F8_KEY: return "F8";
    case F9_KEY: return "F9";
    case HELP_KEY: return "Help";
    case HOME_KEY: return "Home";
    case INSERT_KEY: return "Ins";
    case LEFT_ARROW_KEY: return "Left";
    case MENU_KEY: return "Menu";
    case META_KEY: return "Meta";
    case NUM_LOCK_KEY: return "NumLock";
    case PAGE_DOWN_KEY: return "PgDn";
    case PAGE_UP_KEY: return "PgUp";
    case PAUSE_KEY: return "Pause";
    case PRINT_SCREEN_KEY: return "PrtSc";
    case RIGHT_ARROW_KEY: return "Right";
    case SCROLL_LOCK_KEY: return "ScrollLock";
    case SHIFT_KEY: return "Shift";
    case TAB_KEY: return "Tab";
    case UP_ARROW_KEY: return "Up";
    case WINDOWS_KEY: return "Win";
    case '\r': return "Enter";
    case '\\': return "\\";
    default: return charToString((char) keyCode);
    }
}
Exemplo n.º 20
0
/*
 * A general handler for any uncaught exception.
 * Prints details about the exception and then tries to print a stack trace.
 */
static void stanfordCppLibTerminateHandler() {
    signalHandlerDisable();   // don't want both a signal AND a terminate() call
    std::string DEFAULT_EXCEPTION_KIND = "An exception";
    std::string DEFAULT_EXCEPTION_DETAILS = "(unknown exception details)";
    
    std::string msg;
    msg += "\n";
    msg += " ***\n";
    msg += " *** STANFORD-WHITTIER C++ LIBRARY\n";
    msg += " *** " + DEFAULT_EXCEPTION_KIND + " occurred during program execution: \n";
    msg += " *** " + DEFAULT_EXCEPTION_DETAILS + "\n";
    msg += " ***\n";
    
    std::ostream& out = std::cerr;
    try {
        throw;   // re-throws the exception that already occurred
    } catch (const ErrorException& ex) {
        FILL_IN_EXCEPTION_TRACE(ex, "An ErrorException", ex.what());
    }
//    catch (const InterruptedIOException& /* iex */) {
//        // blocked console I/O was interrupted; just exit program immediately
//        // (doesn't close any other JBE-generated GUI windows, but oh well)
//        std::cout.flush();
//        exit(0);
//    }
    catch (const std::exception& ex) {
        FILL_IN_EXCEPTION_TRACE(ex, "A C++ exception", ex.what());
    } catch (std::string str) {
        FILL_IN_EXCEPTION_TRACE(str, "A string exception", str);
    } catch (char const* str) {
        FILL_IN_EXCEPTION_TRACE(str, "A string exception", str);
    } catch (int n) {
        FILL_IN_EXCEPTION_TRACE(n, "An int exception", integerToString(n));
    } catch (long l) {
        FILL_IN_EXCEPTION_TRACE(l, "A long exception", longToString(l));
    } catch (char c) {
        FILL_IN_EXCEPTION_TRACE(c, "A char exception", charToString(c));
    } catch (bool b) {
        FILL_IN_EXCEPTION_TRACE(b, "A bool exception", boolToString(b));
    } catch (double d) {
        FILL_IN_EXCEPTION_TRACE(d, "A double exception", realToString(d));
    } catch (...) {
        std::string ex = "Unknown";
        FILL_IN_EXCEPTION_TRACE(ex, "An exception", std::string());
    }
}
Exemplo n.º 21
0
t_list * obtenerListaPersonajesAtacables(){
	t_list * personajes = list_create();
	int i;
	for(i=0 ; i < list_size(items) ; i++){
		ITEM_NIVEL * elemento;
		elemento = list_get(items,i);
		if (elemento->item_type == PERSONAJE_ITEM_TYPE){
			t_posicion * pos = posicion_create_pos(elemento->posx, elemento->posy);

			t_personaje_niv1 * personaje = malloc(sizeof(t_personaje_niv1));
			personaje->posicion = pos;
			personaje->simbolo = charToString(elemento->id);

			list_add(personajes, personaje);
		}
	}

	return personajes;
}
Exemplo n.º 22
0
/** Funkcja czytająca słownik z pliku
@param name_save nazwa pliku DT
 */
void Reader::readDictionary(string name_save)
{
    maxColors = (pictureStart-dictionaryStart)/24;
    int bitCounter = 0;
    int pixLength = 24;
    int dictionaryIndex = 1;
    string helpReader;
    string transformedColor;
    char * buffer = new char [pixLength];

    plik.seekg(dictionaryStart - 1,ios::beg);
    int decimal;
    while(bitCounter<pictureStart-dictionaryStart){
        plik.read(buffer,pixLength);
        helpReader = charToString(buffer,pixLength);
        transformedColor=helpReader;
        decimal = bin2dec(transformedColor);
        dictionaryColors[dictionaryIndex] = transformedColor;
        bitCounter = bitCounter +24;
        dictionaryIndex++;
    }

    readIndexesFromPixels(name_save);
}
Exemplo n.º 23
0
void gi::dfaEDSM::print_dfa_dot_mapped_alphabet(string title, const char *file_path)
{
	string state_name_prefix = "q";
	ofstream myfile;
	myfile.open(file_path);

	string header = "digraph "+title+" {\n";

	string start_state = "__start0 [style = invis, shape = none, label = \"\", width = 0, height = 0];\n\n";

	start_state = start_state + "rankdir=LR;\nsize=\"8,5\";\n\n";

	string start_arrow = "";
	start_arrow = "subgraph cluster_main { \n\tgraph [pad=\".75\", ranksep=\"0.15\", nodesep=\"0.15\"];\n\t style=invis; \n\t__start0 -> s0 [penwidth=2];\n}\n";

	//States
	string states = "";
	string shape = "";
	string style="";
	string color="";
	for(int i=0; i<num_states; ++i)
	{
		if(ttable[i][dim_alphabet] == DFA_STATE_UNREACHABLE)
			continue;

		if(ttable[i][dim_alphabet] == DFA_STATE_ACCEPTING){
			shape = "doublecircle";
			style = "rounded,filled";
		}
		else if(ttable[i][dim_alphabet] == DFA_STATE_REJECTING){
			shape = "circle";
			style = "filled";
		} else {
			shape = "circle";
			style = "filled";
		}

		if(is_inside_red_states(i))
			color="#ff817b";
		else if(is_inside_blue_states(i))
			color="powderblue";
		else
			color="white";

		states = states + "s"+intTostring(i)+" [style=\""+style+"\", color=\"black\", fillcolor=\""+color+"\" shape=\""+shape+"\", label=\""+state_name_prefix+intTostring(i)+"\"];\n";
	}


	// Transizioni
	string transitions = "";
	//map<string, string> label_for_transiction;					// La chiave individua una coppia di stati tra cui potrebbe esserci una transizione
																	// Il valore è la label da stampare, contenente tutti i simboli per cui avviene quella transizione

	vector< vector<string> > label_for_transiction(num_states, vector<string>(num_states));

	for(int i=0; i<num_states; ++i){
		for(int j=0; j<dim_alphabet; ++j){

			int arrive_state = ttable[i][j];

			if(arrive_state == ND)
				continue;

			string transition_symbol = charToString(alphabet[j]);

			if(label_for_transiction[i][arrive_state].length() == 0)
				label_for_transiction[i][arrive_state] = label_for_transiction[i][arrive_state] + transition_symbol;
			else if(label_for_transiction[i][arrive_state].length() % 9 == 0)			// Inserisce ogni 7 simboli un ritorno a capo nella label
				label_for_transiction[i][arrive_state] = label_for_transiction[i][arrive_state] + "\\n" + transition_symbol;
			else
				label_for_transiction[i][arrive_state] = label_for_transiction[i][arrive_state] + "," +transition_symbol;


			// ORIGINALE un carattere - una transizione
			//transitions = transitions + "s"+intTostring(i)+" -> s"+intTostring(arrive_state)+" [label=\""+inverse_mapped_alphabet[alphabet_symbols[j]]+"\"];\n";
		}
	}


	for(int i=0; i<num_states; ++i)
		for(int j=0; j<num_states; ++j){
			if(label_for_transiction[i][j].compare(""))
				transitions = transitions + "s"+intTostring(i)+" -> s"+intTostring(j)+" [label=\""+label_for_transiction[i][j]+"\"];\n";
		}

	string end = "__start0 -> 0;";
	string footer ="\n}";

	myfile << header << start_state <<  states << start_arrow << transitions /*<< end*/<<footer;

	myfile.close();
}
Exemplo n.º 24
0
char *charToString( char c, char *s )
{
    return charToString( (unsigned long)(unsigned char)c, s );
}
Exemplo n.º 25
0
void cubex_main(){
input = get_input();
ref_increment((General_t)input);
a = NULL;
__temp4 = NULL;
__temp0 = NULL;
__temp5 = NULL;
__temp1 = NULL;
__temp6 = NULL;
__temp2 = NULL;
__temp7 = NULL;
__temp3 = NULL;
__temp0 = NULL;
ref_decrement((General_t)__temp0);
__temp0 = new_integer(1);
ref_increment((General_t)__temp0);
ref_decrement((General_t)__temp0);
__temp0 = NULL;
ref_decrement((General_t)__temp1);
__temp1 = new_integer(1);
ref_increment((General_t)__temp1);
if(((Boolean_t)__temp1)->value) {
ref_decrement((General_t)__temp1);
__temp1= NULL;
__temp2 = NULL;
ref_decrement((General_t)__temp2);
__temp2 = new_git_obj_charuni((char) 't');
ref_increment((General_t)__temp2);
__temp3 = NULL;
ref_decrement((General_t)__temp3);
__temp3 = iterable_append((git_t) __temp2,(git_t) NULL);
ref_increment((General_t)__temp3);
ref_decrement((General_t)__temp2);
__temp2 = NULL;
ref_decrement((General_t)a);
a = __temp3;
ref_increment((General_t)a);
ref_decrement((General_t)__temp3);
__temp3 = NULL;
} else {
ref_decrement((General_t)__temp1);
__temp1= NULL;
__temp4 = NULL;
ref_decrement((General_t)__temp4);
__temp4 = new_git_obj_charuni((char) 'f');
ref_increment((General_t)__temp4);
__temp5 = NULL;
ref_decrement((General_t)__temp5);
__temp5 = iterable_append((git_t) __temp4,(git_t) NULL);
ref_increment((General_t)__temp5);
ref_decrement((General_t)__temp4);
__temp4 = NULL;
ref_decrement((General_t)a);
a = __temp5;
ref_increment((General_t)a);
ref_decrement((General_t)__temp5);
__temp5 = NULL;
}
ref_decrement((General_t)__temp6);
__temp6 = new_git_obj((void*) a);
ref_increment((General_t)__temp6);
ref_decrement((General_t)a);
a = NULL;
ref_decrement((General_t)__temp7);
__temp7 = iterable_append((git_t) __temp6,(git_t) NULL);
ref_increment((General_t)__temp7);
ref_decrement((General_t)__temp6);
__temp6 = NULL;
_it1 = new_iterator((__temp7));
ref_increment((General_t)_it1);
while(hasNext(_it1)) {
_return = getNext(_it1);
print_line(charToString(_return), stringLength(_return));
}
ref_decrement((General_t)_it1);
_it1 = NULL;
ref_decrement((General_t)__temp7);
__temp7 = NULL;
ref_decrement((General_t)input);
ending();
return;
}
Exemplo n.º 26
0
bool DataCenter::loadHoundInfoFromXml(HoundInfo &info)
{
	std::string str;
	str = FileUtils::getInstance()->fullPathForFilename("hound_info.xml");

	tinyxml2::XMLDocument doc;
	auto data = FileUtils::getInstance()->getDataFromFile(str);
	auto ret = doc.Parse((const char*)data.getBytes(), data.getSize());
	//auto ret = doc.LoadFile(str.c_str());
	if (ret != tinyxml2::XML_NO_ERROR)
	{
		return false;
	}

	const tinyxml2::XMLElement* e_root = nullptr;
	const tinyxml2::XMLElement* e_child_1 = nullptr;
	const tinyxml2::XMLElement* e_child_2 = nullptr;
	const tinyxml2::XMLElement* e_child_3 = nullptr;
	const tinyxml2::XMLElement* e_child_4 = nullptr;

	// get root element
	e_root = doc.RootElement();
	CC_ASSERT(e_root != nullptr);
	//

	// Section: body
	e_child_1 = e_root->FirstChildElement("Body");
	CC_ASSERT(e_child_1 != nullptr);
	charToString(e_child_1->FirstChildElement("Type")->GetText(), str);
	info.body_type = getCommonType(str);
	e_child_1->FirstChildElement("Level")->QueryUnsignedText(&info.body_level);
	charToString(e_child_1->FirstChildElement("Asset")->GetText(), info.body_asset_name);
	// exacting docking positions
	std::map<int, Vec2> docks;
	int dock_id;
	Vec2 dock_pos;
	e_child_2 = e_child_1->FirstChildElement("DockPoints");
	for (e_child_3 = e_child_2->FirstChildElement(); 
		e_child_3 != nullptr;
		e_child_3 = e_child_3->NextSiblingElement())
	{
		dock_id = e_child_3->FindAttribute("id")->IntValue();
		charToString(e_child_3->GetText(), str);
		stringToVec2(str, dock_pos);
		docks[dock_id] = dock_pos;
	}

	// Section: armor
	e_child_1 = e_root->FirstChildElement("Armor");
	CC_ASSERT(e_child_1 != nullptr);
	charToString(e_child_1->FirstChildElement("Type")->GetText(), str);
	info.armor_type = getCommonType(str);
	e_child_1->FirstChildElement("Level")->QueryUnsignedText(&info.armor_level);
	charToString(e_child_1->FirstChildElement("Asset")->GetText(), info.armor_asset_name);

	// Section: engine
	e_child_1 = e_root->FirstChildElement("Engine");
	CC_ASSERT(e_child_1 != nullptr);
	charToString(e_child_1->FirstChildElement("Type")->GetText(), str);
	info.engine_type = getCommonType(str);
	e_child_1->FirstChildElement("Level")->QueryUnsignedText(&info.engine_level);
	charToString(e_child_1->FirstChildElement("Asset")->GetText(), info.engine_asset_name);

	// get hound max life and armor value
	info.max_life = getHoundMaxLife(info.body_type, info.body_level);
	info.armor = getHoundArmor(info.armor_type, info.armor_level);

	// for each weapon
	e_child_1 = e_root->FirstChildElement("Weapons");
	if (e_child_1 != nullptr)
	{
		for (e_child_2 = e_child_1->FirstChildElement(); 
			e_child_2 != nullptr;
			e_child_2 = e_child_2->NextSiblingElement())
		{
			WeaponInfo weapon;
			weapon.id = e_child_2->FindAttribute("id")->IntValue();
			charToString(e_child_2->FirstChildElement("Type")->GetText(), str);
			weapon.type = getCommonType(str);
			e_child_2->FirstChildElement("Level")->QueryUnsignedText(&weapon.level);
			auto wds = getHoundWeaponDSAT(weapon.type, weapon.level);
			weapon.damage = wds.first;
			weapon.speed = wds.second;
			weapon.acceleration = wds.third;
			weapon.steering_accel = wds.fourth;
			scaleByDesign(weapon.speed);
			scaleByDesign(weapon.acceleration);
			e_child_2->FirstChildElement("RotateAngle")->QueryFloatText(&weapon.rotate_angle);
			e_child_2->FirstChildElement("AutoAim")->QueryBoolText(&weapon.auto_aim);
			e_child_2->FirstChildElement("DockAt")->QueryIntText(&dock_id);
			weapon.dock_position = docks[dock_id];
			e_child_2->FirstChildElement("FiringStart")->QueryFloatText(&weapon.time_offset_firing_start);
			e_child_2->FirstChildElement("FiringStop")->QueryFloatText(&weapon.time_offset_firing_stop);
			charToString(e_child_2->FirstChildElement("Asset")->GetText(), weapon.texture_name);

			// for each barrel
			e_child_3 = e_child_2->FirstChildElement("Barrells");
			if (e_child_3 != nullptr)
			{
				for (e_child_4 = e_child_3->FirstChildElement(); 
					e_child_4 != nullptr;
					e_child_4 = e_child_4->NextSiblingElement())
				{
					BarrelInfo barrel;
					charToString(e_child_4->FindAttribute("type")->Value(), str);
					barrel.type = getCommonType(str);
					e_child_4->FirstChildElement("RotateAngle")->QueryFloatText(&barrel.rotate_angle);
					e_child_4->FirstChildElement("FiringInterval")->QueryFloatText(&barrel.firing_interval);
					charToString(e_child_4->FirstChildElement("ProjectileType")->GetText(), str);
					barrel.projectile_type = getCommonType(str);
					e_child_4->FirstChildElement("ProjectileLevel")->QueryIntText(&barrel.projectile_level);
					e_child_4->FirstChildElement("ProjectileScale")->QueryFloatText(&barrel.projectile_scale_xy);
					scaleByDesign(barrel.projectile_scale_xy);
					auto pds = getHoundProjectileDSAT(barrel.projectile_type, barrel.projectile_level);
					barrel.projectile_damage = pds.first;
					barrel.projectile_speed = pds.second;
					barrel.projectile_acceleration = pds.third;
					barrel.projectile_steering_accel = pds.fourth;
					scaleByDesign(barrel.projectile_speed);
					scaleByDesign(barrel.projectile_acceleration);
					scaleByDesign(barrel.projectile_steering_accel);
					barrel.projectile_final_damage = barrel.projectile_damage + weapon.damage;
					barrel.projectile_final_speed = barrel.projectile_speed + weapon.speed;
					barrel.projectile_final_acceleration = barrel.projectile_acceleration + weapon.acceleration;
					barrel.projectile_final_steering_accel = barrel.projectile_steering_accel + weapon.steering_accel;
					charToString(e_child_4->FirstChildElement("Asset")->GetText(), barrel.projectile_asset_name);

					weapon.barrells.push_back(barrel);
				}
			}

			info.weapons.push_back(weapon);
			weapon.barrells.clear();
		}
	}

	return true;
}
Exemplo n.º 27
0
bool DataCenter::loadLevelInfo(int id, LevelInfo &info)
{
	std::stringstream buffer;
	std::string str;

	buffer << "level_info_" << id << ".xml";
	str = FileUtils::getInstance()->fullPathForFilename(buffer.str());

	tinyxml2::XMLDocument doc;
	auto data = FileUtils::getInstance()->getDataFromFile(str);
	auto ret = doc.Parse((const char*)data.getBytes(), data.getSize());
	//auto ret = doc.LoadFile(str.c_str());
	if (ret != tinyxml2::XML_NO_ERROR)
	{
		return false;
	}

	const tinyxml2::XMLElement* e_root = nullptr;
	const tinyxml2::XMLElement* e_child_1 = nullptr;
	const tinyxml2::XMLElement* e_child_2 = nullptr;
	const tinyxml2::XMLElement* e_child_3 = nullptr;
	const tinyxml2::XMLElement* e_child_4 = nullptr;
	const tinyxml2::XMLElement* e_child_5 = nullptr;
	const tinyxml2::XMLElement* e_child_6 = nullptr;
	const tinyxml2::XMLElement* e_child_7 = nullptr;
	const tinyxml2::XMLElement* e_child_8 = nullptr;

	// set level id
	e_root = doc.RootElement();
	CC_ASSERT(e_root != nullptr);
	info.id = e_root->FindAttribute("id")->IntValue();
	//

	// Section: hound entry
	e_child_1 = e_root->FirstChildElement("Hound");
	CC_ASSERT(e_child_1 != nullptr);
	e_child_1->FirstChildElement("Scale")->QueryFloatText(&info.hound_scale);
	scaleByDesign(info.hound_scale);
	e_child_1->FirstChildElement("BoundingCircleRadius")->QueryFloatText(&info.hound_bounding_circle_radius);
	scaleByDesign(info.hound_bounding_circle_radius);

	e_child_2 = e_child_1->FirstChildElement("Entry");
	CC_ASSERT(e_child_2 != nullptr);
		str = e_child_2->FirstChildElement("From")->GetText();
		stringToVec2(str, info.hound_entry_from);
		scaleByDesign(info.hound_entry_from);
		str = e_child_2->FirstChildElement("To")->GetText();
		stringToVec2(str, info.hound_entry_to);
		scaleByDesign(info.hound_entry_to);
		e_child_2->FirstChildElement("Speed")->QueryFloatText(&info.hound_entry_speed);
		scaleByDesign(info.hound_entry_speed);
		e_child_2->FirstChildElement("AutoFacing")->QueryBoolText(&info.hound_entry_auto_facing);
	//

	// Section: hound leave
	e_child_2 = e_child_1->FirstChildElement("Leave");
	CC_ASSERT(e_child_2 != nullptr);
		e_child_2->FirstChildElement("Speed")->QueryFloatText(&info.hound_leave_speed);
		scaleByDesign(info.hound_leave_speed);
		e_child_2->FirstChildElement("AutoFacing")->QueryBoolText(&info.hound_leave_auto_facing);
	//

	// Section: backgrounds
	e_child_1 = e_root->FirstChildElement("Backgrounds");
	CC_ASSERT(e_child_1 != nullptr);
	for (e_child_2 = e_child_1->FirstChildElement(); 
		e_child_2 != nullptr;
		e_child_2 = e_child_2->NextSiblingElement())
	{
		info.sbg_layer_texture_names.push_back(e_child_2->GetText());
	}
	//

	// Section: Enemy Waves
	WaveInfo w_info;
	EnemyInfo ef_info;
	BarrelInfo barrel;
	WeaponInfo weapon;
	StateInfo state;
	StateMapInfo state_map;
	Movement movement;

	e_child_1 = e_root->FirstChildElement("EnemyWaves");
	if (e_child_1 == nullptr)
	{
		return true; // empty level
	}

	// for each wave
	for (e_child_2 = e_child_1->FirstChildElement();
		e_child_2 != nullptr;
		e_child_2 = e_child_2->NextSiblingElement())
	{
		w_info.time_offset = e_child_2->FindAttribute("time_offset")->FloatValue();
		// for each enemy
		for (e_child_3 = e_child_2->FirstChildElement(); 
			e_child_3 != nullptr;
			e_child_3 = e_child_3->NextSiblingElement())
		{
			ef_info.id = e_child_3->FindAttribute("id")->IntValue();
			charToString(e_child_3->FirstChildElement("Type")->GetText(), str);
			ef_info.type = getCommonType(str);
			e_child_3->FirstChildElement("Level")->QueryUnsignedText(&ef_info.level);
			auto mla = getEnemyMaxLifeArmor(ef_info.type, ef_info.level);
			ef_info.max_life = mla.first;
			ef_info.armor = mla.second;
			e_child_3->FirstChildElement("Scale")->QueryFloatText(&ef_info.scale_xy);
			scaleByDesign(ef_info.scale_xy);
			e_child_3->FirstChildElement("BoundingCircleRadius")->QueryFloatText(&ef_info.bounding_circle_radius);
			scaleByDesign(ef_info.bounding_circle_radius);
			e_child_3->FirstChildElement("RotateAngle")->QueryFloatText(&ef_info.rotate_angle);
			charToString(e_child_3->FirstChildElement("Asset")->GetText(), ef_info.body_texture_name);
			// entry
			e_child_4 = e_child_3->FirstChildElement("Entry");
			charToString(e_child_4->FirstChildElement("From")->GetText(), str);
			stringToVec2(str, ef_info.entry_from);
			scaleByDesign(ef_info.entry_from);
			charToString(e_child_4->FirstChildElement("To")->GetText(), str);
			stringToVec2(str, ef_info.entry_to);
			scaleByDesign(ef_info.entry_to);
			e_child_4->FirstChildElement("Speed")->QueryFloatText(&ef_info.entry_speed);
			scaleByDesign(ef_info.entry_speed);
			e_child_4->FirstChildElement("AutoFacing")->QueryBoolText(&ef_info.entry_auto_facing);
			// leave
			e_child_4 = e_child_3->FirstChildElement("Leave");
			e_child_4->FirstChildElement("Speed")->QueryFloatText(&ef_info.leave_speed);
			scaleByDesign(ef_info.leave_speed);
			e_child_4->FirstChildElement("AutoFacing")->QueryBoolText(&ef_info.leave_auto_facing);
			
			// for each weapon
			e_child_4 = e_child_3->FirstChildElement("Weapons");
			if (e_child_4 != nullptr)
			{
				for (e_child_5 = e_child_4->FirstChildElement(); 
					e_child_5 != nullptr;
					e_child_5 = e_child_5->NextSiblingElement())
				{
					weapon.id = e_child_5->FindAttribute("id")->IntValue();
					charToString(e_child_5->FirstChildElement("Type")->GetText(), str);
					weapon.type = getCommonType(str);
					e_child_5->FirstChildElement("Level")->QueryUnsignedText(&weapon.level);
					auto wds = getEnemyWeaponDSAT(weapon.type, weapon.level);
					weapon.damage = wds.first;
					weapon.speed = wds.second;
					weapon.acceleration = wds.third;
					weapon.steering_accel = wds.fourth;
					scaleByDesign(weapon.speed);
					scaleByDesign(weapon.acceleration);
					scaleByDesign(weapon.steering_accel);
					e_child_5->FirstChildElement("RotateAngle")->QueryFloatText(&weapon.rotate_angle);
					e_child_5->FirstChildElement("AutoAim")->QueryBoolText(&weapon.auto_aim);
					charToString(e_child_5->FirstChildElement("DockAt")->GetText(), str);
					stringToVec2(str, weapon.dock_position);
					e_child_5->FirstChildElement("FiringStart")->QueryFloatText(&weapon.time_offset_firing_start);
					e_child_5->FirstChildElement("FiringStop")->QueryFloatText(&weapon.time_offset_firing_stop);
					charToString(e_child_5->FirstChildElement("Asset")->GetText(), weapon.texture_name);

					// for each barrel
					e_child_6 = e_child_5->FirstChildElement("Barrells");
					if (e_child_6 != nullptr)
					{
						for (e_child_7 = e_child_6->FirstChildElement(); 
							e_child_7 != nullptr;
							e_child_7 = e_child_7->NextSiblingElement())
						{
							charToString(e_child_7->FindAttribute("type")->Value(), str);
							barrel.type = getCommonType(str);
							e_child_7->FirstChildElement("RotateAngle")->QueryFloatText(&barrel.rotate_angle);
							e_child_7->FirstChildElement("FiringInterval")->QueryFloatText(&barrel.firing_interval);
							charToString(e_child_7->FirstChildElement("ProjectileType")->GetText(), str);
							barrel.projectile_type = getCommonType(str);
							e_child_7->FirstChildElement("ProjectileLevel")->QueryIntText(&barrel.projectile_level);
							e_child_7->FirstChildElement("ProjectileScale")->QueryFloatText(&barrel.projectile_scale_xy);
							scaleByDesign(barrel.projectile_scale_xy);
							auto pds = getEnemyProjectileDSAT(barrel.projectile_type, barrel.projectile_level);
							barrel.projectile_damage = pds.first;
							barrel.projectile_speed = pds.second;
							barrel.projectile_acceleration = pds.third;
							barrel.projectile_steering_accel = pds.fourth;
							scaleByDesign(barrel.projectile_speed);
							scaleByDesign(barrel.projectile_acceleration);
							barrel.projectile_final_damage = barrel.projectile_damage + weapon.damage;
							barrel.projectile_final_speed = barrel.projectile_speed + weapon.speed;
							barrel.projectile_final_acceleration = barrel.projectile_acceleration + weapon.acceleration;
							scaleByDesign(barrel.projectile_speed);
							charToString(e_child_7->FirstChildElement("Asset")->GetText(), barrel.projectile_asset_name);

							weapon.barrells.push_back(barrel);
						}
					}

					ef_info.weapons.push_back(weapon);
					weapon.barrells.clear();
				}
			}

			// for each state
			e_child_4 = e_child_3->FirstChildElement("States");
			if (e_child_4 != nullptr) 
			{
				for (e_child_5 = e_child_4->FirstChildElement(); 
					e_child_5 != nullptr;
					e_child_5 = e_child_5->NextSiblingElement())
				{
					state.id = e_child_5->FindAttribute("id")->IntValue();
					charToString(e_child_5->FindAttribute("type")->Value(), str);
					state.type = getCommonType(str);

					state.life_threshold = -FLT_MAX;
					e_child_6 = e_child_5->FirstChildElement("LifeThreshold");
					if (e_child_6 != nullptr)
					{
						e_child_6->QueryFloatText(&state.life_threshold);
					}

					state.repeat_movements = false;
					e_child_6 = e_child_5->FirstChildElement("RepeatMovements");
					if (e_child_6 != nullptr)
					{
						e_child_6->QueryBoolText(&state.repeat_movements);
					}

					// for each movement
					e_child_6 = e_child_5->FirstChildElement("Movements");
					if (e_child_6 != nullptr)
					{
						for (e_child_7 = e_child_6->FirstChildElement(); 
							e_child_7 != nullptr;
							e_child_7 = e_child_7->NextSiblingElement())
						{
							charToString(e_child_7->FindAttribute("type")->Value(), str);
							movement.type = getCommonType(str);
							charToString(e_child_7->FirstChildElement("TargetPosition")->GetText(), str);
							stringToVec2(str, movement.target_position);
							scaleByDesign(movement.target_position);

							movement.displmt_auto_facing = false;
							e_child_8 = e_child_7->FirstChildElement("DisplacementAutoFacing");
							if (e_child_8 != nullptr)
							{
								e_child_8->QueryBoolText(&movement.displmt_auto_facing);
							}

							movement.stay_period = FLT_MAX;
							e_child_8 = e_child_7->FirstChildElement("StayPeriod");
							if (e_child_8 != nullptr)
							{
								e_child_8->QueryFloatText(&movement.stay_period);
							}

							movement.target_angle = 0.0f;
							e_child_8 = e_child_7->FirstChildElement("TargetAngle");
							if (e_child_8 != nullptr)
							{
								e_child_8->QueryFloatText(&movement.target_angle);
							}

							movement.speed = 0.0f;
							e_child_8 = e_child_7->FirstChildElement("Speed");
							if (e_child_8 != nullptr)
							{
								e_child_8->QueryFloatText(&movement.speed);
								if (movement.type == (int)MOVEMENT_TYPE::DISPLACEMENT)
									scaleByDesign(movement.speed);
							}

							movement.jump = false;
							e_child_8 = e_child_7->FirstChildElement("Jump");
							if (e_child_8 != nullptr)
							{
								e_child_8->QueryBoolText(&movement.jump);
							}

							state.movements.push_back(movement);
						}
					}

					// for each weapon index
					e_child_6 = e_child_5->FirstChildElement("WeaponGroup");
					if (e_child_6 != nullptr)
					{
						for (e_child_7 = e_child_6->FirstChildElement(); 
							e_child_7 != nullptr;
							e_child_7 = e_child_7->NextSiblingElement())
						{
							int weapon_index;
							e_child_7->QueryIntText(&weapon_index);
							state.weapons.push_back(weapon_index);
						}
					}
				
					ef_info.state_infoes.push_back(state);
					state.movements.clear();
					state.weapons.clear();
				}
			}
			
			// for each state transition
			e_child_4 = e_child_3->FirstChildElement("StateTransitions");
			if (e_child_4 != nullptr)
			{
				for (e_child_5 = e_child_4->FirstChildElement(); 
					e_child_5 != nullptr;
					e_child_5 = e_child_5->NextSiblingElement())
				{
					charToString(e_child_5->FirstChildElement("Event")->GetText(), str);
					state_map.event = getCommonType(str);
					e_child_5->FirstChildElement("From")->QueryIntText(&state_map.from);
					e_child_5->FirstChildElement("To")->QueryIntText(&state_map.to);
					ef_info.state_map_infoes.push_back(state_map);
				}
			}

			w_info.enemies.push_back(ef_info);
			ef_info.weapons.clear();
			ef_info.state_infoes.clear();
			ef_info.state_map_infoes.clear();
		}
		info.enemy_waves.push_back(w_info);
		w_info.enemies.clear();
	}
	//

	return true;
}
Exemplo n.º 28
0
/*
 * Load (non random) board
 *
 * Fills board from given 16 character string
 */
void loadBoard(string boardText, Grid<string>& board){
    for (size_t i = 0; i < boardText.length(); i++) {
        string str = charToString(boardText[i]);
        board[i/4][i%4] = toUpperCase(str);
    }
}
Exemplo n.º 29
0
Arquivo: strlib.c Projeto: cs50/spl
static void testCharToString(void) {
   test(charToString('x'), "x");
}