1
0
Fork 0

Merge commit 'refs/merge-requests/9' of git://gitorious.org/fg/fgdata

This commit is contained in:
Stuart Buchanan 2010-07-24 22:45:30 +01:00
commit 2d40be8ff5
2 changed files with 25 additions and 9 deletions

View file

@ -1,15 +1,15 @@
###############################################################################
## $Id$
##
## A message based information broadcast for the multiplayer network.
##
## Copyright (C) 2008 - 2009 Anders Gidenstam (anders(at)gidenstam.org)
## Copyright (C) 2008 - 2010 Anders Gidenstam (anders(at)gidenstam.org)
## This file is licensed under the GPL license version 2 or later.
##
###############################################################################
###############################################################################
# Broadcast primitive using a MP enabled string property.
# Broadcasts from users in multiplayer.ignore are ignored.
#
# BroadcastChannel.new(mpp_path, process)
# Create a new broadcast primitive. Any MP user with the same
@ -101,7 +101,9 @@ BroadcastChannel.update = func {
props.globals.getNode("/ai/models").getChildren("multiplayer");
foreach (var pilot; mpplayers) {
if ((pilot.getChild("valid") != nil) and
pilot.getChild("valid").getValue()) {
pilot.getChild("valid").getValue() and
!contains(multiplayer.ignore,
pilot.getChild("callsign").getValue())) {
if ((me.peers[pilot.getIndex()] == nil) and
me.accept_predicate(pilot)) {
me.peers[pilot.getIndex()] =
@ -110,8 +112,10 @@ BroadcastChannel.update = func {
MessageChannel.new_message_handler(process_msg, pilot));
}
} else {
delete(me.peers, pilot.getIndex());
me.on_disconnect(pilot);
if (contains(me.peers, pilot.getIndex())) {
delete(me.peers, pilot.getIndex());
me.on_disconnect(pilot);
}
}
}
me.last_time = t;

View file

@ -1,10 +1,9 @@
###############################################################################
## $Id$
##
## A cellular automaton forest fire model with the ability to
## spread over the multiplayer network.
##
## Copyright (C) 2007 - 2009 Anders Gidenstam (anders(at)gidenstam.org)
## Copyright (C) 2007 - 2010 Anders Gidenstam (anders(at)gidenstam.org)
## This file is licensed under the GPL license version 2 or later.
##
###############################################################################
@ -21,6 +20,9 @@ var trace = func {}
# Where to save fire event logs.
var SAVEDIR = getprop("/sim/fg-home") ~ "/Wildfire/";
# Maximum number of ignite events a single user can send per second.
var MAX_IGNITE_RATE = 0.25;
###############################################################################
## External API
@ -132,6 +134,7 @@ var fire_LOD_pp = "environment/wildfire/models/fire-lod";
var smoke_LOD_pp = "environment/wildfire/models/smoke-lod";
var LOD_High = 20;
var LOD_Low = 80;
var mp_last_limited_event = {}; # source : time
var score = { extinguished : 0, protected : 0, waste : 0 };
var old_score = { extinguished : 0, protected : 0, waste : 0 };
@ -189,10 +192,19 @@ var foam_drop_msg = func (pos, radius, volume) {
var parse_msg = func (source, msg) {
if (!getprop(MP_share_pp)) return;
var cur_time = systime();
var type = Binary.decodeByte(substr(msg, 5));
if (type == 1) {
var pos = Binary.decodeCoord(substr(msg, 6));
ignite(pos, 0);
var i = source.getIndex();
if (!contains(mp_last_limited_event, i) or
(cur_time - mp_last_limited_event[i]) > 1/MAX_IGNITE_RATE) {
var pos = Binary.decodeCoord(substr(msg, 6));
ignite(pos, 0);
} else {
printlog("warn", "wildfire.nas: Ignored ignite event from " ~
source.getNode("callsign").getValue());
}
mp_last_limited_event[i] = cur_time;
}
if (type == 2) {
var pos = Binary.decodeCoord(substr(msg, 6));