Esempio n. 1
0
int main () {
	PP_Open(); /* open the Prog&Play API */
	PP_Unit u = PP_GetUnitAt(MY_COALITION, 0);
	PP_Pos p = PP_Unit_GetPosition(u);
	p.x += 927;
	p.y -= 513;
	PP_Unit_ActionOnPosition(u, MOVE, p);
	/* close the Prog&Play API */
	PP_Close();
	return 0;
}
Esempio n. 2
0
static FILE *PP_OpenInclude( const char *filename, size_t len, int incl_type )
{
    char        fullfilename[_MAX_PATH];
    int         rc;

    rc = PP_FindInclude( filename, len, fullfilename, incl_type );
    if( PPFlags & PPFLAG_DEPENDENCIES ) {
        (*PP_CallBack)( filename, len, fullfilename, incl_type );
    } else if( rc == 0 ) {
        return( PP_Open( fullfilename ) );
    }
    return( NULL );
}
Esempio n. 3
0
int PP_Init2( const char *filename, unsigned flags, const char *include_path, const char *leadbytes )
{
    FILE        *handle;
    int         hash;

    for( hash = 0; hash < HASH_SIZE; hash++ ) {
        PPHashTable[hash] = NULL;
    }
    NestLevel = 0;
    SkipLevel = 0;
    PPFlags = flags;
    memset( MBCharLen, 0, 256 );
    if( leadbytes != NULL ) {
        PP_SetLeadBytes( leadbytes );
    } else if( flags & PPFLAG_DB_KANJI ) {
        SetRange( 0x81, 0x9f, 1 );
        SetRange( 0xe0, 0xfc, 1 );
    } else if( flags & PPFLAG_DB_CHINESE ) {
        SetRange( 0x81, 0xfc, 1 );
    } else if( flags & PPFLAG_DB_KOREAN ) {
        SetRange( 0x81, 0xfd, 1 );
    } else if( flags & PPFLAG_UTF8 ) {
        SetRange( 0xc0, 0xdf, 1 );
        SetRange( 0xe0, 0xef, 2 );
        SetRange( 0xf0, 0xf7, 3 );
        SetRange( 0xf8, 0xfb, 4 );
        SetRange( 0xfc, 0xfd, 5 );
    }
    IncludePath2 = PP_Malloc( 1 );
    *IncludePath2 = '\0';
    IncludePath2 = AddIncludePath( IncludePath2, include_path );
    if( (PPFlags & PPFLAG_IGNORE_INCLUDE) == 0 ) {
        IncludePath2 = AddIncludePath( IncludePath2, PP_GetEnv( "INCLUDE" ) );
    }
    PP_AddMacro( "__LINE__", 8 );
    PP_AddMacro( "__FILE__", 8 );
    PP_AddMacro( "__DATE__", 8 );
    PP_AddMacro( "__TIME__", 8 );
    PP_AddMacro( "__STDC__", 8 );
    PP_TimeInit();

    handle = PP_Open( filename );
    if( handle == NULL )
        return( -1 );
    PP_GenLine();
    PPSavedChar = '\0';
    PPTokenPtr = PPNextTokenPtr;
    return( 0 );
}
Esempio n. 4
0
// déplacer toutes les unités à une coordonnée précise
int main (){
	int i; // compteur de boucle
	PP_Unit u; // unité courante
	// définition de al cible
	PP_Pos pos;
	pos.x = 256.0;
	pos.y = 1024.0;
	// ouverture du jeu
	PP_Open();
	// parcourir toutes les unités
	i = 0;
	while (i < PP_GetNumUnits(MY_COALITION)){
		// récupérer l'unité courante
		u = PP_GetUnitAt(MY_COALITION, i);
		// donner l'ordre de déplacement
		PP_Unit_ActionOnPosition(u, MOVE, pos);
		i++;
	}
	// fermer le jeu
	PP_Close();
}
Esempio n. 5
0
int main (){
	int i, j, sens, distance;
	PP_Pos pos;
	PP_Unit u;
	Groupe armee;
	Groupe groupes [NB_GROUPES];
	bool premierLancement, enFuite;
	
	// ouverture du jeu
	PP_Open();
	// initialisation de l'armée
	initialiseBytes(&armee);
	
	// determination de la direction de l'attaque
	if (PP_GetStartPosition().x < PP_GetMapSize().x/2)
		sens = 1;
	else
		sens = -1;
	
	// lancer l'attaquer
	premierLancement = true;
	while (!PP_IsGameOver()){
		traiterUnitesDetruites(&armee);
		printf("  Taille armee : %d\n", armee.nbMembres);
		// restructurer les groupes
		trierSelon(&armee, Y);
		affecterGroupes(armee, groupes, 8);
		printf("  Affichage des groupes : \n");
		for (i = 0 ; i < NB_GROUPES ; i++)
			printf("    groupe %d : %d\n", i, groupes[i].nbMembres);
		
		if (PP_GetNumUnits(ENEMY_COALITION) == 0){
			// rechercher l'adversaire
			if (premierLancement){
				// si premier lancement, avancer en formation
				printf("  Lancer la marche\n");
				distance = sens*PP_GetMapSize().x;
				progresser(armee, distance);
				premierLancement = false;
				// attendre que l'armée ai commence a bouger (rester vigilant quand à la
				// présence de l'ennemie)
				while (PP_GetNumUnits(ENEMY_COALITION) == 0 && !mobile(armee))
					printf("Attente depart armee\n");
			}
			else{
				// rechercher aléatoirement l'adversaire
				for (i = 0 ; i < NB_GROUPES ; i++){
					if (!mobile(groupes[i])){
						pos.x = rand() % (int)PP_GetMapSize().x + 1;
						pos.y = rand() % (int)PP_GetMapSize().y + 1;
						for (j = 0 ; j < groupes[i].nbMembres ; j++)
							PP_Unit_ActionOnPosition(groupes[i].membres[j], MOVE, pos);
					}
				}
			}
		}
		else{
			// Affecter une cible à chaque groupes
			for (i = 0 ; i < NB_GROUPES ; i++){
				u = determinerCible(groupes[i]);
				printf("  Cible pour le groupe %d : %d\n", i, u);
				// pour chaque membre du groupe, donner l'ordre d'attaque si necessaire
				for (j = 0 ; j < groupes[i].nbMembres ; j++)
					if (!enAttaque(groupes[i].membres[j], u))
						PP_Unit_ActionOnUnit(groupes[i].membres[j], ATTACK, u);
			}
		}
	}
	
	// fermer le jeu
	PP_Close();
	return 0;
}
Esempio n. 6
0
int main (){
	PP_Open();
	while (!PP_IsGameOver()){
		// parcours de toutes mes unités
		for (int i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){
			// récupération de l'unité courante
			PP_Unit u = PP_GetUnitAt(MY_COALITION, i);
			// display command params
			if (PP_Unit_GetNumPdgCmds(u) > 0){
				//std::cout << "code : " << PP_Unit_PdgCmd_GetCode(u, 0) << std::endl;
				//std::cout << "nbParams : " << PP_Unit_PdgCmd_GetNumParams(u, 0) << std::endl;
				std::cout << PP_Unit_PdgCmd_GetParam(u, 0, 0) << std::endl;
			}
		}
	}
/*	// définition de la position cible
	PP_Pos p;
	p.x = 100.0;
	p.y = 100.0;
	// ouverture du jeu
	std::cout << "PP_Open" << std::flush;
	if (PP_Open() == -1) std::cout << " " << PP_GetError();
	else std::cout << std::endl;
 //	std::cout << "PP_Close" << std::flush;
 //	if (PP_Close() == -1) std::cout << " " << PP_GetError();
 //	else std::cout << std::endl;
	std::cout << "PP_IsGameOver : " << std::flush;
	int tmp;
	if ((tmp = PP_IsGameOver()) == -1) std::cout << PP_GetError();
	else std::cout << tmp << std::endl;
	std::cout << "PP_GetMapSize : " << std::flush;
	p = PP_GetMapSize();
	if (p.x == -1.0) std::cout << PP_GetError();
	else std::cout << "(" << p.x << ", " << p.y << ")" << std::endl;
	std::cout << "PP_GetStartPosition : " << std::flush;
	p = PP_GetStartPosition();
	if (p.x == -1.0) std::cout << PP_GetError();
	else std::cout << "(" << p.x << ", " << p.y << ")" << std::endl;
	std::cout << "PP_GetNumSpecialAreas : " << std::flush;
	int size = PP_GetNumSpecialAreas();
	if (size == -1) std::cout << PP_GetError();
	else{
		std::cout << size << std::endl;
		for (int i = 0 ; i < size ; i++){
			std::cout << "  PP_GetSpecialAreaPosition de " << i << " : " << std::flush;
			p = PP_GetSpecialAreaPosition(i);
			if (p.x == -1.0) std::cout << PP_GetError();
			else std::cout << "(" << p.x << ", " << p.y << ")" << std::endl;
		}
	}
	for (int i = 0 ; i < 3 ; i++){
		std::cout << "Coalition " << i << " : " << std::endl;
		std::cout << "  PP_GetNumUnits : " << std::flush;
		size = PP_GetNumUnits((PP_Coalition)i);
		if (size == -1) std::cout << PP_GetError();
		else{
			std::cout << size << std::endl;
			for (int j = 0 ; j < size ; j++){
				std::cout << "    PP_GetUnitAt " << j << " : " << std::flush;
				PP_Unit u = PP_GetUnitAt((PP_Coalition)i, j);
				if (u == -1) std::cout << PP_GetError();
				else{
					std::cout << u << std::endl;
					std::cout << "      PP_Unit_GetCoalition : " << std::flush;
					if ((tmp = PP_Unit_GetCoalition(u)) == -1) std::cout << PP_GetError();
					else std::cout << tmp << std::endl;
					std::cout << "      PP_Unit_GetType : " << std::flush;
					if ((tmp = PP_Unit_GetType(u)) == -1) std::cout << PP_GetError();
					else std::cout << tmp << std::endl;
					std::cout << "      PP_Unit_GetPosition : " << std::flush;
					p = PP_Unit_GetPosition(u);
					if (p.x == -1.0) std::cout << PP_GetError();
					else std::cout << "(" << p.x << ", " << p.y << ")" << std::endl;
					std::cout << "      PP_Unit_GetHealth : " << std::flush;
					if ((p.x = PP_Unit_GetHealth(u)) == -1.0) std::cout << PP_GetError();
					else std::cout << p.x << std::endl;
					std::cout << "      PP_Unit_GetMaxHealth : " << std::flush;
					if ((p.x = PP_Unit_GetMaxHealth(u)) == -1.0) std::cout << PP_GetError();
					else std::cout << p.x << std::endl;
					std::cout << "      PP_Unit_GetGroup : " << std::flush;
					if ((tmp = PP_Unit_GetGroup(u)) == -1) std::cout << PP_GetError();
					else std::cout << tmp << std::endl;
					std::cout << "      PP_Unit_SetGroup " << std::flush;
					if (PP_Unit_SetGroup(u, 0) == -1) std::cout << " " << PP_GetError();
					else std::cout << std::endl;
					
					std::cout << "      PP_Unit_GetNumPdgCmds " << std::flush;
					int ret = PP_Unit_GetNumPdgCmds(u);
					if (ret == -1) std::cout << " " << PP_GetError();
					else{
						std::cout << ret << std::endl;
						for (int i =  0 ; i < ret ; i++){
							std::cout << "code : " << PP_Unit_PdgCmd_GetCode(u, i) << "|";
							for (int j = 0 ; j < PP_Unit_PdgCmd_GetNumParams(u, i) ; j++){
								std::cout << " " << PP_Unit_PdgCmd_GetParam(u, i, j);
							}
						}
						std::cout << std::endl;
					}
					
					std::cout << "    PP_GetUnitAt 1 : " << std::flush;
					PP_Unit u1 = PP_GetUnitAt(MY_COALITION, 1);
					if (u1 == -1) std::cout << PP_GetError();
					else{
						std::cout << "      PP_Unit_ActionOnUnit " << std::flush;
						if (PP_Unit_ActionOnUnit(u, GUARD, u1) == -1) std::cout << " " << PP_GetError();
						else std::cout << std::endl;
					}
					std::cout << "      PP_Unit_ActionOnPosition " << std::flush;
					p.x = 50.0;
					p.y = 50.0;
					if (PP_Unit_ActionOnPosition(u, MOVE, p) == -1) std::cout << " " << PP_GetError();
					else std::cout << std::endl;
					//std::cout << "      PP_Unit_UntargetedAction " << std::flush;
					//if (PP_Unit_UntargetedAction(u, FIRE_STATE, 0.0) == -1) std::cout << " " << PP_GetError();
					//else std::cout << std::endl;
				}
			}
		}
	}
	std::cout << "PP_Close" << std::endl;
	PP_Close();*/
}
Esempio n. 7
0
int main (){
	int i, j, sens;
	PP_Pos pos;
	PP_Unit u, select, tmp;
	bool attaque;
	float distance, dx, dy;
	PP_PendingCommands cmd;
	
	// ouverture du jeu
	PP_Open();
	
	// determination de la direction de l'attaque
	if (PP_GetStartPosition().x < PP_GetMapSize().x/2)
		sens = 1;
	else
		sens = -1;
	
	// lancer la marche
	for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){
		pos = PP_Unit_GetPosition(PP_GetUnitAt(MY_COALITION, i));
		if (sens == -1)
			pos.x = 10;
		else
			pos.x = PP_GetMapSize().x - 10;
		PP_Unit_ActionOnPosition(PP_GetUnitAt(MY_COALITION, i), MOVE, pos);
	}
	// attendre le départ de l'armée
	while (!mobile())
		printf("Attente depart armee\n");
	
	// ordonner d'attaquer les bytes ennemis
	while (!PP_IsGameOver()){
		if (PP_GetNumUnits(ENEMY_COALITION) == 0){
			// faire une recherche aléatoire
			for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){
				u = PP_GetUnitAt(MY_COALITION, i);
				if (PP_Unit_GetPendingCommands(u, &cmd) != -1){
					if (cmd.nbCmds == 0){
						pos.x = rand() % (int)PP_GetMapSize().x + 1;
						pos.y = rand() % (int)PP_GetMapSize().y + 1;
						PP_Unit_ActionOnPosition(PP_GetUnitAt(MY_COALITION, i), MOVE, pos);
					}
				}
			}
		}
		else{
			// ordonner aux unités qui n'attaquent pas de cibler l'unité ennemie la plus proche d'elle
			for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){
				printf(" %d", i);
				u = PP_GetUnitAt(MY_COALITION, i);
				if (PP_Unit_GetPendingCommands(u, &cmd) != -1){
					attaque = false;
					if (cmd.nbCmds == 0)
						attaque = true;
					else if (cmd.nbCmds > 0)
						if (cmd.cmd[0].code != ATTACK)
							attaque = true;
					if (attaque){
						pos = PP_Unit_GetPosition(u);
						// calcul de la distance max pour cette carte
						distance = PP_GetMapSize().x*PP_GetMapSize().x+PP_GetMapSize().y*PP_GetMapSize().y;
						select = -1;
						for (j = 0 ; j < PP_GetNumUnits(ENEMY_COALITION) ; j++){
							tmp = PP_GetUnitAt(ENEMY_COALITION, j);
							dx = pos.x - PP_Unit_GetPosition(tmp).x;
							dy = pos.y - PP_Unit_GetPosition(tmp).y;
							if (dx*dx+dy*dy < distance){
								distance = dx*dx+dy*dy;
								select = tmp;
							}
						}
						if (select != -1)
							PP_Unit_ActionOnUnit(u, ATTACK, select);
					}
				}
				else{
					printf("%s", PP_GetError());
				}
			}
			printf("\n");
		}
	}
	// fermer le jeu
	PP_Close();
	return 0;
}