Example #1
0
void Monster::updateBabbling(Duration elapsedTime) {
	assert(elapsedTime >= Duration::zero());

	if (_babbleDelay <= Duration::zero()) {
		return;
	}

	if (elapsedTime >= _babbleDelay) {
		_babbleDelay = _type->babbleInterval;

		if (_type->babbleChance < random_range(1, 100)) {
			return;
		}

		babble();
	}
	else {
		_babbleDelay -= elapsedTime;
	}
}
Example #2
0
int process_program(PROGRAM prog)
{
  if (verbose_flag)
    printf(_("Processing program %s...\n"), prog->filename);
  /* Potential preparation of special - eg. C - source */
  if (prog->kind == C && use_cpp)  
  {
    trim_directives_from(&(prog->source));
    preprocess_from(&(prog->source));
    trim_directives_from(&(prog->source));
	babble(_("File preprocessed."));
  }
  /* 
   * Lexical analysis for atoms 
   * ---
   *  Analiza leksykalna atomów
   */
  if (prog->kind == C)
  { 
    ATOM a;
    FILE *atom_out;
    atcin = (FILE*) fmemopen(prog->source, strlen(prog->source), "r");
    atom_out = (FILE*) open_memstream(&prog->lex_atoms, &prog->num_lex_atoms);
	init_atclex();
	atcMetrics = emptyMetrics;
    while ( a = atclex()) 
    {
      fwrite(&a, sizeof(ATOM), 1, atom_out);
    }
    fclose(atcin);
    fclose(atom_out);
    /*
    Convert size in bytes to count of atom pointers
    ---
    Zamiana rozmiaru w bajtach na liczbê wska¼nikow
    */
    prog->num_lex_atoms /= sizeof(ATOM); 
	prog->theMetrics = atcMetrics;
  }
  else if (prog->kind == BANAL)
  {
    ATOM a;
    FILE *atom_out;
    atbanin = (FILE*) fmemopen(prog->source, strlen(prog->source), "r");
    atom_out = (FILE*) open_memstream(&prog->lex_atoms, &prog->num_lex_atoms);
	init_atbanlex();
	atbanMetrics = emptyMetrics;
    while ( a = atbanlex()) 
    {
      fwrite(&a, sizeof(ATOM), 1, atom_out);
      // printf("%s - code %3d - type %s\n", a->content, a->code, atom_names[a->code]);
    }
    fclose(atbanin);
    fclose(atom_out);
    /*
    Convert size in bytes to count of atom pointers
    ---
    Zamiana rozmiaru w bajtach na liczbe wskaznikow
    */
    prog->num_lex_atoms /= sizeof(ATOM); 
	prog->theMetrics = atbanMetrics;
  }
  else if (prog->kind == PASCAL)
  {
    ATOM a;
    FILE *atom_out;
    atpasin = (FILE*) fmemopen(prog->source, strlen(prog->source), "r");
    atom_out = (FILE*) open_memstream(&prog->lex_atoms, &prog->num_lex_atoms);
	init_atpaslex();
	atpasMetrics = emptyMetrics;
    while ( a = atpaslex()) 
    {
      fwrite(&a, sizeof(ATOM), 1, atom_out);
    }
    fclose(atpasin);
    fclose(atom_out);
    /*
    Convert size in bytes to count of atom pointers
    ---
    Zamiana rozmiaru w bajtach na liczbe wskaznikow
    */
    prog->num_lex_atoms /= sizeof(ATOM); 
	prog->theMetrics = atpasMetrics;
  }
  
  babble(_("Processed."));
  return 1;
}