Esempio n. 1
0
def flag_random(inst, res: Property):
    """Randomly is either true or false."""
    if res.has_children():
        chance = res['chance', '100']
        seed = res['seed', '']
    else:
        chance = res.value
        seed = ''

    # Allow ending with '%' sign
    chance = utils.conv_int(chance.rstrip('%'), 100)

    random.seed('random_chance_{}:{}_{}_{}'.format(
        seed,
        inst['targetname', ''],
        inst['origin'],
        inst['angles'],
    ))
    return random.randrange(100) < chance
Esempio n. 2
0
def write_sound(file, snds: Property, pack_list, snd_prefix='*'):
    """Write either a single sound, or multiple rndsound.

    snd_prefix is the prefix for each filename - *, #, @, etc.
    """
    if snds.has_children():
        file.write(' "rndwave"\n  {\n')
        for snd in snds:
            file.write(
                '  "wave" "{sndchar}{file}"\n'.format(
                    file=snd.value,
                    sndchar=snd_prefix,
                )
            )
            pack_list.add('sound/' + snd.value.casefold())
        file.write('  }\n')
    else:
        file.write(
            ' "wave" "{sndchar}{file}"\n'.format(
                file=snds.value,
                sndchar=snd_prefix,
            )
        )
        pack_list.add('sound/' + snds.value.casefold())